User`s manual

41 assign sy4 = {1’b0, y4};
42
43 // difference terms
44 assign d_x1_x3 = sx1 - sx3;
45 assign d_x2_x4 = sx2 - sx4;
46 assign d_y1_y3 = sy1 - sy3;
47 assign d_y2_y4 = sy2 - sy4;
48
49 // multipliers
50 assign prod0 = d_x1_x3 * d_y2_y4;
51 assign prod1 = d_y1_y3 * d_x2_x4;
52
53 // final area calculation
54 assign prod = prod0 - prod1; // this is twice the area
55
56 // but first, we need to take its absolute value
57 assign abs_prod = (prod < 0) ? -prod : prod;
58 assign unsigned_prod = abs_prod;
59
60 // to compute the percentage of pixels covered, here is the calculation
61 // we want (100*A)/(640*480), or A/(64*48)
62 // what we have is temp=2*A
63 // thus, we need temp/(128*48) = temp/(6144) = temp/(2^11 * 3) = (temp >> 11) / 3
64 // to avoid the division by 3, we approximate 3 ~= 21/64 (accurate to
65 // within 1%)
66 // thus, we want ((temp >> 11)*21) >> 6
67 // but mult by 21 is same as mult by (16 + 4 + 1)
68 // thus, our final calculation is ((temp >> 7) + (temp >> 9) + (temp >> 11))>>6
69 assign shift_prod_7 = unsigned_prod >> 7;
70 assign shift_prod_9 = unsigned_prod >> 9;
71 assign shift_prod_11 = unsigned_prod >> 11;
72 assign sum_shift_prod = shift_prod_7 + shift_prod_9 + shift_prod_11;
73 assign percent_kept = sum_shift_prod >> 6;
74
75 endmodule
A.3.6 bram.v
1 ‘default_nettype none
2 ///////////////////////////////////////////////////////////////////////////////////////////////////
3 // A simple true dual-port bram module, with hardcoded sizes
4 // number of lines: 320*240 = 76800
5 // data word width: 12 bits (4 bits r, 4 bits g, 4 bits b, one pixel per line)
6 // use here is to store a (downsampled) 640x480 frame at reduced resolution
7 // that can fit in bram (approx 1 Mbit usage per instantiation)
8 // Xilinx ISE infers the correct synthesis, and thus this module avoids
221