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 8191;
49 signal spd_cntr : integer range 0 to 3;
51 signal cntrb : unsigned(31 downto 0) := (others => '0');
53 signal bank : std_logic;
55 signal run_readout : std_logic;
56 signal conv_start : std_logic;
57 signal adc_data_i : std_logic_vector(17 downto 0);
58 signal adc_drdy_i : std_logic;
59 signal run_single : std_logic;
60 signal run_single_last : std_logic;
61 signal run_single_i : std_logic;
62 signal finished : std_logic:='0';
63 signal finished_i : std_logic:='0';
64 signal stability_m : std_logic;
66 type states_i is (i0, i1, i2, i3, i4, i5, i6, i7, i8, iddle, ispd, ispdb);
67 signal state_i : states_i;
69 type meas_states is (normal, multi_per_pixel, leakage);
70 signal state_meas : meas_states;
72 signal t1 : unsigned(31 downto 0);
73 signal t2 : unsigned(31 downto 0);
74 signal t3 : unsigned(31 downto 0);
75 signal t4 : unsigned(31 downto 0);
76 signal t5 : unsigned(31 downto 0);
77 signal t6 : unsigned(31 downto 0);
78 signal t7 : unsigned(31 downto 0);
79 signal t8 : unsigned(31 downto 0);
80 signal t9 : unsigned(31 downto 0) ;
83 signal alive_cntr : integer range 0 to 24999999:=0;
84 signal LED_latch : std_logic:='1';
88 snsor_adc_interface:lx_adc_if
98 conv_start => conv_start,
101 data_o => adc_data_i,
102 drdy_o => adc_drdy_i,
107 -- adc_read : process(reset_i,clk_i)
109 -- if reset_i = '1' then
110 -- elsif rising_edge(clk_i) then
111 -- if adc_drdy_i = '1' and pixel < 1025 then
112 --mem_o <= std_logic_vector(resize(unsigned(adc_data_i), mem_o'length));
113 -- mem_o <= std_logic_vector(to_unsigned((pixel),32));
114 -- addr_o <= bank & std_logic_vector(to_unsigned((pixel),10));
121 interf : process(reset_i,clk_i)
123 if reset_i = '1' then -- set default timing
124 t1 <= "00000000000000000000000000000110"; --6
125 t2 <= "00000000000000000000001111101000"; --9
126 t3 <= "00000000000000000000010001111101"; --1149
127 t4 <= "00000000000000000000001111101000"; --14
128 t5 <= "00000000000000000000000000000110"; --6
129 t6 <= "00000000000000000000001001010111"; --599
130 t7 <= "00000000000000000000001010010010"; --658
131 t8 <= "00000000000000000001001100010000"; --4880
132 t9 <= "00000000000000000000000111110011";
133 data_o <= (others => '0');
136 elsif rising_edge(clk_i) then
138 if finished = '1' then
142 if ce_i = '1' and bls_i /= "0000" then
143 if addr_i = "0000" then
144 run_readout <= data_i(0); --start/stop the readout
145 if data_i(1) = '1' then
149 if data_i(3) = '1' then
150 state_meas <= normal;
151 elsif data_i(4) = '1' then
152 state_meas <= leakage;
154 elsif addr_i = "0001" then
155 t1 <= unsigned(data_i);
156 elsif addr_i = "0010" then
157 t2 <= unsigned(data_i);
158 elsif addr_i = "0011" then
159 t3 <= unsigned(data_i);
160 elsif addr_i = "0100" then
161 t4 <= unsigned(data_i);
162 elsif addr_i = "0101" then
163 t5 <= unsigned(data_i);
164 elsif addr_i = "0110" then
165 t6 <= unsigned(data_i);
166 elsif addr_i <= "0111" then
167 t7 <= unsigned(data_i);
168 elsif addr_i <= "1000" then
169 t8 <= unsigned(data_i);
170 elsif addr_i <= "1001" then
171 t9 <= unsigned(data_i);
175 if addr_i = "0000" then
176 data_o <= (others => '0');
177 data_o(2) <= not bank;
178 data_o(6) <= finished_i;
179 data_o(0) <= run_readout;
180 if state_meas = leakage then
182 elsif state_meas = normal then
184 elsif state_meas = multi_per_pixel then
188 elsif addr_i = "0001" then
189 data_o <= std_logic_vector(t1);
190 elsif addr_i = "0010" then
191 data_o <= std_logic_vector(t2);
192 elsif addr_i = "0011" then
193 data_o <= std_logic_vector(t3);
194 elsif addr_i = "0100" then
195 data_o <= std_logic_vector(t4);
196 elsif addr_i = "0101" then
197 data_o <= std_logic_vector(t5);
198 elsif addr_i = "0110" then
199 data_o <= std_logic_vector(t6);
200 elsif addr_i = "0111" then
201 data_o <= std_logic_vector(t7);
202 elsif addr_i = "1000" then
203 data_o <= std_logic_vector(t8);
204 elsif addr_i = "1001" then
205 data_o <= std_logic_vector(t9);
212 proc : process(clk_i, reset_i)
216 cntra <= (others => '0');
223 elsif rising_edge(clk_i) then
228 if run_single = '1' then
231 if run_readout = '1' then
234 cntrb <= (others => '0');
236 -- if start_readout = '1' then
245 mem_o <= "00000000000000"&adc_data_i;
246 --mem_o <= std_logic_vector(to_unsigned((pixel-1),32));
247 addr_o <= bank & std_logic_vector(to_unsigned((pixel-1),10));
254 if run_single_i = '1' and run_single_last = '0' then
255 run_single_last <= '1';
257 if run_single_i = '1' and run_single_last = '1' then
259 run_single_last <= '0';
268 cntra <= (others => '0');
273 cntrb <= (others => '0');
277 when normal | multi_per_pixel =>
280 if state_meas = normal then
281 if pixel > 0 and pixel < 1025 then
282 mem_o <= "00000000000000"&adc_data_i;
283 --mem_o <= std_logic_vector(to_unsigned((pixel-1),32));
284 addr_o <= bank & std_logic_vector(to_unsigned((pixel-1),10));
307 if state_meas = normal then
311 cntra <= (others => '0');
312 if run_single_i = '1' and run_single_last = '0' then
313 run_single_last <= '1';
315 if run_single_i = '1' and run_single_last = '1' then
317 run_single_last <= '0';
328 cntra <= (others => '0');
329 if run_readout = '1' and run_single_last = '0' then
330 run_single_last <= '1';
332 if run_readout = '1' and run_single_last = '1' then
334 run_single_last <= '0';
344 if state_meas = normal then
352 cntra <= t9 - to_unsigned(75,cntra'length);
357 cntra <= to_unsigned(74,cntra'length);
358 mem_o <= "00000000000000"&adc_data_i;
359 addr_o <= std_logic_vector(to_unsigned((pixel-1),11));
368 spd_cntr <= spd_cntr - 1;
373 -- start the readout from adc
375 if run_readout = '1' then
386 cntrb <= (others => '0');
393 cntra <= (others => '0');
403 alive : process(clk_i,reset_i)
405 if reset_i = '1' then
409 elsif rising_edge(clk_i) then
410 alive_cntr<=alive_cntr+1;
411 if alive_cntr = 24999999 then
412 LED_latch <= not LED_latch;