1 | ENTITY cordic_cor IS |
---|
2 | PORT( |
---|
3 | ck : IN std_logic; |
---|
4 | raz : IN std_logic; |
---|
5 | |
---|
6 | wr_axy_p : IN std_logic; |
---|
7 | a_p : IN std_logic_vector(9 DOWNTO 0); |
---|
8 | x_p : IN std_logic_vector(7 DOWNTO 0); |
---|
9 | y_p : IN std_logic_vector(7 DOWNTO 0); |
---|
10 | wok_axy_p : OUT std_logic; |
---|
11 | |
---|
12 | rd_nxy_p : -- to be completed |
---|
13 | nx_p : OUT std_logic_vector(7 DOWNTO 0); |
---|
14 | ny_p : -- to be completed |
---|
15 | rok_nxy_p : -- to be completed |
---|
16 | ); |
---|
17 | END cordic_cor; |
---|
18 | |
---|
19 | ARCHITECTURE vhd OF cordic_cor IS |
---|
20 | |
---|
21 | SIGNAL |
---|
22 | n_get, get, -- get coordinates and angle |
---|
23 | n_norm, norm, -- normalization |
---|
24 | n_calc, calc, -- calcul |
---|
25 | n_mkc, mkc, -- multiply KC |
---|
26 | n_place,place, -- place in good quadrant |
---|
27 | n_put, put, -- put result |
---|
28 | a_lt_0, -- a lower than 0 |
---|
29 | quadrant_0 -- 1 quand a est dans le quadrant 0 |
---|
30 | : std_logic; |
---|
31 | |
---|
32 | SIGNAL |
---|
33 | n_quadrant, quadrant -- numéro du quadrant |
---|
34 | : std_logic_vector(1 downto 0); |
---|
35 | |
---|
36 | SIGNAL |
---|
37 | n_i, i -- compteur de recherche dichotomique |
---|
38 | : std_logic_vector(2 downto 0); |
---|
39 | |
---|
40 | SIGNAL |
---|
41 | n_x, x, -- coordonnée x |
---|
42 | n_y, y, -- coordonnée y |
---|
43 | n_a, a, -- angle |
---|
44 | n_xkc, xkc, -- x * KC |
---|
45 | n_ykc, ykc, -- y * KC |
---|
46 | atan, -- arctangeante de l'angle de rotation |
---|
47 | a_mpidiv2, -- a - PI/2 |
---|
48 | x_sra_1, y_sra_1, -- x >> 1 et y >> 1 |
---|
49 | x_sra_2, y_sra_2, -- x >> 2 et y >> 2 |
---|
50 | x_sra_3, y_sra_3, -- x >> 3 et y >> 3 |
---|
51 | x_sra_4, y_sra_4, -- x >> 4 et y >> 4 |
---|
52 | x_sra_5, y_sra_5, -- x >> 5 et y >> 5 |
---|
53 | x_sra_6, y_sra_6, -- x >> 6 et y >> 6 |
---|
54 | x_sra_7, y_sra_7, -- x >> 7 et y >> 7 |
---|
55 | x_sra_i, y_sra_i -- x >> i et y >> i |
---|
56 | : std_logic_vector(15 downto 0); |
---|
57 | |
---|
58 | BEGIN |
---|
59 | |
---|
60 | ------------------------------------------------------------------------------- |
---|
61 | -- FSM |
---|
62 | ------------------------------------------------------------------------------- |
---|
63 | |
---|
64 | -- FSM transition One Hot |
---|
65 | |
---|
66 | n_get <= (get AND NOT wr_axy_p) |
---|
67 | OR (put AND rd_nxy_p) |
---|
68 | ; |
---|
69 | n_norm <= -- to be completed |
---|
70 | ; |
---|
71 | n_calc <= (norm AND quadrant_0) |
---|
72 | OR (calc AND NOT (i = 7)) |
---|
73 | ; |
---|
74 | n_mkc <= (calc AND (i = 7)) |
---|
75 | OR (mkc AND NOT (i = 2)) |
---|
76 | ; |
---|
77 | n_place <= (mkc AND (i = 2)) |
---|
78 | ; |
---|
79 | n_put <= (place) |
---|
80 | OR (put AND NOT rd_nxy_p) |
---|
81 | ; |
---|
82 | |
---|
83 | FSM : PROCESS (ck) begin |
---|
84 | if ((ck = '1') AND NOT(ck'STABLE) ) |
---|
85 | then |
---|
86 | if (raz = '0') then |
---|
87 | get <= '1'; |
---|
88 | norm <= '0'; |
---|
89 | calc <= '0'; |
---|
90 | mkc <= '0'; |
---|
91 | place <= '0'; |
---|
92 | put <= '0'; |
---|
93 | else |
---|
94 | get <= n_get ; |
---|
95 | norm <= n_norm ; |
---|
96 | calc <= n_calc ; |
---|
97 | mkc <= n_mkc ; |
---|
98 | place <= n_place ; |
---|
99 | put <= n_put ; |
---|
100 | end if; |
---|
101 | end if; |
---|
102 | end process FSM; |
---|
103 | |
---|
104 | -- Sorties issues de l'automate |
---|
105 | |
---|
106 | wok_axy_p <= get; |
---|
107 | rok_nxy_p <= -- to be completedut; |
---|
108 | |
---|
109 | ------------------------------------------------------------------------------- |
---|
110 | -- Compteurs de l'algorithme et calcul de l'angle de rotation@ |
---|
111 | ------------------------------------------------------------------------------- |
---|
112 | |
---|
113 | -- Compteurs de normalisation de l'angle : quadrant est le numéro du quadrant |
---|
114 | |
---|
115 | n_quadrant <= "00" when get |
---|
116 | else quadrant + 1 when norm AND NOT quadrant_0 |
---|
117 | else quadrant; |
---|
118 | |
---|
119 | -- ROM with arctan(2-i) |
---|
120 | |
---|
121 | atan <= x"0065" when i = 0 -- atan(2^-0) |
---|
122 | else x"003B" when i = 1 -- atan(2^-1) |
---|
123 | else x"001F" when i = 2 -- atan(2^-2) |
---|
124 | else x"0010" when i = 3 -- atan(2^-3) |
---|
125 | else x"0008" when i = 4 -- atan(2^-4) |
---|
126 | else x"0004" when i = 5 -- atan(2^-5) |
---|
127 | else x"0002" when i = 6 -- atan(2^-6) |
---|
128 | else x"0001"; -- atan(2^-7) |
---|
129 | |
---|
130 | -- Calcul de l'angle : recherche par dichotomie |
---|
131 | |
---|
132 | a_mpidiv2 <= a - x"00C9"; |
---|
133 | quadrant_0 <= a_mpidiv2(15); |
---|
134 | a_lt_0 <= a(15); -- 1 si a est négatif (signe de a) |
---|
135 | |
---|
136 | n_a <= a_p when get -- init |
---|
137 | else a_mpidiv2 when norm AND NOT quadrant_0 -- a - PI/2 |
---|
138 | else a - atan when calc AND NOT a_lt_0 -- trop grand |
---|
139 | else a + atan when calc AND a_lt_0 -- trop petit |
---|
140 | else a; -- stable |
---|
141 | |
---|
142 | -- Compteurs de la dichotomie et de la normalisation de l'angle |
---|
143 | |
---|
144 | n_i <= "000" when get -- init |
---|
145 | else i + 1 when calc or mkc -- inc |
---|
146 | else i ; -- stable |
---|
147 | |
---|
148 | |
---|
149 | CTL : PROCESS (ck) begin |
---|
150 | if ((ck = '1') AND NOT(ck'STABLE) ) |
---|
151 | then |
---|
152 | i <= n_i ; |
---|
153 | quadrant <= n_quadrant ; |
---|
154 | a <= n_a ; |
---|
155 | end if; |
---|
156 | end process CTL; |
---|
157 | |
---|
158 | ------------------------------------------------------------------------------- |
---|
159 | -- Chemin de données |
---|
160 | ------------------------------------------------------------------------------- |
---|
161 | |
---|
162 | -- Shifters : x_sra_i <= x << i et y_sra_i <= y << i |
---|
163 | |
---|
164 | x_sra_1 <= x(15) & x(15 downto 1); |
---|
165 | x_sra_2 <= x(15) & x_sra_1(15 downto 1); |
---|
166 | x_sra_3 <= x(15) & x_sra_2(15 downto 1); |
---|
167 | x_sra_4 <= x(15) & x_sra_3(15 downto 1); |
---|
168 | x_sra_5 <= x(15) & x_sra_4(15 downto 1); |
---|
169 | x_sra_6 <= x(15) & x_sra_5(15 downto 1); |
---|
170 | x_sra_7 <= x(15) & x_sra_6(15 downto 1); |
---|
171 | x_sra_i <= x_sra_1 when i = 1 |
---|
172 | else x_sra_2 when i = 2 |
---|
173 | else x_sra_3 when i = 3 |
---|
174 | else x_sra_4 when i = 4 |
---|
175 | else x_sra_5 when i = 5 |
---|
176 | else x_sra_6 when i = 6 |
---|
177 | else x_sra_7 when i = 7 |
---|
178 | else x; |
---|
179 | |
---|
180 | y_sra_1 <= y(15) & y(15 downto 1); |
---|
181 | y_sra_2 <= y(15) & y_sra_1(15 downto 1); |
---|
182 | y_sra_3 <= y(15) & y_sra_2(15 downto 1); |
---|
183 | y_sra_4 <= y(15) & y_sra_3(15 downto 1); |
---|
184 | y_sra_5 <= y(15) & y_sra_4(15 downto 1); |
---|
185 | y_sra_6 <= y(15) & y_sra_5(15 downto 1); |
---|
186 | y_sra_7 <= y(15) & y_sra_6(15 downto 1); |
---|
187 | y_sra_i <= y_sra_1 when i = 1 |
---|
188 | else y_sra_2 when i = 2 |
---|
189 | else y_sra_3 when i = 3 |
---|
190 | else y_sra_4 when i = 4 |
---|
191 | else y_sra_5 when i = 5 |
---|
192 | else y_sra_6 when i = 6 |
---|
193 | else y_sra_7 when i = 7 |
---|
194 | else y; |
---|
195 | |
---|
196 | -- produits des coordonnées de rotation par KC |
---|
197 | |
---|
198 | n_xkc <= x_sra_7 + x_sra_5 when mkc AND i = 0 |
---|
199 | else xkc + x_sra_4 when mkc AND i = 1 |
---|
200 | else xkc + x_sra_1 when mkc AND i = 2 |
---|
201 | else xkc; |
---|
202 | |
---|
203 | n_ykc <= y_sra_7 + y_sra_5 when mkc AND i = 0 |
---|
204 | else ykc + y_sra_4 when mkc AND i = 1 |
---|
205 | else ykc + y_sra_1 when mkc AND i = 2 |
---|
206 | else ykc; |
---|
207 | |
---|
208 | -- coordonnées |
---|
209 | |
---|
210 | n_x <= x_p(7) & x_p & "0000000" when get -- init |
---|
211 | else x - y_sra_i when calc AND NOT a_lt_0 -- au dessus |
---|
212 | else x + y_sra_i when calc AND a_lt_0 -- en dessous |
---|
213 | else xkc when place AND (quadrant = 0) |
---|
214 | else -ykc when place AND (quadrant = 1) |
---|
215 | else -xkc when place AND (quadrant = 2) |
---|
216 | else ykc when place AND (quadrant = 3) |
---|
217 | else x; |
---|
218 | |
---|
219 | n_y <= y_p(7) & y_p & "0000000" when get -- init |
---|
220 | else -- to be completed -- when calc AND NOT a_lt_0 -- au dessus |
---|
221 | else -- to be completed -- when calc AND a_lt_0 -- en dessous |
---|
222 | else -- to be completed -- when place AND (quadrant = 0) |
---|
223 | else -- to be completed -- when place AND (quadrant = 1) |
---|
224 | else -- to be completed -- when place AND (quadrant = 2) |
---|
225 | else -- to be completed -- when place AND (quadrant = 3) |
---|
226 | else y; |
---|
227 | |
---|
228 | DP : PROCESS (ck) begin |
---|
229 | if ((ck = '1') AND NOT(ck'STABLE) ) |
---|
230 | then |
---|
231 | x <= n_x ; |
---|
232 | y <= n_y ; |
---|
233 | xkc <= n_xkc ; |
---|
234 | ykc <= n_ykc ; |
---|
235 | end if; |
---|
236 | end process DP; |
---|
237 | |
---|
238 | -- Sorties du chemin de données |
---|
239 | |
---|
240 | nx_p <= x(14 downto 7); |
---|
241 | ny_p <= y(14 downto 7); |
---|
242 | |
---|
243 | END vhd; |
---|