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_o : out std_logic;
26 index_event_o : out std_logic;
27 index_event2_o : out std_logic;
28 a_rise_o, a_fall_o : out std_logic;
29 b_rise_o, b_fall_o : out std_logic;
30 ab_event_o : out std_logic;
31 ab_error_o : out std_logic
35 architecture behavioral of qcounter is
37 signal last_reset_s : std_logic;
38 signal a_s, b_s : std_logic;
39 signal a_prev_s, b_prev_s : std_logic;
40 signal ab_error_s : std_logic;
41 signal ab_error_int_s : std_logic;
42 signal index_event_int_s : std_logic;
43 signal index_event2_int_s : std_logic;
44 signal index_s : std_logic;
45 signal index_prev_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_out_s : std_logic_vector (7 downto 0);
49 signal count_index_s : std_logic_vector (7 downto 0);
76 count_out_s(0) <= a_s xor b_s;
77 count_out_s(1) <= b_s;
78 count_out_s(7 downto 2) <= count_s;
80 qcount_o <= count_out_s;
81 qcount_index_o <= count_index_s;
83 ab_error_o <= ab_error_int_s;
85 index_event_o <= index_event_int_s;
86 index_event2_o <= index_event2_int_s;
89 process (reset_i, last_reset_s, a_prev_s, b_prev_s, a_s, b_s)
98 if reset_i = '0' and last_reset_s = '0' then
99 if ((a_s xor a_prev_s) and (b_s xor b_prev_s)) = '1' then
100 -- forbidden double transition
104 a_rise_o <= (a_s xor a_prev_s) and a_s;
105 a_fall_o <= (a_s xor a_prev_s) and (not a_s);
106 b_rise_o <= (b_s xor b_prev_s) and b_s;
107 b_fall_o <= (b_s xor b_prev_s) and (not b_s);
108 ab_event_o <= (a_s xor a_prev_s) or (b_s xor b_prev_s);
114 process (reset_i, last_reset_s, a_prev_s, b_prev_s, a_s, b_s,
115 index_s, count_prev_s)
118 if reset_i = '1' or last_reset_s = '1' then
119 count_s <= count_prev_s;
120 elsif (a_prev_s = '0') and (b_prev_s = '1') and (a_s = '0') and
122 count_s <= count_prev_s + 1;
123 elsif (a_prev_s = '0') and (b_prev_s = '0') and (a_s = '0') and
125 count_s <= count_prev_s - 1;
127 count_s <= count_prev_s;
134 variable index_event_v : std_logic;
136 -- Reset for qcounter is synchronous and lasts at least one more cycle
137 -- to prevent hazardous states after releasing it
138 wait until clk_i'event and clk_i = '1';
140 index_event_v := '0';
142 if reset_i = '1' then
143 count_prev_s <= (others => '0');
144 count_index_s <= (others => '0');
145 index_event_int_s <= '0';
146 index_event2_int_s <= '0';
147 ab_error_int_s <= '0';
151 if index_s = '1' and index_prev_s = '0' then
152 count_index_s <= count_out_s;
153 index_event_v := '1';
156 if reset_index_event_i = '1' then
157 index_event_int_s <= '0';
159 index_event_int_s <= index_event_int_s or index_event_v;
162 if reset_index_event2_i = '1' then
163 index_event2_int_s <= '0';
165 index_event2_int_s <= index_event2_int_s or index_event_v;
168 if reset_ab_error_i = '1' then
169 ab_error_int_s <= '0';
171 ab_error_int_s <= ab_error_int_s or ab_error_s;
174 count_prev_s <= count_s;
175 index_prev_s <= index_s;
181 last_reset_s <= reset_i;