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;
7 -- Quadcounter (for IRC)
14 a0, b0 : in std_logic;
16 qcount : out std_logic_vector (31 downto 0);
17 a_rise, a_fall, b_rise, b_fall, ab_event: out std_logic;
18 ab_error : out std_logic
22 architecture behavioral of qcounter is
33 subtype std_logic4 is std_logic_vector (3 downto 0);
34 signal last_reset: std_logic;
35 signal a, b, a_prev, b_prev: std_logic;
36 signal count_prev: std_logic_vector (29 downto 0);
37 signal count: std_logic_vector (29 downto 0);
59 qcount(31 downto 2) <= count;
61 comb_event: process (reset, last_reset, a_prev, b_prev, a, b)
70 if reset = '0' and last_reset = '0' then
71 if ((a xor a_prev) and (b xor b_prev)) = '1' then
72 -- forbidden double transition
75 a_rise <= (a xor a_prev) and a;
76 a_fall <= (a xor a_prev) and not a;
77 b_rise <= (b xor b_prev) and b;
78 b_fall <= (b xor b_prev) and not b;
79 ab_event <= (a xor a_prev) or (b xor b_prev);
84 comb_count: process (reset, last_reset, a_prev, b_prev, a, b, count_prev)
86 if reset = '1' or last_reset = '1' then
88 elsif (a_prev = '0') and (b_prev = '1') and (a = '0') and (b = '0') then
89 count <= count_prev + 1;
90 elsif (a_prev = '0') and (b_prev = '0') and (a = '0') and (b = '1') then
91 count <= count_prev - 1;
99 -- Reset for qcounter is synchronous and lasts at least one more cycle
100 -- to prevent hazardous states after releasing it
101 if clk = '1' and clk'event then
105 count_prev <= (others => '0');