Debian Codegraph @

hdl/fpga/ip/nuand/synthesis/tan_table.vhd

raw
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 use ieee.math_real.all;
5
6 entity tan_table is
7 generic(
8 Q : positive := 12;
9 INPUT_WIDTH : positive := 16;
10 OUTPUT_WIDTH: positive := 16;
11 STEPS : positive := 4;
12 ANGLE : real := MATH_PI*(45.0/180.0)
13 );
14 port(
15 reset : in std_logic;
16 clock : in std_logic;
17
18 phase : in signed(INPUT_WIDTH-1 downto 0);
19 phase_valid : in std_logic;
20
21 y : out signed(OUTPUT_WIDTH-1 downto 0);
22 y_valid : out std_logic
23 );
24 end entity;
25
26
27 architecture arch of tan_table is
28
29 type tan_table_t is array (natural range <>) of signed(OUTPUT_WIDTH-1 downto 0);
30 type tan_table_real_t is array (natural range <>) of real;
31
32 function generate_tan_table(steps, qscale : positive) return tan_table_t is
33 variable table : tan_table_t(0 to steps) := (others => (others => '0'));
34 begin
35 for i in table'range loop
36 table(i) := to_signed(integer(round(real(2**qscale)* tan(ANGLE * real(i)/real(steps)))),table(i)'length);
37 end loop;
38 return table;
39 end function;
40
41 function generate_tan_table_real(steps : positive) return tan_table_real_t is
42 variable table : tan_table_real_t(0 to steps) := (others => (0.0));
43 begin
44 for i in table'range loop
45 table(i) :=tan(ANGLE * real(i)/real(steps));
46 end loop;
47 return table;
48 end function;
49
50
51 constant table : tan_table_t(0 to STEPS) := generate_tan_table(STEPS,Q);
52 constant table_2 : tan_table_real_t(0 to STEPS) := generate_tan_table_real(STEPS);
53
54 begin
55
56 find_y : process(clock, reset)
57 begin
58 if reset = '1' then
59 --
60 y_valid <= '0';
61 y <= (others => '0');
62 elsif rising_edge(clock) then
63 y_valid <= '0';
64 if phase_valid = '1' then
65 if phase < 0 then
66 y <= table(to_integer(abs(phase)));
67 else
68 y <= -table(to_integer(abs(phase)));
69 end if;
70
71 y_valid <= '1';
72 end if;
73 --
74 end if;
75 end process;
76
77 end architecture;