]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - vector_gen.vhd
Wave_table initialization data format modified.
[fpga/pwm.git] / vector_gen.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 use ieee.std_logic_unsigned.all;
5
6 --------------------------------------------------------------------------------
7
8 entity vector_gen is
9   generic (
10     LUT_DAT_W  : integer := 10;
11     LUT_ADR_W  : integer := 9;
12     LUT_P1_OFF : integer := 0;
13     LUT_P2_OFF : integer := 171;
14     LUT_P3_OFF : integer := 341;
15     IRF_ADR_W  : integer := 5;
16     A_BASE     : integer := 0;
17     P_BASE     : integer := 1;
18     P1_OFF     : integer := 0;
19     P2_OFF     : integer := 1;
20     P3_OFF     : integer := 2);
21   port (
22     -- Primary slave interface
23     ACK_O     : out std_logic;
24     CLK_I     : in  std_logic;
25     RST_I     : in  std_logic;
26     STB_I     : in  std_logic;
27     -- Master interface to the interface memory
28     IRF_ACK_I : in  std_logic;
29     IRF_ADR_O : out std_logic_vector (IRF_ADR_W-1 downto 0);
30     IRF_CYC_O : out std_logic;
31     IRF_DAT_I : in  std_logic_vector (15 downto 0);
32     IRF_DAT_O : out std_logic_vector (15 downto 0);
33     IRF_STB_O : out std_logic := '0';
34     IRF_WE_O  : out std_logic;
35     -- Master interface to the wave look-up-table
36     LUT_ADR_O : out std_logic_vector (LUT_ADR_W-1 downto 0);
37     LUT_DAT_I : in  std_logic_vector (LUT_DAT_W-1 downto 0);
38     LUT_STB_O : out std_logic);
39 end entity vector_gen;
40
41 --------------------------------------------------------------------------------
42
43 architecture behavioral of vector_gen is
44
45   type state_t is (ready, angle, phase1, phase2, phase3, done);
46   subtype irf_adr_t is std_logic_vector (IRF_ADR_W-1 downto 0);
47   subtype lut_adr_t is std_logic_vector (LUT_ADR_W-1 downto 0);
48
49   constant A_ADR  : irf_adr_t := conv_std_logic_vector(A_BASE, IRF_ADR_W);
50   constant P1_ADR : irf_adr_t := conv_std_logic_vector(P_BASE+P1_OFF, IRF_ADR_W);
51   constant P2_ADR : irf_adr_t := conv_std_logic_vector(P_BASE+P2_OFF, IRF_ADR_W);
52   constant P3_ADR : irf_adr_t := conv_std_logic_vector(P_BASE+P3_OFF, IRF_ADR_W);
53
54   signal state     : state_t := ready;
55   signal angle_in  : lut_adr_t;
56   signal ack_latch : std_logic := '0';
57
58 --------------------------------------------------------------------------------
59   
60 begin
61
62   IRF_DAT_O (IRF_DAT_O'HIGH downto LUT_DAT_I'HIGH+1) <= (others => '0');
63   IRF_DAT_O (LUT_DAT_I'RANGE) <= LUT_DAT_I;
64   
65   ACK_O <= ack_latch and STB_I;
66
67   
68   FSM : process (CLK_I) is
69   begin
70     if rising_edge(CLK_I) then
71       if RST_I = '1' or STB_I = '0' then
72         state     <= ready;
73         ack_latch <= '0';
74         IRF_CYC_O <= '0';
75         IRF_STB_O <= '0';
76         IRF_WE_O  <= '0';
77         LUT_STB_O <= '0';
78
79       else
80         case state is
81           when ready =>
82             if STB_I = '1' then
83               state     <= angle;
84               IRF_ADR_O <= A_ADR;
85               IRF_CYC_O <= '1';
86               IRF_STB_O <= '1';
87             end if;
88
89           when angle =>
90             if IRF_ACK_I = '1' then
91               state     <= phase1;
92               angle_in  <= IRF_DAT_I(angle_in'RANGE);
93               LUT_ADR_O <= IRF_DAT_I(angle_in'RANGE) + LUT_P1_OFF;
94               LUT_STB_O <= '1';
95             end if;
96             
97           when phase1 =>
98             state     <= phase2;
99             IRF_ADR_O <= P1_ADR;
100             IRF_WE_O  <= '1';
101             LUT_ADR_O <= angle_in + LUT_P2_OFF;
102             
103           when phase2 =>
104             state     <= phase3;
105             IRF_ADR_O <= P2_ADR;
106             LUT_ADR_O <= angle_in + LUT_P3_OFF;
107
108           when phase3 =>
109             state     <= done;
110             IRF_ADR_O <= P3_ADR;
111
112             
113           when done =>
114             ack_latch <= '1';
115             IRF_CYC_O <= '0';
116             IRF_STB_O <= '0';
117             IRF_WE_O  <= '0';
118             LUT_STB_O <= '0';
119         end case;
120
121       end if;
122     end if;
123   end process;
124
125 end architecture behavioral;
126