User`s manual

5.5 accel lut (Ganesh)
The accel lut module provides a look-up table from the accelerometer readings
in two directions to the four corners of the quadrilateral. The output is synchro-
nized to the global sys clk. The module is essentially implemented as a giant
case statement, from which Xilinx’s tools are able to infer a ROM of the appro-
priate size. Although the data coming out of the accelerometer has 10 bits of
precision in each axis, using the full precision would require too much space for
the ROM. Instead, we use 6 bits for each of the 2 axes, for a total of 12 bits as
an index into the ROM. Each word of the ROM is 76 bits wide. This is because
each x coordinate is 10 bits wide (0 to 639), each y coordinate is 9 bits wide
(0 to 479), and there are 4 corners. Since each entry corresponds to a choice
of quadrilateral corners, and there are 2
12
= 4096 entries, manual entry of the
look-up table is infeasible. Instead, we wrote a code generator accel lut.jl in the
Julia programming language (julialang.org). Essentially, the code generator
accepts an input CSV (comma separated values) file containing some entries
of the desired look-up table obtained via manual testing. The code generator
then does a mathematical interpolation to obtain the remaining values of the
look-up table, and writes out the accel lut.v file. Of course, it may be argued
that the interpolation is not sufficient to get fine grained accuracy. Indeed,
our demonstration did show that our look-up table could use some refinement.
However, we believe that this is not an inherent deficiency of the approach; it
just means that we need more data points and sufficient polynomial degree of
the interpolator. Also related to this is another merit to this method: as the
user obtains more and more entries, he/she can simply populate the CSV file
with them. The quality of interpolation can then only improve.
5.6 pixels kept (Ganesh)
The pixels kept module accepts the four corners of the quadrilateral, computes
its area, and expresses it as a percentage of the total area. The area formula of
a quadrilateral in terms of the coordinates of its four corners is a simple deter-
minant expansion, and may be found easily in elementary geometry references.
For a quadrilateral with coordinates (x
1
, y
1
), (x
2
, y
2
), (x
3
, y
3
), (x
4
, y
4
), its area
A is given by the expression:
2A = |(x
1
x
3
)(y
2
y
4
) (y
1
y
3
)(x
2
x
4
)|. (1)
The division by 640 × 480, and subsequent multiplication by 100 is accom-
plished without doing either a hardware division or multiplication for efficiency
reasons. The key observation here is that 64 × 48 = 2
10
× 3. Thus, it suffices to
figure out how to divide by 3 without performing a hardware division. For this,
we approximate 3 by
21
64
, giving us the result correct to the nearest percent. The
output is then a 7 bit value expressing the percentage from 0 to 100.
14