2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
5 use work.lx_dad_pkg.all;
12 reset_i : in std_logic;
16 phi_1 : out std_logic;
17 phi_2 : out std_logic;
18 phi_st : out std_logic;
19 ph_rst : out std_logic;
20 -- LED : out std_logic;
21 sck_o : out std_logic;
22 cnv_o : out std_logic;
25 mem_o : out std_logic_vector(31 downto 0);
27 --memory related outputs
28 addr_o : out std_logic_vector(10 downto 0);
29 bls_o : out std_logic_vector(3 downto 0);
34 addr_i : in std_logic_vector(3 downto 0);
35 data_i : in std_logic_vector(31 downto 0);
37 bls_i : in std_logic_vector(3 downto 0);
38 data_o : out std_logic_vector(31 downto 0)
43 architecture rtl of clockgen is
45 --constant CLK_MASTER_FREQ: unsigned := 50000000;
47 signal cntra : unsigned(31 downto 0) := (others => '0');
48 signal pixel : integer range 0 to 2047;
50 signal cntrb : unsigned(31 downto 0) := (others => '0');
52 signal bank : std_logic;
54 signal run_readout : std_logic;
55 signal conv_start : std_logic;
56 signal adc_data_i : std_logic_vector(17 downto 0);
57 signal adc_drdy_i : std_logic;
58 signal run_single : std_logic;
59 signal run_single_last : std_logic;
60 signal run_single_i : std_logic;
61 signal finished : std_logic:='0';
62 signal finished_i : std_logic:='0';
63 signal stability_m : std_logic;
65 type states_i is (i0, i1, i2, i3, i4, i5, i6, i7, i8, iddle);
66 signal state_i : states_i;
68 type meas_states is (normal, multi_per_pixel, leakage);
69 signal state_meas : meas_states;
71 signal t1 : unsigned(31 downto 0);
72 signal t2 : unsigned(31 downto 0);
73 signal t3 : unsigned(31 downto 0);
74 signal t4 : unsigned(31 downto 0);
75 signal t5 : unsigned(31 downto 0);
76 signal t6 : unsigned(31 downto 0);
77 signal t7 : unsigned(31 downto 0);
78 signal t8 : unsigned(31 downto 0);
79 signal t9 : unsigned(31 downto 0) ;
82 signal alive_cntr : integer range 0 to 24999999:=0;
83 signal LED_latch : std_logic:='1';
87 snsor_adc_interface:lx_adc_if
97 conv_start => conv_start,
100 data_o => adc_data_i,
101 drdy_o => adc_drdy_i,
106 -- adc_read : process(reset_i,clk_i)
108 -- if reset_i = '1' then
109 -- elsif rising_edge(clk_i) then
110 -- if adc_drdy_i = '1' and pixel < 1025 then
111 --mem_o <= std_logic_vector(resize(unsigned(adc_data_i), mem_o'length));
112 -- mem_o <= std_logic_vector(to_unsigned((pixel),32));
113 -- addr_o <= bank & std_logic_vector(to_unsigned((pixel),10));
120 interf : process(reset_i,clk_i)
122 if reset_i = '1' then -- set default timing
123 t1 <= "00000000000000000000000000000110"; --6
124 t2 <= "00000000000000000000001111101000"; --9
125 t3 <= "00000000000000000000010001111101"; --1149
126 t4 <= "00000000000000000000001111101000"; --14
127 t5 <= "00000000000000000000000000000110"; --6
128 t6 <= "00000000000000000000001001010111"; --599
129 t7 <= "00000000000000000000001010010010"; --658
130 t8 <= "00000000000000000001001100010000"; --4880
131 t9 <= "00000000000000000000000111110011";
132 data_o <= (others => '0');
135 elsif rising_edge(clk_i) then
137 if finished = '1' then
141 if ce_i = '1' and bls_i /= "0000" then
142 if addr_i = "0000" then
143 run_readout <= data_i(0); --start/stop the readout
144 if data_i(1) = '1' then
148 if data_i(3) = '1' then
149 state_meas <= normal;
150 elsif data_i(4) = '1' then
151 state_meas <= leakage;
153 elsif addr_i = "0001" then
154 t1 <= unsigned(data_i);
155 elsif addr_i = "0010" then
156 t2 <= unsigned(data_i);
157 elsif addr_i = "0011" then
158 t3 <= unsigned(data_i);
159 elsif addr_i = "0100" then
160 t4 <= unsigned(data_i);
161 elsif addr_i = "0101" then
162 t5 <= unsigned(data_i);
163 elsif addr_i = "0110" then
164 t6 <= unsigned(data_i);
165 elsif addr_i <= "0111" then
166 t7 <= unsigned(data_i);
167 elsif addr_i <= "1000" then
168 t8 <= unsigned(data_i);
169 elsif addr_i <= "1001" then
170 t9 <= unsigned(data_i);
174 if addr_i = "0000" then
175 data_o <= (others => '0');
176 data_o(2) <= not bank;
177 data_o(6) <= finished_i;
178 data_o(0) <= run_readout;
179 if state_meas = leakage then
181 elsif state_meas = normal then
183 elsif state_meas = multi_per_pixel then
187 elsif addr_i = "0001" then
188 data_o <= std_logic_vector(t1);
189 elsif addr_i = "0010" then
190 data_o <= std_logic_vector(t2);
191 elsif addr_i = "0011" then
192 data_o <= std_logic_vector(t3);
193 elsif addr_i = "0100" then
194 data_o <= std_logic_vector(t4);
195 elsif addr_i = "0101" then
196 data_o <= std_logic_vector(t5);
197 elsif addr_i = "0110" then
198 data_o <= std_logic_vector(t6);
199 elsif addr_i = "0111" then
200 data_o <= std_logic_vector(t7);
201 elsif addr_i = "1000" then
202 data_o <= std_logic_vector(t8);
203 elsif addr_i = "1001" then
204 data_o <= std_logic_vector(t9);
211 proc : process(clk_i, reset_i)
215 cntra <= (others => '0');
221 elsif rising_edge(clk_i) then
226 if run_single = '1' then
229 if run_readout = '1' then
232 cntrb <= (others => '0');
234 -- if start_readout = '1' then
243 mem_o <= "00000000000000"&adc_data_i;
244 --mem_o <= std_logic_vector(to_unsigned((pixel-1),32));
245 addr_o <= bank & std_logic_vector(to_unsigned((pixel-1),10));
252 if run_single_i = '1' and run_single_last = '0' then
253 run_single_last <= '1';
255 if run_single_i = '1' and run_single_last = '1' then
257 run_single_last <= '0';
266 cntra <= (others => '0');
271 cntrb <= (others => '0');
278 if pixel > 0 and pixel < 1025 then
279 mem_o <= "00000000000000"&adc_data_i;
280 --mem_o <= std_logic_vector(to_unsigned((pixel-1),32));
281 addr_o <= bank & std_logic_vector(to_unsigned((pixel-1),10));
306 cntra <= (others => '0');
307 if run_single_i = '1' and run_single_last = '0' then
308 run_single_last <= '1';
310 if run_single_i = '1' and run_single_last = '1' then
312 run_single_last <= '0';
325 -- start the readout from adc
327 if run_readout = '1' then
338 cntrb <= (others => '0');
345 cntra <= (others => '0');
355 alive : process(clk_i,reset_i)
357 if reset_i = '1' then
361 elsif rising_edge(clk_i) then
362 alive_cntr<=alive_cntr+1;
363 if alive_cntr = 24999999 then
364 LED_latch <= not LED_latch;