Debian Codegraph @

hdl/fpga/ip/nuand/synthesis/cos_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 cos_table is
7 generic (
8 Q : positive := 12;
9 INPUT_LENGTH : positive := 16;
10 OUTPUT_LENGTH : positive := 16;
11 DPHASE_STEPS_90 : positive := 4
12 );
13 port(
14 reset : in std_logic;
15 clock : in std_logic;
16
17 phase : in unsigned(INPUT_LENGTH-1 downto 0);
18 phase_valid : in std_logic;
19
20 y : out signed(OUTPUT_LENGTH-1 downto 0);
21 y_valid : out std_logic
22 );
23 end entity;
24
25
26 architecture arch of cos_table is
27
28
29 type cos_table_t is array(natural range <>) of signed(INPUT_LENGTH-1 downto 0);
30
31 function generate_cos_table(steps, qscale : positive) return cos_table_t is
32 variable table : cos_table_t(0 to steps + 1) := (others => (others =>'0'));
33 begin
34 for i in table'range loop
35 table(i) := to_signed(integer(round(real(qscale)*cos(MATH_PI/2.0 * real(real(i)/real(steps))))),table(i)'length);
36 end loop;
37 return table;
38 end function;
39
40 constant table : cos_table_t(0 to DPHASE_STEPS_90 +1) := generate_cos_table(DPHASE_STEPS_90, 2**Q);
41
42
43 begin
44
45 find_y : process(clock,reset)
46 variable cur_index : natural;
47 begin
48 if reset = '1' then
49 y <= (others=>'0');
50 y_valid <= '0';
51 elsif rising_edge(clock) then
52 y_valid <= '0';
53 if phase_valid = '1' then
54 y_valid <= '1';
55 if phase <= DPHASE_STEPS_90 then
56 y <= (table(to_integer(phase)));
57 cur_index := to_integer(phase);
58 elsif phase <= (2*DPHASE_STEPS_90) then
59 y <= -(table(DPHASE_STEPS_90 - (to_integer(phase) -(DPHASE_STEPS_90))));
60 cur_index := DPHASE_STEPS_90 - (to_integer(phase) -(DPHASE_STEPS_90));
61 elsif phase <= (3*DPHASE_STEPS_90) then
62 y <= -(table(to_integer(phase)- (2*DPHASE_STEPS_90)));
63 cur_index := to_integer(phase)- (2*DPHASE_STEPS_90);
64 else
65 y<= (table(DPHASE_STEPS_90 - (to_integer(phase)-(3*DPHASE_STEPS_90))));
66 cur_index := DPHASE_STEPS_90 - (to_integer(phase)-(3*DPHASE_STEPS_90));
67 end if;
68 end if;
69 end if;
70 end process;
71
72 end architecture;