1 | ----------------------------------------------------------------------------------
|
---|
2 | -- Company: ETH Zurich, Institute for Particle Physics
|
---|
3 | -- Engineer: P. Vogler, Q. Weitzel
|
---|
4 | --
|
---|
5 | -- Create Date: 08/04/2010
|
---|
6 | -- Design Name:
|
---|
7 | -- Module Name: FTU_test8_dac_control - Behavioral
|
---|
8 | -- Project Name:
|
---|
9 | -- Target Devices:
|
---|
10 | -- Tool versions:
|
---|
11 | -- Description: test8 for controling DAC on FTU board
|
---|
12 | --
|
---|
13 | -- Dependencies:
|
---|
14 | --
|
---|
15 | -- Revision:
|
---|
16 | -- Revision 0.01 - File Created
|
---|
17 | -- Additional Comments:
|
---|
18 | --
|
---|
19 | ----------------------------------------------------------------------------------
|
---|
20 | library IEEE;
|
---|
21 | use IEEE.STD_LOGIC_1164.ALL;
|
---|
22 | use IEEE.STD_LOGIC_ARITH.ALL;
|
---|
23 | use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
---|
24 | library ftu_definitions_test8;
|
---|
25 | USE ftu_definitions_test8.ftu_array_types.all;
|
---|
26 |
|
---|
27 | ---- Uncomment the following library declaration if instantiating
|
---|
28 | ---- any Xilinx primitives in this code.
|
---|
29 | --library UNISIM;
|
---|
30 | --use UNISIM.VComponents.all;
|
---|
31 |
|
---|
32 | entity FTU_test8_dac_control is
|
---|
33 | port(
|
---|
34 | clk : IN STD_LOGIC;
|
---|
35 | reset : IN STD_LOGIC;
|
---|
36 | clr : OUT STD_LOGIC;
|
---|
37 | mosi : OUT STD_LOGIC;
|
---|
38 | sck : OUT STD_LOGIC;
|
---|
39 | cs_ld : out STD_LOGIC;
|
---|
40 | enable1 : out STD_LOGIC;
|
---|
41 | enable2 : out STD_LOGIC;
|
---|
42 | enable3 : out STD_LOGIC
|
---|
43 | );
|
---|
44 | end FTU_test8_dac_control;
|
---|
45 |
|
---|
46 | architecture Behavioral of FTU_test8_dac_control is
|
---|
47 |
|
---|
48 | component FTU_test8_spi_interface
|
---|
49 | port(
|
---|
50 | clk_50MHz : IN std_logic;
|
---|
51 | config_start : IN std_logic;
|
---|
52 | dac_array : IN dac_array_type;
|
---|
53 | config_ready : OUT std_logic;
|
---|
54 | config_started : OUT std_logic;
|
---|
55 | dac_cs : OUT std_logic;
|
---|
56 | mosi : OUT std_logic;
|
---|
57 | sclk : OUT std_logic;
|
---|
58 | miso : INOUT std_logic
|
---|
59 | );
|
---|
60 | end component;
|
---|
61 |
|
---|
62 | signal clk_sig : std_logic;
|
---|
63 | signal reset_sig : std_logic;
|
---|
64 |
|
---|
65 | signal clr_sig : std_logic;
|
---|
66 | signal mosi_sig : std_logic := '0';
|
---|
67 | signal serial_clock_sig : std_logic;
|
---|
68 | signal dac_cs_sig : std_logic;
|
---|
69 |
|
---|
70 | signal config_start_sig : std_logic := '0';
|
---|
71 | signal config_ready_sig : std_logic;
|
---|
72 | signal config_started_sig : std_logic := '0';
|
---|
73 | signal dac_array_sig : dac_array_type := (0,0,0,0,0,0,0,100);
|
---|
74 |
|
---|
75 | -- Build an enumerated type for the state machine
|
---|
76 | type state_type is (START, SET, WAITING, WAITING_MORE, STOP);
|
---|
77 |
|
---|
78 | -- Register to hold the current state
|
---|
79 | signal state : state_type;
|
---|
80 |
|
---|
81 | signal ramp_cnt : integer range 0 to 45 := 0;
|
---|
82 | constant RAMP_STEP : integer := 91;
|
---|
83 |
|
---|
84 | --signal wait_cnt : integer range 0 to 150000000 := 0; --implement
|
---|
85 | signal wait_cnt : integer range 0 to 10 := 0; --simulation
|
---|
86 | --change this also below!!!
|
---|
87 |
|
---|
88 | begin
|
---|
89 |
|
---|
90 | reset_sig <= reset;
|
---|
91 | clk_sig <= clk;
|
---|
92 | mosi <= mosi_sig;
|
---|
93 | sck <= serial_clock_sig;
|
---|
94 | cs_ld <= dac_cs_sig;
|
---|
95 |
|
---|
96 | -- FSM for dac control: second process
|
---|
97 | FSM_logic: process(clk_sig)
|
---|
98 | begin
|
---|
99 | if rising_edge(clk_sig) then
|
---|
100 | case state is
|
---|
101 | when START =>
|
---|
102 | dac_array_sig <= (0,0,0,0,0,0,0,100);
|
---|
103 | config_start_sig <= '0';
|
---|
104 | enable1 <= '0';
|
---|
105 | enable2 <= '1';
|
---|
106 | enable3 <= '1';
|
---|
107 | state <= SET;
|
---|
108 | when SET =>
|
---|
109 | dac_array_sig <= (ramp_cnt*91,ramp_cnt*91,ramp_cnt*91,ramp_cnt*91,0,0,0,100);
|
---|
110 | config_start_sig <= '1';
|
---|
111 | enable1 <= '0';
|
---|
112 | enable2 <= '1';
|
---|
113 | enable3 <= '1';
|
---|
114 | if config_started_sig = '1' then
|
---|
115 | state <= WAITING;
|
---|
116 | else
|
---|
117 | state <= SET;
|
---|
118 | end if;
|
---|
119 | when WAITING =>
|
---|
120 | dac_array_sig <= (ramp_cnt*91,ramp_cnt*91,ramp_cnt*91,ramp_cnt*91,0,0,0,100);
|
---|
121 | config_start_sig <= '1';
|
---|
122 | enable1 <= '0';
|
---|
123 | enable2 <= '1';
|
---|
124 | enable3 <= '1';
|
---|
125 | if (config_ready_sig = '1') then
|
---|
126 | state <= WAITING_MORE;
|
---|
127 | else
|
---|
128 | state <= WAITING;
|
---|
129 | end if;
|
---|
130 | when WAITING_MORE =>
|
---|
131 | dac_array_sig <= (ramp_cnt*91,ramp_cnt*91,ramp_cnt*91,ramp_cnt*91,0,0,0,100);
|
---|
132 | config_start_sig <= '0';
|
---|
133 | enable1 <= '1';
|
---|
134 | enable2 <= '0';
|
---|
135 | enable3 <= '1';
|
---|
136 | if wait_cnt < 10 then
|
---|
137 | wait_cnt <= wait_cnt + 1;
|
---|
138 | state <= WAITING_MORE;
|
---|
139 | else
|
---|
140 | wait_cnt <= 0;
|
---|
141 | if (ramp_cnt < 45) then
|
---|
142 | ramp_cnt <= ramp_cnt + 1;
|
---|
143 | state <= SET;
|
---|
144 | else
|
---|
145 | state <= STOP;
|
---|
146 | end if;
|
---|
147 | end if;
|
---|
148 | when STOP =>
|
---|
149 | dac_array_sig <= (0,0,0,0,0,0,0,100);
|
---|
150 | enable1 <= '1';
|
---|
151 | enable2 <= '1';
|
---|
152 | enable3 <= '0';
|
---|
153 | config_start_sig <= '0';
|
---|
154 | end case;
|
---|
155 | end if;
|
---|
156 | end process;
|
---|
157 |
|
---|
158 | Inst_FTU_test8_spi_interface : FTU_test8_spi_interface
|
---|
159 | port map(
|
---|
160 | clk_50MHz => clk_sig,
|
---|
161 | config_start => config_start_sig,
|
---|
162 | dac_array => dac_array_sig,
|
---|
163 | config_ready => config_ready_sig,
|
---|
164 | config_started => config_started_sig,
|
---|
165 | dac_cs => dac_cs_sig,
|
---|
166 | mosi => mosi_sig,
|
---|
167 | sclk => serial_clock_sig,
|
---|
168 | miso => open
|
---|
169 | );
|
---|
170 |
|
---|
171 | end Behavioral;
|
---|
172 |
|
---|