Consider this VHDL process for a 2-bit binary up counter with asynchronous reset:
process(clk, reset)
begin
if reset = '1' then
count <= "00";
elsif rising_edge(clk) then
count <= count + 1;
end if;
end process;If the reset is deasserted at the start and the clock ticks 5 times, what is the value of count?
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port( clk : in std_logic; reset : in std_logic; count : out std_logic_vector(1 downto 0) ); end entity; architecture rtl of counter is signal count_reg : unsigned(1 downto 0) := (others => '0'); begin process(clk, reset) begin if reset = '1' then count_reg <= (others => '0'); elsif rising_edge(clk) then count_reg <= count_reg + 1; end if; end process; count <= std_logic_vector(count_reg); end architecture;
Count starts at 0 and increments by 1 each clock cycle. Remember it is 2 bits wide.
The 2-bit counter counts from 00, 01, 10, 11, then wraps around to 00, 01. After 5 clock cycles starting from 00, the count is 01 (decimal 1).
Given a 3-bit binary up counter that increments on every rising clock edge and resets asynchronously to zero, what will be the value of the counter after 8 clock cycles?
signal count : unsigned(2 downto 0) := (others => '0'); process(clk, reset) begin if reset = '1' then count <= (others => '0'); elsif rising_edge(clk) then count <= count + 1; end if; end process;
Think about the maximum count for 3 bits and what happens after 8 increments.
A 3-bit counter counts from 0 to 7 ("000" to "111"). After 8 increments, it wraps back to "000".
Examine this VHDL code snippet for a 4-bit binary up counter:
process(clk)
begin
if rising_edge(clk) then
count <= count + 1;
elsif reset = '1' then
count <= (others => '0');
end if;
end process;What error will this code cause during synthesis or simulation?
signal count : unsigned(3 downto 0) := (others => '0');
Check the order of conditions and sensitivity list.
The reset condition is checked after the clock edge condition, so reset will never trigger properly. Also, reset is not in the sensitivity list, so asynchronous reset won't work.
Choose the correct VHDL signal declaration for a 5-bit binary up counter using unsigned type.
Remember that the range defines the bit width and direction.
Unsigned vectors are usually declared with the most significant bit on the left. For 5 bits, indices 4 downto 0 give 5 bits.
A 6-bit binary up counter increments by 1 on each clock cycle and wraps around after reaching its maximum value. How many unique states does it have before it repeats?
Think about how many values can be represented with 6 bits.
A 6-bit counter can represent 2^6 = 64 unique states, from 0 to 63.
