1 |
2 |
feddischso |
----------------------------------------------------------------------------
|
2 |
|
|
---- ----
|
3 |
|
|
---- File : cordic_iterative_int.vhd ----
|
4 |
|
|
---- Project : YAC (Yet Another CORDIC Core) ----
|
5 |
|
|
---- Creation : Feb. 2014 ----
|
6 |
|
|
---- Limitations : ----
|
7 |
|
|
---- Synthesizer : ----
|
8 |
|
|
---- Target : ----
|
9 |
|
|
---- ----
|
10 |
|
|
---- Author(s): : Christian Haettich ----
|
11 |
|
|
---- Email : feddischson@opencores.org ----
|
12 |
|
|
---- ----
|
13 |
|
|
---- ----
|
14 |
|
|
----- -----
|
15 |
|
|
---- ----
|
16 |
|
|
---- Description ----
|
17 |
|
|
---- VHDL implementation of YAC ----
|
18 |
|
|
---- ----
|
19 |
|
|
---- ----
|
20 |
|
|
---- ----
|
21 |
|
|
----- -----
|
22 |
|
|
---- ----
|
23 |
|
|
---- TODO ----
|
24 |
|
|
---- Some documentation and function description ----
|
25 |
|
|
---- Optimization ----
|
26 |
|
|
---- ----
|
27 |
|
|
---- ----
|
28 |
|
|
---- ----
|
29 |
|
|
----------------------------------------------------------------------------
|
30 |
|
|
---- ----
|
31 |
|
|
---- Copyright Notice ----
|
32 |
|
|
---- ----
|
33 |
|
|
---- This file is part of YAC - Yet Another CORDIC Core ----
|
34 |
|
|
---- Copyright (c) 2014, Author(s), All rights reserved. ----
|
35 |
|
|
---- ----
|
36 |
|
|
---- YAC is free software; you can redistribute it and/or ----
|
37 |
|
|
---- modify it under the terms of the GNU Lesser General Public ----
|
38 |
|
|
---- License as published by the Free Software Foundation; either ----
|
39 |
|
|
---- version 3.0 of the License, or (at your option) any later version. ----
|
40 |
|
|
---- ----
|
41 |
|
|
---- YAC is distributed in the hope that it will be useful, ----
|
42 |
|
|
---- but WITHOUT ANY WARRANTY; without even the implied warranty of ----
|
43 |
|
|
---- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ----
|
44 |
|
|
---- Lesser General Public License for more details. ----
|
45 |
|
|
---- ----
|
46 |
|
|
---- You should have received a copy of the GNU Lesser General Public ----
|
47 |
|
|
---- License along with this library. If not, download it from ----
|
48 |
|
|
---- http://www.gnu.org/licenses/lgpl ----
|
49 |
|
|
---- ----
|
50 |
|
|
----------------------------------------------------------------------------
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
library ieee;
|
55 |
|
|
library std;
|
56 |
|
|
use std.textio.all;
|
57 |
|
|
use ieee.std_logic_1164.ALL;
|
58 |
|
|
use ieee.numeric_std.ALL;
|
59 |
|
|
use ieee.std_logic_textio.all; -- I/O for logic types
|
60 |
|
|
use work.cordic_pkg.ALL;
|
61 |
|
|
use ieee.math_real.ALL;
|
62 |
|
|
|
63 |
|
|
entity cordic_iterative_int is
|
64 |
|
|
generic(
|
65 |
|
|
XY_WIDTH : natural := 12;
|
66 |
|
|
A_WIDTH : natural := 12;
|
67 |
|
|
GUARD_BITS : natural := 2;
|
68 |
|
|
RM_GAIN : natural := 4
|
69 |
|
|
);
|
70 |
|
|
port(
|
71 |
|
|
clk, rst : in std_logic;
|
72 |
|
|
en : in std_logic;
|
73 |
|
|
start : in std_logic;
|
74 |
|
|
done : out std_logic;
|
75 |
|
|
mode_i : in std_logic_vector( 4-1 downto 0 );
|
76 |
|
|
x_i : in std_logic_vector( XY_WIDTH-1 downto 0 );
|
77 |
|
|
y_i : in std_logic_vector( XY_WIDTH-1 downto 0 );
|
78 |
|
|
a_i : in std_logic_vector( A_WIDTH+2-1 downto 0 );
|
79 |
|
|
x_o : out std_logic_vector( XY_WIDTH+GUARD_BITS-1 downto 0 );
|
80 |
|
|
y_o : out std_logic_vector( XY_WIDTH+GUARD_BITS-1 downto 0 );
|
81 |
|
|
a_o : out std_logic_vector( A_WIDTH+2-1 downto 0 )
|
82 |
|
|
);
|
83 |
|
|
end entity cordic_iterative_int;
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
architecture BEHAVIORAL of cordic_iterative_int is
|
87 |
|
|
|
88 |
|
|
-- log2( max-iteration )
|
89 |
|
|
constant L2_MAX_I : natural := 8;
|
90 |
|
|
|
91 |
|
|
constant MAX_A_WIDTH : natural := 34;
|
92 |
|
|
|
93 |
|
|
-- Internal angle width
|
94 |
|
|
constant A_WIDTH_I : natural := A_WIDTH+2;
|
95 |
3 |
feddischso |
<<<<<<< HEAD
|
96 |
2 |
feddischso |
|
97 |
|
|
|
98 |
|
|
constant SQRT2_REAL : real := 1.4142135623730951454746218587388284504413604;
|
99 |
|
|
constant PI_REAL : real := 3.1415926535897931159979634685441851615905762;
|
100 |
|
|
constant PI : integer := natural( PI_REAL * real( 2**( A_WIDTH-1 ) ) + 0.5 );
|
101 |
|
|
constant PI_H : integer := natural( PI_REAL * real( 2**( A_WIDTH-2 ) ) + 0.5 );
|
102 |
|
|
constant SQRT2 : integer := natural( SQRT2_REAL * real( 2**( XY_WIDTH-1 ) ) + 0.5 );
|
103 |
|
|
constant XY_MAX : integer := natural( 2**( XY_WIDTH-1)-1);
|
104 |
|
|
|
105 |
3 |
feddischso |
=======
|
106 |
|
|
|
107 |
|
|
constant PI_REAL : real := 3.1415926535897931159979634685441851615905762;
|
108 |
|
|
constant PI : integer := natural( PI_REAL * real( 2**( A_WIDTH-1 ) ) + 0.5 );
|
109 |
|
|
constant PI_H : integer := natural( PI_REAL * real( 2**( A_WIDTH-2 ) ) + 0.5 );
|
110 |
|
|
>>>>>>> initial commit
|
111 |
2 |
feddischso |
|
112 |
|
|
constant XY_WIDTH_G : natural := XY_WIDTH + GUARD_BITS;
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
type state_st is( ST_IDLE, ST_INIT, ST_ROTATE, ST_RM_GAIN, ST_DONE );
|
117 |
|
|
type state_t is record
|
118 |
|
|
st : state_st;
|
119 |
|
|
mode : std_logic_vector( mode_i'range );
|
120 |
|
|
x : signed( XY_WIDTH_G -1 downto 0 );
|
121 |
|
|
y : signed( XY_WIDTH_G -1 downto 0 );
|
122 |
|
|
x_sh : signed( XY_WIDTH_G -1 downto 0 );
|
123 |
|
|
y_sh : signed( XY_WIDTH_G -1 downto 0 );
|
124 |
|
|
x_sum : signed( XY_WIDTH_G -1 downto 0 );
|
125 |
|
|
y_sum : signed( XY_WIDTH_G -1 downto 0 );
|
126 |
|
|
a : signed( A_WIDTH_I -1 downto 0 );
|
127 |
|
|
a_tmp : signed( A_WIDTH_I -1 downto 0 );
|
128 |
|
|
ylst : signed( XY_WIDTH_G -1 downto 0 );
|
129 |
|
|
alst : signed( A_WIDTH_I -1 downto 0 );
|
130 |
|
|
i : signed( L2_MAX_I -1 downto 0 );
|
131 |
|
|
do_shift : std_logic;
|
132 |
|
|
done : std_logic;
|
133 |
|
|
repeate : std_logic;
|
134 |
|
|
end record state_t;
|
135 |
|
|
signal state : state_t;
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
---------------------------------------
|
139 |
|
|
-- Auto-generated function
|
140 |
|
|
-- by matlab (see c_octave/cordic_iterative_code.m)
|
141 |
|
|
function angular_lut( n : integer; mode : std_logic_vector; ANG_WIDTH : natural ) return signed is
|
142 |
|
|
variable result : signed( ANG_WIDTH-1 downto 0 );
|
143 |
|
|
variable temp : signed( MAX_A_WIDTH-1 downto 0 );
|
144 |
|
|
begin
|
145 |
|
|
if mode = VAL_MODE_CIR then
|
146 |
|
|
case n is
|
147 |
|
|
when 0 => temp := "0110010010000111111011010101000100"; -- -1843415740
|
148 |
|
|
when 1 => temp := "0011101101011000110011100000101011"; -- -312264661
|
149 |
|
|
when 2 => temp := "0001111101011011011101011111100100"; -- 2104350692
|
150 |
|
|
when 3 => temp := "0000111111101010110111010100110101"; -- 1068201269
|
151 |
|
|
when 4 => temp := "0000011111111101010101101110110111"; -- 536173495
|
152 |
|
|
when 5 => temp := "0000001111111111101010101011011101"; -- 268348125
|
153 |
|
|
when 6 => temp := "0000000111111111111101010101010110"; -- 134206806
|
154 |
|
|
when 7 => temp := "0000000011111111111111101010101010"; -- 67107498
|
155 |
|
|
when 8 => temp := "0000000001111111111111111101010101"; -- 33554261
|
156 |
|
|
when 9 => temp := "0000000000111111111111111111101010"; -- 16777194
|
157 |
|
|
when 10 => temp := "0000000000011111111111111111111101"; -- 8388605
|
158 |
|
|
when others => temp := to_signed( 2**(MAX_A_WIDTH-1-n), MAX_A_WIDTH );
|
159 |
|
|
end case;
|
160 |
|
|
elsif mode = VAL_MODE_HYP then
|
161 |
|
|
case n is
|
162 |
|
|
when 1 => temp := "0100011001001111101010011110101010"; -- 423536554
|
163 |
|
|
when 2 => temp := "0010000010110001010111011111010100"; -- -2100987948
|
164 |
|
|
when 3 => temp := "0001000000010101100010010001110010"; -- 1079387250
|
165 |
|
|
when 4 => temp := "0000100000000010101011000100010101"; -- 537571605
|
166 |
|
|
when 5 => temp := "0000010000000000010101010110001000"; -- 268522888
|
167 |
|
|
when 6 => temp := "0000001000000000000010101010101100"; -- 134228652
|
168 |
|
|
when 7 => temp := "0000000100000000000000010101010101"; -- 67110229
|
169 |
|
|
when 8 => temp := "0000000010000000000000000010101010"; -- 33554602
|
170 |
|
|
when 9 => temp := "0000000001000000000000000000010101"; -- 16777237
|
171 |
|
|
when 10 => temp := "0000000000100000000000000000000010"; -- 8388610
|
172 |
|
|
when others => temp := to_signed( 2**(MAX_A_WIDTH-1-n), MAX_A_WIDTH );
|
173 |
|
|
end case;
|
174 |
|
|
elsif mode = VAL_MODE_LIN then
|
175 |
|
|
temp := ( others => '0' );
|
176 |
|
|
temp( temp'high-1-n downto 0 ) := ( others => '1' );
|
177 |
|
|
end if;
|
178 |
|
|
result := temp( temp'high downto temp'high-result'length+1 );
|
179 |
|
|
return result;
|
180 |
|
|
end function angular_lut;
|
181 |
|
|
---------------------------------------
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
function repeat_hyperbolic_it( i : integer ) return boolean is
|
185 |
|
|
variable res : boolean;
|
186 |
|
|
begin
|
187 |
|
|
case i is
|
188 |
|
|
when 5 => res := true;
|
189 |
|
|
when 14 => res := true;
|
190 |
|
|
when 41 => res := true;
|
191 |
|
|
when 122 => res := true;
|
192 |
|
|
when others => res := false;
|
193 |
|
|
end case;
|
194 |
|
|
return res;
|
195 |
|
|
end;
|
196 |
|
|
|
197 |
|
|
begin
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
ST : process( clk, rst )
|
201 |
|
|
variable sign : std_logic;
|
202 |
|
|
begin
|
203 |
|
|
|
204 |
|
|
if clk'event and clk = '1' then
|
205 |
|
|
if rst = '1' then
|
206 |
|
|
state <= ( st => ST_IDLE,
|
207 |
|
|
x => ( others => '0' ),
|
208 |
|
|
y => ( others => '0' ),
|
209 |
|
|
x_sh => ( others => '0' ),
|
210 |
|
|
y_sh => ( others => '0' ),
|
211 |
|
|
x_sum => ( others => '0' ),
|
212 |
|
|
y_sum => ( others => '0' ),
|
213 |
|
|
a => ( others => '0' ),
|
214 |
|
|
a_tmp => ( others => '0' ),
|
215 |
|
|
ylst => ( others => '0' ),
|
216 |
|
|
alst => ( others => '0' ),
|
217 |
|
|
mode => ( others => '0' ),
|
218 |
|
|
i => ( others => '0' ),
|
219 |
|
|
done => '0',
|
220 |
|
|
do_shift => '0',
|
221 |
|
|
repeate => '0'
|
222 |
|
|
);
|
223 |
|
|
|
224 |
|
|
elsif en = '1' then
|
225 |
|
|
|
226 |
|
|
if state.st = ST_IDLE and start = '1' then
|
227 |
|
|
state.st <= ST_INIT;
|
228 |
|
|
state.mode <= mode_i;
|
229 |
|
|
state.x <= resize( signed( x_i ), state.x'length );
|
230 |
|
|
state.y <= resize( signed( y_i ), state.y'length );
|
231 |
|
|
state.a <= resize( signed( a_i ), state.a'length );
|
232 |
|
|
state.i <= ( others => '0' );
|
233 |
|
|
|
234 |
3 |
feddischso |
<<<<<<< HEAD
|
235 |
2 |
feddischso |
elsif state.st = ST_INIT then
|
236 |
|
|
--
|
237 |
|
|
-- initialization state
|
238 |
|
|
-- -> do initial rotation (alignment)
|
239 |
|
|
-- -> check special situations / miss-configurations (TODO)
|
240 |
|
|
--
|
241 |
|
|
|
242 |
3 |
feddischso |
=======
|
243 |
|
|
--
|
244 |
|
|
-- initialization state
|
245 |
|
|
-- -> do initial rotation (alignment)
|
246 |
|
|
-- -> check special situations / miss-configurations (TODO)
|
247 |
|
|
--
|
248 |
|
|
elsif state.st = ST_INIT then
|
249 |
|
|
>>>>>>> initial commit
|
250 |
2 |
feddischso |
state.st <= ST_ROTATE;
|
251 |
|
|
state.do_shift <= '1';
|
252 |
|
|
|
253 |
|
|
|
254 |
3 |
feddischso |
<<<<<<< HEAD
|
255 |
2 |
feddischso |
if state.mode( 1 downto 0 ) = VAL_MODE_HYP then
|
256 |
|
|
-- if we do a hyperbolic rotation, we start with 1
|
257 |
3 |
feddischso |
=======
|
258 |
|
|
-- if we do a hyperbolic rotation, we start with 1
|
259 |
|
|
if state.mode( 1 downto 0 ) = VAL_MODE_HYP then
|
260 |
|
|
>>>>>>> initial commit
|
261 |
2 |
feddischso |
state.i(0) <= '1';
|
262 |
|
|
end if;
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
3 |
feddischso |
<<<<<<< HEAD
|
268 |
2 |
feddischso |
if state.mode( I_FLAG_VEC_ROT ) = '0'
|
269 |
|
|
and state.mode( 1 downto 0 ) = VAL_MODE_CIR then
|
270 |
|
|
-- circular vector mode
|
271 |
|
|
|
272 |
|
|
if state.a < - PI_H then
|
273 |
|
|
-- move from third quadrant to first
|
274 |
|
|
state.a <= state.a + PI;
|
275 |
|
|
state.x <= - state.x;
|
276 |
|
|
state.y <= - state.y;
|
277 |
|
|
elsif state.a > PI_H then
|
278 |
|
|
-- move from second quadrant to fourth
|
279 |
3 |
feddischso |
=======
|
280 |
|
|
-- circular vector mode
|
281 |
|
|
if state.mode( FLAG_VEC_ROT ) = '0'
|
282 |
|
|
and state.mode( 1 downto 0 ) = VAL_MODE_CIR then
|
283 |
|
|
|
284 |
|
|
-- move from third quadrant to first
|
285 |
|
|
if state.a < - PI_H then
|
286 |
|
|
state.a <= state.a + PI;
|
287 |
|
|
state.x <= - state.x;
|
288 |
|
|
state.y <= - state.y;
|
289 |
|
|
-- move from second quadrant to fourth
|
290 |
|
|
elsif state.a > PI_H then
|
291 |
|
|
>>>>>>> initial commit
|
292 |
2 |
feddischso |
state.a <= state.a - PI;
|
293 |
|
|
state.x <= - state.x;
|
294 |
|
|
state.y <= - state.y;
|
295 |
|
|
end if;
|
296 |
|
|
|
297 |
3 |
feddischso |
<<<<<<< HEAD
|
298 |
2 |
feddischso |
elsif state.mode( I_FLAG_VEC_ROT ) = '1'
|
299 |
|
|
and state.mode( 1 downto 0 ) = VAL_MODE_CIR then
|
300 |
|
|
-- circular rotation mode
|
301 |
|
|
|
302 |
|
|
if state.x = 0 and state.y = 0 then
|
303 |
|
|
-- zero-input
|
304 |
|
|
state.a <= ( others => '0' );
|
305 |
|
|
state.y <= ( others => '0' );
|
306 |
|
|
state.st <= ST_DONE;
|
307 |
|
|
|
308 |
|
|
elsif state.x = XY_MAX and state.y = XY_MAX then
|
309 |
|
|
-- all-max 1
|
310 |
|
|
state.a <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
|
311 |
|
|
state.x <= to_signed( SQRT2, state.x'length );
|
312 |
|
|
state.y <= (others => '0' );
|
313 |
|
|
state.st <= ST_DONE;
|
314 |
|
|
elsif state.x = -XY_MAX and state.y = -XY_MAX then
|
315 |
|
|
-- all-max 2
|
316 |
|
|
state.a <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ) - PI;
|
317 |
|
|
state.x <= to_signed( SQRT2, state.x'length );
|
318 |
|
|
state.y <= (others => '0' );
|
319 |
|
|
state.st <= ST_DONE;
|
320 |
|
|
elsif state.x = XY_MAX and state.y = -XY_MAX then
|
321 |
|
|
-- all-max 3
|
322 |
|
|
state.a <= resize( -angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
|
323 |
|
|
state.x <= to_signed( SQRT2, state.x'length );
|
324 |
|
|
state.y <= (others => '0' );
|
325 |
|
|
state.st <= ST_DONE;
|
326 |
|
|
elsif state.x = -XY_MAX and state.y = XY_MAX then
|
327 |
|
|
-- all-max 4
|
328 |
|
|
state.a <= PI- resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
|
329 |
|
|
state.x <= to_signed( SQRT2, state.x'length );
|
330 |
|
|
state.y <= (others => '0' );
|
331 |
|
|
state.st <= ST_DONE;
|
332 |
|
|
|
333 |
|
|
elsif state.x = 0 and state.y > 0 then
|
334 |
|
|
-- fixed rotation of pi/2
|
335 |
|
|
state.a <= to_signed( PI_H, state.a'length );
|
336 |
|
|
state.x <= state.y;
|
337 |
|
|
state.y <= ( others => '0' );
|
338 |
|
|
state.st<= ST_DONE;
|
339 |
|
|
elsif state.x = 0 and state.y < 0 then
|
340 |
|
|
-- fixed rotation of -pi/2
|
341 |
|
|
state.a <= to_signed( -PI_H, state.a'length );
|
342 |
|
|
state.x <= -state.y;
|
343 |
|
|
state.y <= ( others => '0' );
|
344 |
|
|
state.st<= ST_DONE;
|
345 |
|
|
|
346 |
|
|
elsif state.x < 0 and state.y >= 0 then
|
347 |
|
|
-- move from second quadrant to fourth
|
348 |
|
|
state.x <= - state.x;
|
349 |
|
|
state.y <= - state.y;
|
350 |
|
|
state.a <= to_signed( PI, state.a'length );
|
351 |
|
|
elsif state.x < 0 and state.y < 0 then
|
352 |
|
|
-- move from third quadrant to first
|
353 |
|
|
state.x <= - state.x;
|
354 |
|
|
state.y <= - state.y;
|
355 |
|
|
state.a <= to_signed( -PI, state.a'length );
|
356 |
|
|
else
|
357 |
|
|
state.a <= ( others => '0' );
|
358 |
|
|
end if;
|
359 |
|
|
elsif state.mode( I_FLAG_VEC_ROT ) = '1'
|
360 |
|
|
and state.mode( 1 downto 0 ) = VAL_MODE_LIN then
|
361 |
|
|
-- linear rotation mode
|
362 |
|
|
if state.x < 0 then
|
363 |
|
|
state.x <= - state.x;
|
364 |
|
|
state.y <= - state.y;
|
365 |
|
|
end if;
|
366 |
|
|
state.a <= to_signed( 0, state.a'length );
|
367 |
3 |
feddischso |
=======
|
368 |
|
|
-- circular rotation mode
|
369 |
|
|
elsif state.mode( FLAG_VEC_ROT ) = '1'
|
370 |
|
|
and state.mode( 1 downto 0 ) = VAL_MODE_CIR then
|
371 |
2 |
feddischso |
|
372 |
3 |
feddischso |
-- move from second quadrant to fourth
|
373 |
|
|
if state.x < 0 and state.y > 0 then
|
374 |
|
|
state.x <= - state.x;
|
375 |
|
|
state.y <= - state.y;
|
376 |
|
|
state.a <= to_signed( PI, state.a'length );
|
377 |
|
|
-- move from third quadrant to first
|
378 |
|
|
elsif state.x < 0 and state.y < 0 then
|
379 |
|
|
state.x <= - state.x;
|
380 |
|
|
state.y <= - state.y;
|
381 |
|
|
state.a <= to_signed( -PI, state.a'length );
|
382 |
|
|
-- y=0 condition
|
383 |
|
|
elsif state.x < 0 and state.y = 0 then
|
384 |
|
|
state.a <= to_signed( PI, state.a'length );
|
385 |
|
|
state.st<= ST_DONE;
|
386 |
|
|
else
|
387 |
|
|
state.a <= ( others => '0' );
|
388 |
|
|
end if;
|
389 |
|
|
-- linear rotation mode
|
390 |
|
|
elsif state.mode( FLAG_VEC_ROT ) = '1'
|
391 |
|
|
and state.mode( 1 downto 0 ) = VAL_MODE_LIN then
|
392 |
|
|
|
393 |
|
|
if state.x < 0 then
|
394 |
|
|
state.x <= - state.x;
|
395 |
|
|
state.y <= - state.y;
|
396 |
|
|
end if;
|
397 |
|
|
state.a <= to_signed( 0, state.a'length );
|
398 |
|
|
>>>>>>> initial commit
|
399 |
|
|
|
400 |
2 |
feddischso |
end if;
|
401 |
|
|
|
402 |
|
|
|
403 |
|
|
|
404 |
|
|
|
405 |
|
|
|
406 |
|
|
--
|
407 |
|
|
-- rotation state
|
408 |
|
|
--
|
409 |
|
|
-- Each rotation takes
|
410 |
|
|
-- two steps: in the first step, the shifting is
|
411 |
|
|
-- done, in the second step, the
|
412 |
|
|
-- shift-result is added/subtracted
|
413 |
|
|
--
|
414 |
|
|
--
|
415 |
|
|
--
|
416 |
|
|
elsif state.st = ST_ROTATE then
|
417 |
|
|
|
418 |
|
|
-- get the sign
|
419 |
3 |
feddischso |
<<<<<<< HEAD
|
420 |
2 |
feddischso |
if state.mode( I_FLAG_VEC_ROT ) = '0' then
|
421 |
3 |
feddischso |
=======
|
422 |
|
|
if state.mode( FLAG_VEC_ROT ) = '0' then
|
423 |
|
|
>>>>>>> initial commit
|
424 |
2 |
feddischso |
if state.a < 0 then
|
425 |
|
|
sign := '0';
|
426 |
|
|
else
|
427 |
|
|
sign := '1';
|
428 |
|
|
end if;
|
429 |
|
|
else
|
430 |
|
|
if state.y < 0 then
|
431 |
|
|
sign := '1';
|
432 |
|
|
else
|
433 |
|
|
sign := '0';
|
434 |
|
|
end if;
|
435 |
|
|
end if;
|
436 |
|
|
|
437 |
|
|
|
438 |
|
|
|
439 |
|
|
if state.do_shift = '1' then
|
440 |
|
|
-- get the angle, do the shifting and set the right angle
|
441 |
|
|
|
442 |
|
|
if sign = '1' then
|
443 |
|
|
|
444 |
|
|
-- circular case
|
445 |
|
|
if state.mode( 1 downto 0 ) = VAL_MODE_CIR then
|
446 |
|
|
|
447 |
|
|
state.a_tmp <= resize( - angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH), A_WIDTH_I );
|
448 |
|
|
state.y_sh <= - SHIFT_RIGHT( state.y, to_integer( state.i ) );
|
449 |
|
|
|
450 |
|
|
-- hyperbolic case
|
451 |
|
|
elsif state.mode( 1 downto 0 ) = VAL_MODE_HYP then
|
452 |
|
|
|
453 |
|
|
state.a_tmp <= resize( - angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH), A_WIDTH_I );
|
454 |
|
|
state.y_sh <= SHIFT_RIGHT( state.y, to_integer( state.i ) );
|
455 |
|
|
|
456 |
|
|
-- linear case
|
457 |
|
|
else
|
458 |
|
|
|
459 |
|
|
state.a_tmp <= resize( - angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ) ;
|
460 |
|
|
state.y_sh <= ( others => '0' );
|
461 |
|
|
|
462 |
|
|
end if;
|
463 |
|
|
state.x_sh <= SHIFT_RIGHT( state.x, to_integer( state.i ) );
|
464 |
|
|
|
465 |
|
|
else
|
466 |
|
|
|
467 |
|
|
-- circular case
|
468 |
|
|
if state.mode( 1 downto 0 ) = VAL_MODE_CIR then
|
469 |
|
|
|
470 |
|
|
state.a_tmp <= resize( angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
|
471 |
|
|
state.y_sh <= SHIFT_RIGHT( state.y, to_integer( state.i ) );
|
472 |
|
|
|
473 |
|
|
-- hyperbolic case
|
474 |
|
|
elsif state.mode( 1 downto 0 ) = VAL_MODE_HYP then
|
475 |
|
|
|
476 |
|
|
state.a_tmp <= resize( angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
|
477 |
|
|
state.y_sh <= - SHIFT_RIGHT( state.y, to_integer( state.i ) );
|
478 |
|
|
|
479 |
|
|
-- linear case
|
480 |
|
|
else
|
481 |
|
|
|
482 |
|
|
state.a_tmp <= resize( angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ) ;
|
483 |
|
|
state.y_sh <= ( others => '0' );
|
484 |
|
|
|
485 |
|
|
end if;
|
486 |
|
|
state.x_sh <= - SHIFT_RIGHT( state.x, to_integer( state.i ) );
|
487 |
|
|
|
488 |
|
|
end if;
|
489 |
|
|
state.do_shift <= '0';
|
490 |
|
|
|
491 |
|
|
-- abort condition
|
492 |
3 |
feddischso |
<<<<<<< HEAD
|
493 |
2 |
feddischso |
if( state.mode( I_FLAG_VEC_ROT ) = '0' and
|
494 |
|
|
state.a = 0 ) then
|
495 |
|
|
state.st <= ST_RM_GAIN;
|
496 |
|
|
state.i <= ( others => '0' );
|
497 |
|
|
elsif( state.mode( I_FLAG_VEC_ROT ) = '0' and
|
498 |
|
|
state.a = state.alst ) then
|
499 |
|
|
state.st <= ST_RM_GAIN;
|
500 |
|
|
state.i <= ( others => '0' );
|
501 |
|
|
elsif( state.mode( I_FLAG_VEC_ROT ) = '1' and
|
502 |
|
|
state.y = 0 ) then
|
503 |
|
|
state.st <= ST_RM_GAIN;
|
504 |
|
|
state.i <= ( others => '0' );
|
505 |
|
|
elsif( state.mode( I_FLAG_VEC_ROT ) = '1' and
|
506 |
3 |
feddischso |
=======
|
507 |
|
|
if( state.mode( FLAG_VEC_ROT ) = '0' and
|
508 |
|
|
( state.a = 0 or state.a = -1 ) ) then
|
509 |
|
|
state.st <= ST_RM_GAIN;
|
510 |
|
|
state.i <= ( others => '0' );
|
511 |
|
|
elsif( state.mode( FLAG_VEC_ROT ) = '0' and
|
512 |
|
|
( state.a = state.alst ) ) then
|
513 |
|
|
state.st <= ST_RM_GAIN;
|
514 |
|
|
state.i <= ( others => '0' );
|
515 |
|
|
elsif( state.mode( FLAG_VEC_ROT ) = '1' and
|
516 |
|
|
( state.y = 0 or state.y = -1 ) ) then
|
517 |
|
|
state.st <= ST_RM_GAIN;
|
518 |
|
|
state.i <= ( others => '0' );
|
519 |
|
|
elsif( state.mode( FLAG_VEC_ROT ) = '1' and
|
520 |
|
|
>>>>>>> initial commit
|
521 |
2 |
feddischso |
( state.y = state.ylst ) ) then
|
522 |
|
|
state.st <= ST_RM_GAIN;
|
523 |
|
|
state.i <= ( others => '0' );
|
524 |
|
|
end if;
|
525 |
|
|
|
526 |
|
|
state.ylst <= state.y;
|
527 |
|
|
state.alst <= state.a;
|
528 |
|
|
|
529 |
|
|
|
530 |
|
|
else
|
531 |
|
|
state.x <= state.x + state.y_sh;
|
532 |
|
|
state.y <= state.y + state.x_sh;
|
533 |
|
|
state.a <= state.a + state.a_tmp;
|
534 |
|
|
if VAL_MODE_HYP = state.mode( 1 downto 0 ) and
|
535 |
|
|
state.repeate = '0' and
|
536 |
|
|
repeat_hyperbolic_it( to_integer( state.i ) ) then
|
537 |
|
|
state.repeate <= '1';
|
538 |
|
|
else
|
539 |
|
|
state.repeate <= '0';
|
540 |
|
|
state.i <= state.i+1;
|
541 |
|
|
end if;
|
542 |
|
|
state.do_shift <= '1';
|
543 |
|
|
end if;
|
544 |
|
|
|
545 |
|
|
|
546 |
|
|
|
547 |
|
|
|
548 |
|
|
|
549 |
|
|
--
|
550 |
|
|
-- removal of the cordic gain
|
551 |
|
|
--
|
552 |
|
|
elsif state.st = ST_RM_GAIN then
|
553 |
|
|
-- we need RM_GAIN+1 cycles to
|
554 |
|
|
-- calculate the RM_GAIN steps
|
555 |
|
|
if state.i = (RM_GAIN) then
|
556 |
|
|
state.st <= ST_DONE;
|
557 |
|
|
state.done <= '1';
|
558 |
|
|
state.i <= ( others => '0' );
|
559 |
|
|
else
|
560 |
|
|
state.i <= state.i + 1;
|
561 |
|
|
end if;
|
562 |
|
|
|
563 |
|
|
if state.mode( 1 downto 0 ) = VAL_MODE_CIR then
|
564 |
|
|
mult_0_61( state.x, state.x_sh, state.x_sum, to_integer( state.i ), RM_GAIN );
|
565 |
|
|
mult_0_61( state.y, state.y_sh, state.y_sum, to_integer( state.i ), RM_GAIN );
|
566 |
|
|
elsif state.mode( 1 downto 0 ) = VAL_MODE_HYP then
|
567 |
|
|
mult_0_21( state.x, state.x_sh, state.x_sum, to_integer( state.i ), RM_GAIN );
|
568 |
|
|
mult_0_21( state.y, state.y_sh, state.y_sum, to_integer( state.i ), RM_GAIN );
|
569 |
|
|
else
|
570 |
|
|
-- TODO merge ST_DONE and state.done
|
571 |
|
|
state.done <= '1';
|
572 |
|
|
state.st <= ST_DONE;
|
573 |
|
|
state.x_sum <= state.x;
|
574 |
|
|
state.y_sum <= state.y;
|
575 |
|
|
end if;
|
576 |
|
|
|
577 |
|
|
|
578 |
|
|
elsif state.st = ST_DONE then
|
579 |
|
|
state.st <= ST_IDLE;
|
580 |
|
|
state.done <= '0';
|
581 |
|
|
end if;
|
582 |
|
|
-- end states
|
583 |
|
|
|
584 |
|
|
|
585 |
|
|
|
586 |
|
|
end if;
|
587 |
|
|
-- end ena
|
588 |
|
|
|
589 |
|
|
|
590 |
|
|
end if;
|
591 |
|
|
-- end clk
|
592 |
|
|
|
593 |
|
|
end process;
|
594 |
|
|
done <= state.done ;
|
595 |
|
|
x_o <= std_logic_vector( state.x_sum );
|
596 |
|
|
y_o <= std_logic_vector( state.y_sum );
|
597 |
|
|
a_o <= std_logic_vector( state.a );
|
598 |
|
|
|
599 |
|
|
end architecture BEHAVIORAL;
|
600 |
|
|
|
601 |
|
|
|
602 |
|
|
|