-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADC.vhd
133 lines (118 loc) · 4.81 KB
/
ADC.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity top_level_ADC is
port(
clk : in std_logic;
output, output2, output3 : out std_logic_vector(3 downto 0));
end entity;
architecture structural of top_level_ADC is
component hello_adc is
port (
-- adc_control_core_command.valid
adc_control_core_command_valid : in std_logic;
-- .channel
adc_control_core_command_channel : in std_logic_vector(4 downto 0) := (others => '0');
-- .startofpacket
adc_control_core_command_startofpacket : in std_logic := '0';
-- .endofpacket
adc_control_core_command_endofpacket : in std_logic := '0';
-- .ready
adc_control_core_command_ready : out std_logic;
-- adc_control_core_response.valid
adc_control_core_response_valid : out std_logic;
-- .channel
adc_control_core_response_channel : out std_logic_vector(4 downto 0);
-- .data
adc_control_core_response_data : out std_logic_vector(11 downto 0);
-- .startofpacket
adc_control_core_response_startofpacket : out std_logic;
-- .endofpacket
adc_control_core_response_endofpacket : out std_logic;
-- clk.clk
clk_clk : in std_logic := '0';
-- clock_bridge_out_clk.clk
clock_bridge_out_clk_clk : out std_logic;
-- reset.reset_n
reset_reset_n : in std_logic := '0'
);
end component hello_adc;
component adc_sample_to_BCD is
port (
adc_sample : in std_logic_vector(11 downto 0);
vol : out std_logic_vector(12 downto 0);
ones : out std_logic_vector(3 downto 0);
tenths : out std_logic_vector(3 downto 0);
hundredths : out std_logic_vector(3 downto 0);
thousandths : out std_logic_vector(3 downto 0)
);
end component;
signal req_channel, cur_channel : std_logic_vector(4 downto 0);
signal sample_data : std_logic_vector(11 downto 0);
signal adc_cc_command_ready : std_logic;
signal adc_cc_response_valid : std_logic;
signal adc_cc_response_channel : std_logic_vector(4 downto 0);
signal adc_cc_response_data : std_logic_vector(11 downto 0);
-- BCD signals
signal ones : std_logic_vector(3 downto 0);
signal tenths : std_logic_vector(3 downto 0);
signal hundredths : std_logic_vector(3 downto 0);
signal thousandths : std_logic_vector(3 downto 0);
signal sys_clk, nreset, reset : std_logic;
begin
reset <= '0';
nreset <= not reset;
adc_command : process(sys_clk, adc_cc_command_ready)
variable temp : std_logic_vector(4 downto 0) := (others => '0');
begin
if rising_edge(sys_clk) then
if (adc_cc_command_ready = '1') then
temp(2 downto 0) := "001";
end if;
end if;
req_channel <= temp;
end process;
adc_read : process(sys_clk, adc_cc_response_valid)
variable reading : std_logic_vector(11 downto 0) := (others => '0');
variable ch : std_logic_vector(4 downto 0) := (others => '0');
begin
if rising_edge(sys_clk) then
if (adc_cc_response_valid = '1') then
reading := adc_cc_response_data;
ch := adc_cc_response_channel;
end if;
end if;
cur_channel <= ch;
sample_data <= reading;
end process;
adc_sample_to_BCD_conv : adc_sample_to_BCD
port map (
adc_sample => sample_data,
vol => open,
ones => ones,
tenths => tenths,
hundredths => hundredths,
thousandths => thousandths
);
qsys_u0 : component hello_adc
port map (
-- command always valid
adc_control_core_command_valid => '1',
adc_control_core_command_channel => req_channel,
-- startofpacket and endofpacket are ignored in adc_control_core
adc_control_core_command_startofpacket => '1',
adc_control_core_command_endofpacket => '1',
adc_control_core_command_ready => adc_cc_command_ready,
adc_control_core_response_valid => adc_cc_response_valid,
adc_control_core_response_channel => adc_cc_response_channel,
adc_control_core_response_data => adc_cc_response_data,
adc_control_core_response_startofpacket => open,
adc_control_core_response_endofpacket => open,
clk_clk => clk,
clock_bridge_out_clk_clk => sys_clk,
reset_reset_n => nreset
);
output <= ones;
output2 <= tenths;
output3 <= hundredths;
end architecture structural;