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 constant pixel_max: integer := 2047;
49 signal cntra : unsigned(31 downto 0) := (others => '0');
50 signal pixel : integer range 0 to pixel_max;
51 signal spd_cntr : integer range 0 to 3;
52 signal spd_timer : integer range 0 to 255;
54 signal cntrb : unsigned(31 downto 0) := (others => '0');
56 signal bank : std_logic;
58 signal run_readout : std_logic;
59 signal conv_start : std_logic;
60 signal adc_data_i : std_logic_vector(17 downto 0);
61 signal adc_drdy_i : std_logic;
62 signal run_single : std_logic;
63 signal run_single_last : std_logic;
64 signal run_single_i : std_logic;
65 signal finished : std_logic:='0';
66 signal finished_i : std_logic:='0';
67 signal stability_m : std_logic;
69 type states_i is (i0, i1, i2, i3, i4, i5, i6, i7, i8, iddle);
70 signal state_i : states_i;
72 type meas_states is (normal, multi_per_pixel, leakage);
73 signal state_meas : meas_states;
75 signal t1 : unsigned(31 downto 0);
76 signal t2 : unsigned(31 downto 0);
77 signal t3 : unsigned(31 downto 0);
78 signal t4 : unsigned(31 downto 0);
79 signal t5 : unsigned(31 downto 0);
80 signal t6 : unsigned(31 downto 0);
81 signal t7 : unsigned(31 downto 0);
82 signal t8 : unsigned(31 downto 0);
83 signal t9 : unsigned(31 downto 0) ;
84 signal pixel_last : integer range 0 to pixel_max;
85 signal pixel_cnt : integer range 0 to pixel_max;
86 signal pixel_addr : integer range 0 to pixel_max;
88 signal store_samples_s : std_logic;
89 signal sync_multi_s : std_logic;
91 signal alive_cntr : integer range 0 to 24999999:=0;
92 signal LED_latch : std_logic:='1';
96 snsor_adc_interface:lx_adc_if
106 conv_start => conv_start,
109 data_o => adc_data_i,
110 drdy_o => adc_drdy_i,
115 -- adc_read : process(reset_i,clk_i)
117 -- if reset_i = '1' then
118 -- elsif rising_edge(clk_i) then
119 -- if adc_drdy_i = '1' and pixel < 1025 then
120 --mem_o <= std_logic_vector(resize(unsigned(adc_data_i), mem_o'length));
121 -- mem_o <= std_logic_vector(to_unsigned((pixel),32));
122 -- addr_o <= bank & std_logic_vector(to_unsigned((pixel),10));
129 interf : process(reset_i,clk_i)
131 if reset_i = '1' then -- set default timing
132 t1 <= "00000000000000000000000000000110"; --6
133 t2 <= "00000000000000000000001111101000"; --9
134 t3 <= "00000000000000000000010001111101"; --1149
135 t4 <= "00000000000000000000001111101000"; --14
136 t5 <= "00000000000000000000000000000110"; --6
137 t6 <= "00000000000000000000001001010111"; --599
138 t7 <= "00000000000000000000001010010010"; --658
139 t8 <= "00000000000000000001001100010000"; --4880
140 t9 <= "00000000000000000000000111110011";
142 data_o <= (others => '0');
145 elsif rising_edge(clk_i) then
147 if finished = '1' then
151 if ce_i = '1' and bls_i /= "0000" then
152 if addr_i = "0000" then
153 run_readout <= data_i(0); --start/stop the readout
154 if data_i(1) = '1' then
158 if data_i(3) = '1' then
159 state_meas <= normal;
160 elsif data_i(4) = '1' then
161 state_meas <= leakage;
162 elsif data_i(5) = '1' then
163 state_meas <= multi_per_pixel;
165 elsif addr_i = "0001" then
166 t1 <= unsigned(data_i);
167 elsif addr_i = "0010" then
168 t2 <= unsigned(data_i);
169 elsif addr_i = "0011" then
170 t3 <= unsigned(data_i);
171 elsif addr_i = "0100" then
172 t4 <= unsigned(data_i);
173 elsif addr_i = "0101" then
174 t5 <= unsigned(data_i);
175 elsif addr_i = "0110" then
176 t6 <= unsigned(data_i);
177 elsif addr_i <= "0111" then
178 t7 <= unsigned(data_i);
179 elsif addr_i <= "1000" then
180 t8 <= unsigned(data_i);
181 elsif addr_i <= "1001" then
182 t9 <= unsigned(data_i);
183 elsif addr_i <= "1100" then
184 pixel_last <= to_integer(unsigned(data_i));
188 if addr_i = "0000" then
189 data_o <= (others => '0');
190 data_o(2) <= not bank;
191 data_o(6) <= finished_i;
192 data_o(0) <= run_readout;
193 if state_meas = leakage then
195 elsif state_meas = normal then
197 elsif state_meas = multi_per_pixel then
201 elsif addr_i = "0001" then
202 data_o <= std_logic_vector(t1);
203 elsif addr_i = "0010" then
204 data_o <= std_logic_vector(t2);
205 elsif addr_i = "0011" then
206 data_o <= std_logic_vector(t3);
207 elsif addr_i = "0100" then
208 data_o <= std_logic_vector(t4);
209 elsif addr_i = "0101" then
210 data_o <= std_logic_vector(t5);
211 elsif addr_i = "0110" then
212 data_o <= std_logic_vector(t6);
213 elsif addr_i = "0111" then
214 data_o <= std_logic_vector(t7);
215 elsif addr_i = "1000" then
216 data_o <= std_logic_vector(t8);
217 elsif addr_i = "1001" then
218 data_o <= std_logic_vector(t9);
219 elsif addr_i = "1100" then
220 data_o <= std_logic_vector(to_unsigned(pixel_last, 32));
222 data_o <= "00000000000000000000000000000000";
229 proc : process(clk_i, reset_i)
233 cntra <= (others => '0');
243 store_samples_s <= '0';
245 elsif rising_edge(clk_i) then
251 if run_single = '1' then
254 if run_readout = '1' then
257 cntrb <= (others => '0');
260 if (state_meas = multi_per_pixel) and (store_samples_s = '1') then
261 if sync_multi_s = '1' then
262 spd_timer <= 125 - 1;
264 if spd_timer > 0 then
265 spd_timer <= spd_timer - 1;
267 spd_timer <= 125 - 1;
273 if adc_drdy_i = '1' and store_samples_s = '1' then
274 mem_o <= "00000000000000" & adc_data_i;
275 addr_o <= bank & std_logic_vector(to_unsigned((pixel_addr),addr_o'length -1));
278 if pixel_addr /= (2 ** (addr_o'length - 1)) - 1 then
279 pixel_addr <= pixel_addr + 1;
281 store_samples_s <= '0';
293 if run_single_i = '1' and run_single_last = '0' then
294 run_single_last <= '1';
296 if run_single_i = '1' and run_single_last = '1' then
298 run_single_last <= '0';
302 store_samples_s <= '1';
309 cntra <= (others => '0');
314 cntrb <= (others => '0');
318 when normal | multi_per_pixel =>
339 if pixel_cnt = 0 then
342 cntra <= (others => '0');
343 if run_single_i = '1' and run_single_last = '0' then
344 run_single_last <= '1';
346 if run_single_i = '1' and run_single_last = '1' then
348 run_single_last <= '0';
352 pixel_cnt <= pixel_cnt - 1;
362 -- start the readout from adc
364 if run_readout = '1' then
366 if state_meas = normal then
374 store_samples_s <= '1';
381 cntrb <= (others => '0');
388 cntra <= (others => '0');
389 pixel_cnt <= pixel_last;
400 alive : process(clk_i,reset_i)
402 if reset_i = '1' then
406 elsif rising_edge(clk_i) then
407 alive_cntr<=alive_cntr+1;
408 if alive_cntr = 24999999 then
409 LED_latch <= not LED_latch;