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
19 subtype std_logic4 is std_logic_vector (3 downto 0);
20 signal a_prev, b_prev: std_logic;
21 signal count: std_logic_vector (29 downto 0)
22 := "000000000000000000000000000000";
23 signal count_next: std_logic_vector (29 downto 0);
25 qcount(0) <= a_prev xor b_prev;
27 qcount(31 downto 2) <= count;
29 comb_event: process (a_prev, b_prev, a, b)
37 if ((a xor a_prev) and (b xor b_prev)) = '1' then
38 -- forbidden double transition
41 a_rise <= (a xor a_prev) and a;
42 a_fall <= (a xor a_prev) and not a;
43 b_rise <= (b xor b_prev) and b;
44 b_fall <= (b xor b_prev) and not b;
45 ab_event <= (a xor a_prev) or (b xor b_prev);
49 comb_count: process (a_prev, b_prev, a, b, count)
51 if (a_prev = '1') and (b_prev = '0') and (a = '0') and (b = '0') then
52 count_next <= count + 1;
53 elsif (a_prev = '0') and (b_prev = '0') and (a = '1') and (b = '0') then
54 count_next <= count - 1;
62 wait until clock'event and clock = '1';
64 count <= "000000000000000000000000000000";