2 use ieee.std_logic_1164.all;
\r
3 use ieee.numeric_std.all;
\r
4 use work.util_pkg.all;
\r
5 use work.lx_dad_pkg.all;
\r
10 adc_res : positive := 18;
\r
11 conv_cycles : integer := 85
\r
15 clk_i : in std_logic;
\r
16 rst_i : in std_logic;
\r
17 conv_start : in std_logic;
\r
19 sck_o : out std_logic;
\r
20 cnv_o : out std_logic;
\r
21 data_o : out std_logic_vector((adc_res-1) downto 0);
\r
22 drdy_o : out std_logic;
\r
24 sck_i : in std_logic;
\r
29 architecture rtl of lx_adc_if is
\r
30 signal received : std_logic_vector((adc_res-1) downto 0);
\r
31 signal ckout : std_logic;
\r
32 --signal active_bit_t integer range 0 to (adc_res-1);
\r
33 signal active_bit_r : integer range 0 to (adc_res-1);
\r
35 signal conv_cnter : integer range 0 to conv_cycles;
\r
37 type states_i is (conv, reading, iddle);
\r
38 signal state_i : states_i;
\r
39 signal convert : std_logic;
\r
41 signal drdy_i : std_logic;
\r
42 signal drdy_i_last : std_logic;
\r
43 signal drdy_i_last_last : std_logic;
\r
45 attribute REGISTER_DUPLICATION : string;
\r
46 attribute REGISTER_DUPLICATION of received : signal is "NO";
\r
47 attribute REGISTER_DUPLICATION of drdy_i : signal is "NO";
\r
48 attribute REGISTER_DUPLICATION of drdy_i_last : signal is "NO";
\r
49 attribute REGISTER_DUPLICATION of drdy_i_last_last : signal is "NO";
\r
53 data_sync: process(clk_i,rst_i)
\r
58 drdy_i_last_last <= '0';
\r
59 data_o <= (others => '0');
\r
60 elsif rising_edge(clk_i) then
\r
61 drdy_i_last_last <= drdy_i_last;
\r
62 drdy_i_last <= drdy_i;
\r
64 if drdy_i = '1' and drdy_i_last = '1' and drdy_i_last_last = '0' then
\r
71 adc_readout: process(sck_i,rst_i)
\r
76 received <= (others => '0');
\r
77 elsif rising_edge(sck_i) then
\r
78 if convert = '1' and active_bit_r = 17 then
\r
79 received(active_bit_r) <= SDI;
\r
82 elsif active_bit_r /= 17 then
\r
83 if active_bit_r = 0 then
\r
87 active_bit_r <= active_bit_r - 1;
\r
89 received(active_bit_r) <= SDI;
\r
95 adc_control: process(clk_i, rst_i)
\r
100 elsif rising_edge(clk_i) then
\r
103 if conv_start = '1' then
\r
109 if conv_cnter = (conv_cycles - 1) then
\r
111 state_i <= reading;
\r
113 conv_cnter <= conv_cnter + 1;
\r
116 if conv_cnter < (adc_res) then
\r
117 if ckout = '1' then
\r
118 conv_cnter <= conv_cnter + 1;
\r
120 ckout <= not ckout;
\r