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;
13 qcount: out std_logic_vector (31 downto 0);
14 a_rise, a_fall, b_rise, b_fall, ab_event: out std_logic;
15 ab_error: out std_logic
19 architecture behavioral of qcounter is
28 subtype std_logic4 is std_logic_vector (3 downto 0);
29 signal a, b, a_prev, b_prev: std_logic;
30 signal count_prev: std_logic_vector (29 downto 0)
31 := "000000000000000000000000000000";
32 signal count: std_logic_vector (29 downto 0);
49 qcount(31 downto 2) <= count;
51 comb_event: process (a_prev, b_prev, a, b)
59 if ((a xor a_prev) and (b xor b_prev)) = '1' then
60 -- forbidden double transition
63 a_rise <= (a xor a_prev) and a;
64 a_fall <= (a xor a_prev) and not a;
65 b_rise <= (b xor b_prev) and b;
66 b_fall <= (b xor b_prev) and not b;
67 ab_event <= (a xor a_prev) or (b xor b_prev);
71 comb_count: process (a_prev, b_prev, a, b, count)
73 if (a_prev = '0') and (b_prev = '1') and (a = '0') and (b = '0') then
74 count <= count_prev + 1;
75 elsif (a_prev = '0') and (b_prev = '0') and (a = '0') and (b = '1') then
76 count <= count_prev - 1;
84 wait until clock'event and clock = '1';
86 count_prev <= "000000000000000000000000000000";