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;
12 qcount: out std_logic_vector (31 downto 0);
13 a_rise, a_fall, b_rise, b_fall, ab_event: out std_logic;
14 ab_error: out std_logic
18 architecture behavioral of qcounter is
27 subtype std_logic4 is std_logic_vector (3 downto 0);
28 signal a, b, a_prev, b_prev: std_logic;
29 signal count_prev: std_logic_vector (29 downto 0)
30 := "000000000000000000000000000000";
31 signal count: std_logic_vector (29 downto 0);
48 qcount(31 downto 2) <= count;
50 comb_event: process (a_prev, b_prev, a, b)
58 if ((a xor a_prev) and (b xor b_prev)) = '1' then
59 -- forbidden double transition
62 a_rise <= (a xor a_prev) and a;
63 a_fall <= (a xor a_prev) and not a;
64 b_rise <= (b xor b_prev) and b;
65 b_fall <= (b xor b_prev) and not b;
66 ab_event <= (a xor a_prev) or (b xor b_prev);
70 comb_count: process (a_prev, b_prev, a, b, count)
72 if (a_prev = '0') and (b_prev = '1') and (a = '0') and (b = '0') then
73 count <= count_prev + 1;
74 elsif (a_prev = '0') and (b_prev = '0') and (a = '0') and (b = '1') then
75 count <= count_prev - 1;
83 wait until clock'event and clock = '1';
85 count_prev <= "000000000000000000000000000000";