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

📄 sc.tdf

📁 计算机算术是微处理器运算的数学基础,其中一个非常重要的部分就是超越函数的计算问题。数学函数的VHDL实现
💻 TDF
字号:
FUNCTION lpm_clshift (data[LPM_WIDTH-1..0], distance[LPM_WIDTHDIST-1..0], direction)
   WITH (LPM_WIDTH=width, LPM_WIDTHDIST=Ceil(log2(width)), LPM_SHIFTTYPE="ARITHMETIC")
   RETURNS (result[LPM_WIDTH-1..0], underflow, overflow);

FUNCTION lpm_add_sub (cin, dataa[LPM_WIDTH-1..0], datab[LPM_WIDTH-1..0], add_sub, clock, aclr)
   WITH (LPM_WIDTH=width, LPM_REPRESENTATION="SIGNED", LPM_DIRECTION, LPM_PIPELINE, ONE_INPUT_IS_CONSTANT)
   RETURNS (result[LPM_WIDTH-1..0], cout, overflow);

parameters
(
        width=16
);

constant maxcount=width-1;

subdesign SC
(
        angle[width-1..0]                                       :       input;          -- angle (rad)

        -- angle(deg)*143 or angle(rad)*8192

        clock                                                           :       input;          -- 20MHz clock
        reset                                                           :       input;          -- global reset

        sin[width-1..0]                                         :       output;         -- sine result
        cos[width-1..0]                                         :       output;         -- cosine result

        -- result=sin/8192 || cos/8192

)
variable
        fn_add_sub[3..1]                                        :       lpm_add_sub;
        fn_shift[2..1]                                          :       lpm_clshift;
        
        bitcount[ceil(log2(width))-1..0]        :       dff;
        rx[width-1..0]                                          :       dff;
        ry[width-1..0]                                          :       dff;
        ra[width-1..0]                                          :       dff;

        sm                                                                      :       machine with states (s1,s2,s3);

begin
        case bitcount[] is
                when 0 =>
                        fn_add_sub[3].datab[]=6434;             -- 8192*atn(1)
                when 1 =>
                        fn_add_sub[3].datab[]=3798;             -- 8192*atn(1/2)
                when 2 =>
                        fn_add_sub[3].datab[]=2007;             -- 8192*atn(1/4)
                when 3 =>
                        fn_add_sub[3].datab[]=1019;             -- 8192*atn(1/8)
                when 4 =>
                        fn_add_sub[3].datab[]=512;              -- 8192*atn(1/16)
                when 5 =>
                        fn_add_sub[3].datab[]=256;              -- 8192*atn(1/32)
                when 6 =>
                        fn_add_sub[3].datab[]=128;              -- 8192*atn(1/64)
                when 7 =>
                        fn_add_sub[3].datab[]=64;               -- 8192*atn(1/128)
                when 8 =>
                        fn_add_sub[3].datab[]=32;               -- 8192*atn(1/256)
                when 9 =>
                        fn_add_sub[3].datab[]=16;               -- 8192*atn(1/512)
                when 10 =>
                        fn_add_sub[3].datab[]=8;                -- 8192*atn(1/1024)
                when 11 =>
                        fn_add_sub[3].datab[]=4;                -- 8192*atn(1/2048)
                when 12 =>
                        fn_add_sub[3].datab[]=2;                -- 8192*atn(1/4096)
                when 13 =>
                        fn_add_sub[3].datab[]=1;                -- 8192*atn(1/8192)
                when 14 =>
                        fn_add_sub[3].datab[]=0;                -- 8192*atn(1/16384)
                when 15 =>
                        fn_add_sub[3].datab[]=0;                -- 8192*atn(1/32768)
        end case;
        sin[]=rx[];
        cos[]=ry[];
        sm.clk=clock;
        sm.reset=reset;
        bitcount[]=bitcount[]+1;
        bitcount[].clk=((not clock) and (sm==s2));
        case sm is
                when s1 =>
                        -- initial x=0.6072544793
                        -- first state to initialise variables
                        rx[]=4975;
                        ra[]=angle[];
                        ry[]=0;
                        sm=s2;
                        rx[].clk=!clock;
                        ry[].clk=!clock;
                        ra[].clk=!clock;
                when s2 =>
                        -- handle the barrel shifter
                        fn_shift[1].data[]=ry[];
                        fn_shift[1].distance[]=bitcount[];
                        fn_shift[1].direction=vcc;
                        fn_shift[2].data[]=rx[];
                        fn_shift[2].distance[]=bitcount[];
                        fn_shift[2].direction=vcc;
                        -- add or subtract?
                        fn_add_sub[1].add_sub=ra[width-1];
                        fn_add_sub[2].add_sub=(not ra[width-1]);
                        fn_add_sub[3].add_sub=ra[width-1];
                        -- perform the math
                        fn_add_sub[1].dataa[]=rx[];
                        fn_add_sub[1].datab[]=fn_shift[1].result[];
                        fn_add_sub[2].dataa[]=ry[];
                        fn_add_sub[2].datab[]=fn_shift[2].result[];
                        fn_add_sub[3].dataa[]=ra[];
                        -- new sub result
                        rx[]=fn_add_sub[1].result[];
                        ry[]=fn_add_sub[2].result[];
                        ra[]=fn_add_sub[3].result[];
                        rx[].clk=!clock;
                        ry[].clk=!clock;
                        ra[].clk=!clock;
                        if (bitcount[]==maxcount) then
                                sm=s3;
                        end if;
                when s3 =>
                        -- state in halt mode till reset
                        sm=s3;
        end case;
end;

⌨️ 快捷键说明

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