File: cos_table.vhd

package info (click to toggle)
bladerf 0.2017.12~rc1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 14,620 kB
  • sloc: ansic: 50,123; vhdl: 12,873; python: 1,062; tcl: 1,060; xml: 1,017; makefile: 657; sh: 589; csh: 18; cpp: 9
file content (72 lines) | stat: -rw-r--r-- 2,456 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    use ieee.math_real.all;

entity cos_table is
    generic (
        Q :     positive := 12;
        INPUT_LENGTH : positive := 16;
        OUTPUT_LENGTH : positive := 16;
        DPHASE_STEPS_90 : positive := 4
        );
        port(
        reset   :       in std_logic;
        clock   :       in std_logic;

        phase   :       in unsigned(INPUT_LENGTH-1 downto 0);
        phase_valid :   in std_logic;

        y       :       out signed(OUTPUT_LENGTH-1 downto 0);
        y_valid :       out std_logic
        );
end entity;


architecture arch of cos_table is


    type cos_table_t is array(natural range <>) of signed(INPUT_LENGTH-1 downto 0);
    
    function generate_cos_table(steps, qscale : positive) return cos_table_t is
        variable table : cos_table_t(0 to steps + 1) := (others => (others =>'0'));
    begin
        for i in table'range loop
            table(i) := to_signed(integer(round(real(qscale)*cos(MATH_PI/2.0 * real(real(i)/real(steps))))),table(i)'length);
        end loop;
        return table;
    end function;

    constant table : cos_table_t(0 to DPHASE_STEPS_90 +1) := generate_cos_table(DPHASE_STEPS_90, 2**Q); 


begin

    find_y : process(clock,reset)
        variable cur_index : natural;
    begin
        if reset = '1' then
            y <= (others=>'0');
            y_valid <= '0';
        elsif rising_edge(clock) then
            y_valid <= '0';
            if phase_valid = '1' then 
                y_valid <= '1';
                if phase <= DPHASE_STEPS_90 then
                    y <= (table(to_integer(phase)));
                    cur_index := to_integer(phase);
                elsif phase <= (2*DPHASE_STEPS_90) then
                    y <= -(table(DPHASE_STEPS_90 - (to_integer(phase) -(DPHASE_STEPS_90))));
                    cur_index := DPHASE_STEPS_90 - (to_integer(phase) -(DPHASE_STEPS_90));
                elsif phase <= (3*DPHASE_STEPS_90) then
                    y <= -(table(to_integer(phase)- (2*DPHASE_STEPS_90)));
                    cur_index := to_integer(phase)- (2*DPHASE_STEPS_90);
                else
                    y<= (table(DPHASE_STEPS_90 - (to_integer(phase)-(3*DPHASE_STEPS_90))));
                    cur_index := DPHASE_STEPS_90 - (to_integer(phase)-(3*DPHASE_STEPS_90));
                end if;
            end if;
        end if;
    end process;

end architecture;