entity qcounter is
port
(
- clk : in std_logic;
- reset : in std_logic;
- a0, b0 : in std_logic;
- index0 : in std_logic;
-
- qcount : out std_logic_vector (31 downto 0);
- qcount_index : out std_logic_vector (31 downto 0);
- a_rise, a_fall, b_rise, b_fall, ab_event: out std_logic;
- ab_error : out std_logic
+ -- Inputs
+ clk_i : in std_logic;
+ reset_i : in std_logic;
+ a0_i, b0_i : in std_logic;
+ index0_i : in std_logic;
+ -- Outputs
+ qcount_o : out std_logic_vector (31 downto 0);
+ qcount_index_o : out std_logic_vector (31 downto 0);
+ a_rise_o, a_fall_o : out std_logic;
+ b_rise_o, b_fall_o : out std_logic;
+ ab_event_o : out std_logic;
+ ab_error_o : out std_logic
);
end qcounter;
architecture behavioral of qcounter is
- signal last_reset: std_logic;
- signal a, b, a_prev, b_prev: std_logic;
- signal index: std_logic;
- signal count_prev: std_logic_vector (29 downto 0);
- signal count: std_logic_vector (29 downto 0);
- signal count_index_prev: std_logic_vector (31 downto 0);
- signal count_index: std_logic_vector (31 downto 0);
+ signal last_reset_s : std_logic;
+ signal a_s, b_s : std_logic;
+ signal a_prev_s, b_prev_s : std_logic;
+ signal index_s : std_logic;
+ signal count_prev_s : std_logic_vector (29 downto 0);
+ signal count_s : std_logic_vector (29 downto 0);
+ signal count_index_prev_s : std_logic_vector (31 downto 0);
+ signal count_index_s : std_logic_vector (31 downto 0);
begin
dff_a: dff2
port map
(
- clk => clk,
- reset => '0',
- d => a0,
- q => a
+ clk_i => clk_i,
+ reset_i => '0',
+ d_i => a0_i,
+ q_o => a_s
);
dff_b: dff2
port map
(
- clk => clk,
- reset => '0',
- d => b0,
- q => b
+ clk_i => clk_i,
+ reset_i => '0',
+ d_i => b0_i,
+ q_o => b_s
);
dff_index: dff2
port map
(
- clk => clk,
- reset => '0',
- d => index0,
- q => index
+ clk_i => clk_i,
+ reset_i => '0',
+ d_i => index0_i,
+ q_o => index_s
);
- qcount(0) <= a xor b;
- qcount(1) <= b;
- qcount(31 downto 2) <= count;
+ qcount_o(0) <= a_s xor b_s;
+ qcount_o(1) <= b_s;
+ qcount_o(31 downto 2) <= count_s;
- qcount_index <= count_index;
+ qcount_index_o <= count_index_s;
- comb_event: process (reset, last_reset, a_prev, b_prev, a, b)
- begin
- a_rise <= '0';
- a_fall <= '0';
- b_rise <= '0';
- b_fall <= '0';
- ab_event <= '0';
- ab_error <= '0';
+comb_event:
+ process (reset_i, last_reset_s, a_prev_s, b_prev_s, a_s, b_s)
+ begin
+ a_rise_o <= '0';
+ a_fall_o <= '0';
+ b_rise_o <= '0';
+ b_fall_o <= '0';
+ ab_event_o <= '0';
+ ab_error_o <= '0';
- if reset = '0' and last_reset = '0' then
- if ((a xor a_prev) and (b xor b_prev)) = '1' then
+ if reset_i = '0' and last_reset_s = '0' then
+ if ((a_s xor a_prev_s) and (b_s xor b_prev_s)) = '1' then
-- forbidden double transition
- ab_error <= '1';
+ ab_error_o <= '1';
else
- a_rise <= (a xor a_prev) and a;
- a_fall <= (a xor a_prev) and not a;
- b_rise <= (b xor b_prev) and b;
- b_fall <= (b xor b_prev) and not b;
- ab_event <= (a xor a_prev) or (b xor b_prev);
+ a_rise_o <= (a_s xor a_prev_s) and a_s;
+ a_fall_o <= (a_s xor a_prev_s) and (not a_s);
+ b_rise_o <= (b_s xor b_prev_s) and b_s;
+ b_fall_o <= (b_s xor b_prev_s) and (not b_s);
+ ab_event_o <= (a_s xor a_prev_s) or (b_s xor b_prev_s);
end if;
end if;
end process;
- comb_count: process (reset, last_reset, a_prev, b_prev, a, b, index, count_prev, count_index_prev)
- begin
- if reset = '1' or last_reset = '1' then
- count <= count_prev;
- count_index <= count_index_prev;
-
- elsif (a_prev = '0') and (b_prev = '1') and (a = '0') and (b = '0') then
- count <= count_prev + 1;
-
- if index = '1' then
- count_index(0) <= a xor b;
- count_index(1) <= b;
- count_index(31 downto 2) <= count_prev + 1;
+comb_count:
+ process (reset_i, last_reset_s, a_prev_s, b_prev_s, a_s, b_s,
+ index_s, count_prev_s, count_index_prev_s)
+ begin
+ if reset_i = '1' or last_reset_s = '1' then
+ count_s <= count_prev_s;
+ count_index_s <= count_index_prev_s;
+ elsif (a_prev_s = '0') and (b_prev_s = '1') and (a_s = '0') and
+ (b_s = '0') then
+ count_s <= count_prev_s + 1;
+ if index_s = '1' then
+ count_index_s(0) <= a_s xor b_s;
+ count_index_s(1) <= b_s;
+ count_index_s(31 downto 2) <= count_prev_s + 1;
else
- count_index <= count_index_prev;
+ count_index_s <= count_index_prev_s;
end if;
-
- elsif (a_prev = '0') and (b_prev = '0') and (a = '0') and (b = '1') then
- count <= count_prev - 1;
-
- if index = '1' then
- count_index(0) <= a xor b;
- count_index(1) <= b;
- count_index(31 downto 2) <= count_prev - 1;
+ elsif (a_prev_s = '0') and (b_prev_s = '0') and (a_s = '0') and
+ (b_s = '1') then
+ count_s <= count_prev_s - 1;
+
+ if index_s = '1' then
+ count_index_s(0) <= a_s xor b_s;
+ count_index_s(1) <= b_s;
+ count_index_s(31 downto 2) <= count_prev_s - 1;
else
- count_index <= count_index_prev;
+ count_index_s <= count_index_prev_s;
end if;
-
else
- count <= count_prev;
-
- if index = '1' then
- count_index(0) <= a xor b;
- count_index(1) <= b;
- count_index(31 downto 2) <= count_prev;
+ count_s <= count_prev_s;
+ if index_s = '1' then
+ count_index_s(0) <= a_s xor b_s;
+ count_index_s(1) <= b_s;
+ count_index_s(31 downto 2) <= count_prev_s;
else
- count_index <= count_index_prev;
+ count_index_s <= count_index_prev_s;
end if;
-
end if;
end process;
- seq: process (clk)
- begin
+seq:
+ process (clk_i)
+ begin
-- Reset for qcounter is synchronous and lasts at least one more cycle
-- to prevent hazardous states after releasing it
- if clk = '1' and clk'event then
- if reset = '0' then
- count_prev <= count;
- count_index_prev <= count_index;
+ if clk_i = '1' and clk_i'event then
+ if reset_i = '0' then
+ count_prev_s <= count_s;
+ count_index_prev_s <= count_index_s;
else
- count_prev <= (others => '0');
- count_index_prev <= (others => '0');
+ count_prev_s <= (others => '0');
+ count_index_prev_s <= (others => '0');
end if;
- a_prev <= a;
- b_prev <= b;
- last_reset <= reset;
+ a_prev_s <= a_s;
+ b_prev_s <= b_s;
+ last_reset_s <= reset_i;
end if;
end process;