1 | library ieee;
|
2 | use ieee.std_logic_1164.all;
|
3 | use ieee.numeric_std.all;
|
4 |
|
5 | entity adc_test is
|
6 | port
|
7 | (
|
8 | CLK_50 : in std_logic;
|
9 | BTN_RST : in std_logic;
|
10 | LED : out std_logic_vector(7 downto 0);
|
11 | SWITCH : in std_logic_vector(3 downto 0);
|
12 | ADC_CS : out std_logic;
|
13 | ADC_DAT_IN : out std_logic;
|
14 | ADC_DAT_OUT : in std_logic;
|
15 | ADC_CLK : out std_logic
|
16 | );
|
17 | end adc_test;
|
18 |
|
19 | architecture adc_test_arc of adc_test is
|
20 |
|
21 | component pll_clock IS
|
22 | PORT
|
23 | (
|
24 | inclk0 : IN STD_LOGIC := '0';
|
25 | c0 : OUT STD_LOGIC -- I used a 4MHz clock
|
26 | );
|
27 | END component;
|
28 |
|
29 | component adc_controller is
|
30 | port
|
31 | (
|
32 | clk : in std_logic;
|
33 | reset : in std_logic;
|
34 | output : out std_logic_vector(11 downto 0);
|
35 | output_valid : out std_logic;
|
36 | go : in std_logic;
|
37 | ch_sel : in std_logic_vector(2 downto 0);
|
38 | adc_clk : out std_logic;
|
39 | adc_cs_n : out std_logic;
|
40 | adc_sadr : out std_logic;
|
41 | adc_dat : in std_logic
|
42 | );
|
43 | end component;
|
44 |
|
45 | signal adc_controller_clk : std_logic := '0';
|
46 | signal adc_data : std_logic_vector(11 downto 0) := (others => '0');
|
47 | signal adc_data_valid : std_logic := '0';
|
48 | signal adc_go : std_logic := '0';
|
49 | signal rst_btn_sr : std_logic_vector(2 downto 0) := (others =>'0');
|
50 | signal adc_reset : std_logic := '0';
|
51 | signal rst_counter : natural := 0;
|
52 | signal reset_me : std_logic := '0';
|
53 |
|
54 | begin
|
55 |
|
56 | pll_clock_inst : pll_clock port map(
|
57 | inclk0 => CLK_50,
|
58 | c0 => adc_controller_clk
|
59 | );
|
60 |
|
61 | adc_controller_inst : adc_controller port map(
|
62 | clk => adc_controller_clk,
|
63 | reset => adc_reset,
|
64 | output => adc_data,
|
65 | output_valid => adc_data_valid,
|
66 | go => adc_go,
|
67 | ch_sel => SWITCH(2 downto 0),
|
68 | adc_clk => ADC_CLK,
|
69 | adc_cs_n => ADC_CS,
|
70 | adc_sadr => ADC_DAT_IN,
|
71 | adc_dat => ADC_DAT_OUT
|
72 | );
|
73 |
|
74 |
|
75 | -- RESET button process
|
76 | reset_btn_proc : process
|
77 | begin
|
78 | wait until rising_edge(CLK_50);
|
79 | rst_btn_sr <= rst_btn_sr(1 downto 0) & (NOT BTN_RST);
|
80 | if (rst_btn_sr = "111") then
|
81 | reset_me <= '1';
|
82 | else
|
83 | reset_me <= '0';
|
84 | end if;
|
85 | end process reset_btn_proc;
|
86 |
|
87 | --RESET process
|
88 | reset_proc :process
|
89 | begin
|
90 | wait until rising_edge(CLK_50);
|
91 | if (reset_me = '1') then
|
92 | rst_counter <= 100;
|
93 | end if;
|
94 | if (rst_counter > 0) then
|
95 | adc_reset <= '1';
|
96 | adc_go <= '0';
|
97 | rst_counter <= rst_counter - 1;
|
98 | else
|
99 | adc_reset <= '0';
|
100 | adc_go <= '1';
|
101 | end if;
|
102 | end process reset_proc;
|
103 |
|
104 | -- LED process
|
105 | led_proc : process
|
106 | begin
|
107 | wait until rising_edge(CLK_50);
|
108 | if (adc_reset = '1') then
|
109 | LED <= (others => '0');
|
110 | else
|
111 | if (adc_data_valid = '1') then
|
112 | LED <= adc_data(7 downto 0);
|
113 | end if;
|
114 | end if;
|
115 | end process led_proc;
|
116 |
|
117 | end adc_test_arc;
|