📄 cordic_m1_rot.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
package mypack is --定义右移的函数
function ShiftRight (a: signed; n: integer) return signed;
end ;
package body mypack is
function ShiftRight (a : in signed;n: in integer)
return signed is
variable b : signed(a'length-1 downto 0);
subtype rtype is signed(n-1 downto 0);
begin
b(a'length-1-n downto 0) :=a(a'length-1 downto n);
b(a'length-1 downto a'length-n) :=rtype'(others =>a(a'length-1));
return b;
end function ShiftRight;
end;
library ieee;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
PACKAGE eight_bit_int is -- user defined types
SUBTYPE BYTE16 is signed(15 downto 0);
TYPE ARRAY_BYTE is ARRAY (0 TO 15) of BYTE16;
end eight_bit_int;
LIBRARY work;
use work.eight_bit_int.all;
use work.mypack.all;
library ieee;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
ENTITY cordic_m1_rot is ----->8级流水线结构
PORT (clk : in STD_LOGIC; ------> interface
r_in , phi_in : in signed(15 downto 0);
x_out,y_out: out std_logic_vector(15 downto 0);
eps:out signed(15 downto 0));
end cordic_m1_rot;
ARCHITECTURE flex of cordic_m1_rot is
signal x, y, z : ARRAY_BYTE; -- Array of Bytes
signal x0,y0,z0:signed(15 downto 0);
begin
process(clk) ------> Behavioral Style
begin
if clk'event and clk='1' then -- Compute last value first in
x_out<=conv_std_logic_vector(x(15),16)+"1000000000000000"; -- sequential VHDL statements !!
eps<= z(15);
y_out<= conv_std_logic_vector(y(15),16)+"1000000000000000";
if z(14) >= 0 then -- rotate 3 degrees
x(15) <= x(14) - ShiftRight(y(14),14);
y(15) <= y(14) + ShiftRight(x(14),14);
z(15) <= z(14) - 1;
else
x(15) <= x(14) + ShiftRight(y(14),14);
y(15) <= y(14) - ShiftRight(x(14),14);
z(15) <= z(14) + 1;
end if;
if z(13) >= 0 then -- rotate 3 degrees
x(14) <= x(13) - ShiftRight(y(13),13);
y(14) <= y(13) + ShiftRight(x(13),13);
z(14) <= z(13) - 1;
else
x(14) <= x(13) + ShiftRight(y(13),13);
y(14) <= y(13) - ShiftRight(x(13),13);
z(14) <= z(13) + 1;
end if;
if z(12) >= 0 then -- rotate 3 degrees
x(13) <= x(12) - ShiftRight(y(12),12);
y(13) <= y(12) + ShiftRight(x(12),12);
z(13) <= z(12) - 3;
else
x(13) <= x(12) + ShiftRight(y(12),12);
y(13) <= y(12) - ShiftRight(x(12),12);
z(13) <= z(12) + 3;
end if;
if z(11) >= 0 then -- rotate 3 degrees
x(12) <= x(11) - ShiftRight(y(11),11);
y(12) <= y(11) + ShiftRight(x(11),11);
z(12) <= z(11) - 5;
else
x(12) <= x(11) + ShiftRight(y(11),11);
y(12) <= y(11) - ShiftRight(x(11),11);
z(12) <= z(11) + 5;
end if;
if z(10) >= 0 then -- rotate 3 degrees
x(11) <= x(10) - ShiftRight(y(10),10);
y(11) <= y(10) + ShiftRight(x(10),10);
z(11) <= z(10) - 10;
else
x(11) <= x(10) + ShiftRight(y(10),10);
y(11) <= y(10) - ShiftRight(x(10),10);
z(11) <= z(10) + 10;
end if;
if z(9) >= 0 then -- rotate 3 degrees
x(10) <= x(9) - ShiftRight(y(9),9);
y(10) <= y(9) + ShiftRight(x(9),9);
z(10) <= z(9) - 20;
else
x(10) <= x(9) + ShiftRight(y(9),9);
y(10) <= y(9) - ShiftRight(x(9),9);
z(10) <= z(9) + 20;
end if;
if z(8) >= 0 then -- rotate 3 degrees
x(9) <= x(8) - ShiftRight(y(8),8);
y(9) <= y(8) + ShiftRight(x(8),8);
z(9) <= z(8) - 40;
else
x(9) <= x(8) + ShiftRight(y(8),8);
y(9) <= y(8) - ShiftRight(x(8),8);
z(9) <= z(8) + 40;
end if;
if z(7) >= 0 then -- rotate 3 degrees
x(8) <= x(7) - ShiftRight(y(7),7);
y(8) <= y(7) + ShiftRight(x(7),7);
z(8) <= z(7) - 81;
else
x(8) <= x(7) + ShiftRight(y(7),7);
y(8) <= y(7) - ShiftRight(x(7),7);
z(8) <= z(7) + 81;
end if;
if z(6) >= 0 then -- rotate 1 degrees
x(7) <= x(6) - ShiftRight(y(6),6);
y(7) <= y(6) + ShiftRight(x(6),6);
z(7) <= z(6) - 163;
else
x(7) <= x(6) + ShiftRight(y(6),6);
y(7) <= y(6) - ShiftRight(x(6),6);
z(7) <= z(6) + 163;
end if;
if z(5) >= 0 then -- rotate 1 degrees
x(6) <= x(5) - ShiftRight(y(5),5);
y(6) <= y(5) + ShiftRight(x(5),5);
z(6) <= z(5) - 326;
else
x(6) <= x(5) + ShiftRight(y(5),5);
y(6) <= y(5) - ShiftRight(x(5),5);
z(6) <= z(5) + 326;
end if;
if z(4) >=0 then -- rotate 3 degrees
x(5) <= x(4) - ShiftRight(y(4),4);
y(5) <= y(4) + ShiftRight(x(4),4);
z(5) <= z(4) - 651;
else
x(5) <= x(4) + ShiftRight(y(4),4);
y(5) <= y(4) - ShiftRight(x(4),4);
z(5) <= z(4) + 651;
end if;
if z(3) >= 0 then -- rotate 7 degrees
x(4) <= x(3) - ShiftRight(y(3),3);
y(4) <= y(3) + ShiftRight(x(3),3);
z(4) <= z(3) - 1297;
else
x(4) <= x(3) + ShiftRight(y(3),3);
y(4) <= y(3) - ShiftRight(x(3),3);
z(4) <= z(3) + 1297;
end if;
if z(2) >= 0 then -- rotate 14 degrees
x(3) <= x(2) - ShiftRight(y(2),2);
y(3) <= y(2) + ShiftRight(x(2),2);
z(3) <= z(2) - 2555;
else
x(3) <= x(2) + ShiftRight(y(2),2);
y(3) <= y(2) - ShiftRight(x(2),2);
z(3) <= z(2) + 2555;
end if;
if z(1) >= 0 then -- rotate 26 degrees
x(2) <= x(1) - ShiftRight(y(1),1);
y(2) <= y(1) + ShiftRight(x(1),1);
z(2) <= z(1) - 4836;
else
x(2) <= x(1) + ShiftRight(y(1),1);
y(2) <= y(1) - ShiftRight(x(1),1);
z(2) <= z(1) + 4836;
end if;
if z(0) >= 0 then -- rotate 45 degrees
x(1) <= x(0) - y(0);
y(1) <= y(0) + x(0);
z(1) <= z(0) - 8192;
else
x(1) <= x(0) + y(0);
y(1) <= y(0) - x(0);
z(1) <= z(0) + 8192;
end if;
if phi_in >=0 then
x(0)<= "0000000000000000"; -- input in register 0
y(0)<= r_in;
z(0)<= phi_in-16384;
else
x(0)<= "0000000000000000";
y(0)<=-r_in;
z(0)<= phi_in+16384;
end if;
end if;
end process;
end flex;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -