⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄

📁 自己写的cordic 的 64位计算反正切的程序
💻
字号:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
--------------------------------------------------------------------------------
package mypack is
function shiftright(a:std_logic_vector;n:integer) return  std_logic_vector;
end;
package body mypack is
   function shiftright(a:in std_logic_vector;n:in integer)
     return   std_logic_vector is
     variable b  :std_logic_vector(a'length-1 downto 0);
subtype rtype is std_logic_vector(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_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
use work.mypack.all;
entity artan_ch is
port(clk:in std_logic;
     rst,en:std_logic;
     --anjer:in std_logic_vector(31 downto 0);
     ysin:in std_logic_vector(63 downto 0);
     --xcos:in std_logic_vector(31 downto 0);
     --xsx:out std_logic_vector(32 downto 0);
     --ysy:out std_logic_vector(32 downto 0);
     --zout:out std_logic_vector(31 downto 0);
     anjer:out std_logic_vector(31 downto 0)
     --xcos:buffer std_logic_vector(31 downto 0);
     --xsin:buffer std_logic_vector(31 downto 0)
);
end entity;
architecture behave of artan_ch is
    type database is array(0 to 31) of std_logic_vector(31 downto 0);                   
begin
process(clk,en,rst)
    variable x0:std_logic_vector(64 downto 0);
    variable y0:std_logic_vector(64 downto 0);
    variable x,y:std_logic_vector(64 downto 0);
    variable z:std_logic_vector(31 downto 0);
    variable n:integer range 0 to 33;
    variable xs,ys:std_logic_vector(64 downto 0);
    variable ansign:std_logic_vector(2 downto 0);
    --variable nq:integer range 0 to 1; 
    --constant pp :std_logic_vector(32 downto 0):="001001101101110100111011011010011";
    constant bz :std_logic_vector(31 downto 0):="00000000000000000000000000000000";
    constant xcos:std_logic_vector(64 downto 0):="00000000000000000000000000000000001111111111111111111111111111111";
    constant actg :database:=
     ("01000000000000000000000000000000",
      "00100101110010000000101000111011",
      "00010011111101100111000010110111",
      "00001010001000100010001110101000",
      "00000101000101100001101010000110",
      "00000010100010111010111111000011",
      "00000001010001011110110000111101",
      "00000000101000101111100010101010",
      "00000000010100010111110010100111",
      "00000000001010001011111001011101",
      "00000000000101000101111100110000",
      "00000000000010100010111110011000",
      "00000000000001010001011111001100",
      "00000000000000101000101111100110",
      "00000000000000010100010111110011",
      "00000000000000001010001011111010",
      "00000000000000000101000101111101",
      "00000000000000000010100010111110",
      "00000000000000000001010001011111",
      "00000000000000000000101000110000",
      "00000000000000000000010100011000",
      "00000000000000000000001010001100",
      "00000000000000000000000101000110",
      "00000000000000000000000010100011",
      "00000000000000000000000001010001",
      "00000000000000000000000000101001",
      "00000000000000000000000000010100",
      "00000000000000000000000000001010",
      "00000000000000000000000000000101",
      "00000000000000000000000000000011",
      "00000000000000000000000000000001",
      "00000000000000000000000000000001"
     );
    --variable i:integer range 0 to 33:=0;
begin
   if(rst='1') then 
     -- xcos<="00000000000000000000000000000000";  
      --ysin<="00000000000000000000000000000000"; 
      anjer<="00000000000000000000000000000000"; 
   elsif(clk'event and clk='1') then
      if(en='1') then 
         xs:=xcos;
         ys:=ysin(63)&ysin;
         if (ys(64)='0')then
            x0:=xs+ys;
            y0:=ys-xs;
            z:=actg(0);
         else
            x0:=xs-ys;
            y0:=ys+xs;
            z:=bz-actg(0);
         end if;
         --zout<=z;
         --if(anjer(31)='0')then
            --y0:=pp;
            --z:=anjer-actg(0);
        -- else
            --y0:=0-pp;
            --z:=anjer+actg(0);
         --end if;
      for n in 1 to 31 loop
         if y0(64)='0' then
            x:=x0+shiftright(y0,n);
            y:=y0-shiftright(x0,n);
            z:=z+actg(n);
         else
            x:=x0-shiftright(y0,n);
            y:=y0+shiftright(x0,n);
            z:=z-actg(n);
         end if;
         x0:=x;
         y0:=y;
      end loop;
      ansign:=ysin(63)&z(31 downto 30);
      case ansign is
         when  "011"  =>  anjer<="00000000000000000000000000000000";
         when  "010"  =>  anjer<="01111111111111111111111111111111";
         --when  "1"
         when  others =>  anjer<=z;
      end case;
         --anjer<=z;
        --xsx<=xs;
        --ysy<=ys;
      --xs:=anjer(31) & x(32 downto 31);
      --ys:=anjer(31) & y(32 downto 31);
      --case xs is
        -- when   "001"  =>  xcos<="01111111111111111111111111111111";
         --when   "111"  =>  xcos<="00000000000000000000000000000000";
        -- when   "101"  =>  xcos<="01111111111111111111111111111111";
        -- when   others =>  xcos<=x(31 downto 0);
      --end case;
      --case ys is
         --when   "001"  =>  xsin<="01111111111111111111111111111111";
         --when   "110"  =>  xsin<="10000000000000000000000000000000";
        -- when   others =>  xsin<=y(31 downto 0);
      --end case;
      else
         --xcos<="00000000000000000000000000000000";
         --xsin<="00000000000000000000000000000000";
         anjer<="00000000000000000000000000000000";
      end if;
  end if;
end process;
end behave;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -