User`s manual

135 for i=1:2^12
136 quad_corners[i] = y4_interp[i] + (x4_interp[i] << 9) + (y3_interp[i] << 19) + (x3_interp[i] << 28)
137 quad_corners[i] += (y2_interp[i] << 38) + (x2_interp[i] << 47) + (y1_interp[i] << 57) + (x1_interp[i] << 66)
138 end
139
140 # write header
141 comment_head = "////////////////////////////////////////////////////////////////////////////////\n"
142 comment_body1 = "//This file was autogenerated by accel_lut.jl.\n"
143 comment_body2 = "//DO NOT MANUALLY EDIT THIS FILE!!!\n\n"
144 comment_body3 = "//This file implements accel_lut rom for lookup of quadrilateral corners\n//based on accelerometer readings\n"
145 comment_tail = "////////////////////////////////////////////////////////////////////////////////\n\n"
146 code_preamble1 = "module accel_lut(input clk, input[11:0] accel_val, output reg[75:0] quad_corners);\n"
147 code_preamble2 = "always @(posedge clk) begin\n"
148 code_preamble3 = "\tcase (accel_val)\n";
149 fs = open(path, "w")
150 write(fs, string(comment_head, comment_body1, comment_body2, comment_body3, comment_tail, code_preamble1, code_preamble2, code_preamble3))
151
152 # write body
153 for i=0:2^12-1
154 val = quad_corners[i+1]
155 line_str = string("\t\t12’d", i, ": quad_corners = 76’d", val, ";\n")
156 write(fs, line_str)
157 end
158
159 # write footer
160 code_end = "\tendcase\nend\nendmodule\n"
161 write(fs, code_end)
162 close(fs)
163 end
164
165 function accel_lut(in_path, out_path)
166 x_accel, y_accel, x1, y1, x2, y2, x3, y3, x4, y4 = parse_data(in_path)
167 write_file(out_path, x_accel, y_accel, x1, y1, x2, y2, x3, y3, x4, y4)
168 end
A.3.4 accel lut.txt
1 20,20, 0,0, 0,1df, 27f,1df, 27f,0
2 20,24, a,d, 0,1df, 27f,1df, 275,d
3 20,28, 12,1a, 0,1df, 27f,1df, 26e,1a
4 20,2c, 1b,39, 0,1df, 27f,1df, 265,39
5 20,30, 1f,43, 0,1df, 27f,1df, 263,43
6 20,34, 27,4d, 0,1df, 27f,1df, 25b,4d
7 28,20, 28,0, 0,1b9, 25c,1df, 27f,1e
8 30,20, 5a,0, 0,176, 22c,1df, 27f,72
9 34,30, 6e,0, 16,155, 20f,1df, 26a,86
219