File: tan_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 (77 lines) | stat: -rw-r--r-- 2,302 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
73
74
75
76
77
library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    use ieee.math_real.all;

entity tan_table is
    generic(
        Q       :       positive := 12;
        INPUT_WIDTH :   positive := 16;
        OUTPUT_WIDTH:   positive := 16;
        STEPS   :       positive := 4;
        ANGLE   :       real := MATH_PI*(45.0/180.0)
    );
    port(
        reset   :       in std_logic;
        clock   :       in std_logic;

        phase   :       in signed(INPUT_WIDTH-1 downto 0);
        phase_valid :   in std_logic;

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


architecture arch of tan_table is

    type tan_table_t is array (natural range <>) of signed(OUTPUT_WIDTH-1 downto 0);
    type tan_table_real_t is array (natural range <>) of real;

    function generate_tan_table(steps, qscale : positive) return tan_table_t is
        variable table : tan_table_t(0 to steps) := (others => (others => '0'));
    begin
        for i in table'range loop
            table(i) := to_signed(integer(round(real(2**qscale)* tan(ANGLE * real(i)/real(steps)))),table(i)'length);
        end loop;
        return table;
    end function;

    function generate_tan_table_real(steps : positive) return tan_table_real_t is
        variable table : tan_table_real_t(0 to steps) := (others => (0.0));
    begin
        for i in table'range loop
            table(i) :=tan(ANGLE * real(i)/real(steps));
        end loop;
        return table;
    end function;


    constant table : tan_table_t(0 to STEPS) := generate_tan_table(STEPS,Q);
    constant table_2 : tan_table_real_t(0 to STEPS) := generate_tan_table_real(STEPS);

begin

    find_y : process(clock, reset)
    begin
        if reset = '1' then
            --
            y_valid <= '0';
            y <= (others => '0');
        elsif rising_edge(clock) then
            y_valid <= '0';
            if phase_valid = '1' then
                if phase < 0 then
                    y <= table(to_integer(abs(phase)));
                else
                    y <= -table(to_integer(abs(phase)));
                end if;
                
                y_valid <= '1';
            end if;
            --
        end if;
    end process;

end architecture;