2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 use ieee.std_logic_unsigned.all;
5 use ieee.numeric_std.all;
6 use work.lx_rocon_pkg.all;
8 -- Quadcounter (for IRC)
15 reset_i : in std_logic;
16 a0_i, b0_i : in std_logic;
17 index0_i : in std_logic;
19 reset_index_event_i : in std_logic;
20 reset_index_event2_i : in std_logic;
21 reset_ab_error_i : in std_logic;
23 qcount_o : out std_logic_vector (7 downto 0);
24 qcount_index_o : out std_logic_vector (7 downto 0);
25 index_event_o : out std_logic;
26 index_event2_o : out std_logic;
27 a_rise_o, a_fall_o : out std_logic;
28 b_rise_o, b_fall_o : out std_logic;
29 ab_event_o : out std_logic;
30 ab_error_o : out std_logic
34 architecture behavioral of qcounter is
36 signal last_reset_s : std_logic;
37 signal a_s, b_s : std_logic;
38 signal a_prev_s, b_prev_s : std_logic;
39 signal ab_error_s : std_logic;
40 signal ab_error_int_s : std_logic;
41 signal index_event_s : std_logic;
42 signal index_event_int_s : std_logic;
43 signal index_event2_s : std_logic;
44 signal index_event2_int_s : std_logic;
45 signal index_s : std_logic;
46 signal count_prev_s : std_logic_vector (5 downto 0);
47 signal count_s : std_logic_vector (5 downto 0);
48 signal count_index_prev_s : std_logic_vector (7 downto 0);
49 signal count_index_s : std_logic_vector (7 downto 0);
79 qcount_o(0) <= a_s xor b_s;
81 qcount_o(7 downto 2) <= count_s;
83 qcount_index_o <= count_index_s;
85 ab_error_o <= ab_error_int_s;
86 index_event_o <= index_event_int_s;
87 index_event2_o <= index_event2_int_s;
90 process (reset_i, last_reset_s, a_prev_s, b_prev_s, a_s, b_s)
99 if reset_i = '0' and last_reset_s = '0' then
100 if ((a_s xor a_prev_s) and (b_s xor b_prev_s)) = '1' then
101 -- forbidden double transition
105 a_rise_o <= (a_s xor a_prev_s) and a_s;
106 a_fall_o <= (a_s xor a_prev_s) and (not a_s);
107 b_rise_o <= (b_s xor b_prev_s) and b_s;
108 b_fall_o <= (b_s xor b_prev_s) and (not b_s);
109 ab_event_o <= (a_s xor a_prev_s) or (b_s xor b_prev_s);
115 process (reset_i, last_reset_s, a_prev_s, b_prev_s, a_s, b_s,
116 index_s, count_prev_s, count_index_prev_s)
119 index_event_s <= '0';
121 if reset_i = '1' or last_reset_s = '1' then
122 count_s <= count_prev_s;
123 count_index_s <= count_index_prev_s;
124 elsif (a_prev_s = '0') and (b_prev_s = '1') and (a_s = '0') and
126 count_s <= count_prev_s + 1;
127 if index_s = '1' then
128 count_index_s(0) <= a_s xor b_s;
129 count_index_s(1) <= b_s;
130 count_index_s(7 downto 2) <= count_prev_s + 1;
132 count_index_s <= count_index_prev_s;
134 elsif (a_prev_s = '0') and (b_prev_s = '0') and (a_s = '0') and
136 count_s <= count_prev_s - 1;
138 if index_s = '1' then
139 count_index_s(0) <= a_s xor b_s;
140 count_index_s(1) <= b_s;
141 count_index_s(7 downto 2) <= count_prev_s - 1;
142 index_event_s <= '1';
144 count_index_s <= count_index_prev_s;
147 count_s <= count_prev_s;
148 if index_s = '1' then
149 count_index_s(0) <= a_s xor b_s;
150 count_index_s(1) <= b_s;
151 count_index_s(7 downto 2) <= count_prev_s;
152 index_event_s <= '1';
154 count_index_s <= count_index_prev_s;
163 -- Reset for qcounter is synchronous and lasts at least one more cycle
164 -- to prevent hazardous states after releasing it
165 wait until clk_i'event and clk_i = '1';
167 if reset_i = '1' then
168 count_prev_s <= (others => '0');
169 count_index_prev_s <= (others => '0');
170 index_event_int_s <= '0';
171 index_event2_int_s <= '0';
172 ab_error_int_s <= '0';
174 count_prev_s <= count_s;
175 count_index_prev_s <= count_index_s;
177 if reset_index_event_i = '1' then
178 index_event_int_s <= '0';
180 index_event_int_s <= index_event_int_s or index_event_s;
183 if reset_index_event2_i = '1' then
184 index_event2_int_s <= '0';
186 index_event2_int_s <= index_event2_int_s or index_event_s;
189 if reset_ab_error_i = '1' then
190 ab_error_int_s <= '0';
192 ab_error_int_s <= ab_error_int_s or ab_error_s;
197 last_reset_s <= reset_i;