Consider a VHDL timer counting from 0 to 9 with a terminal count output that goes high when the count reaches 9. What is the value of the terminal count output (tc) after 10 clock cycles?
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity timer is Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; tc : out STD_LOGIC); end timer; architecture Behavioral of timer is signal count : unsigned(3 downto 0) := (others => '0'); begin process(clk, reset) begin if reset = '1' then count <= (others => '0'); elsif rising_edge(clk) then if count = 9 then count <= (others => '0'); else count <= count + 1; end if; end if; end process; tc <= '1' when count = 9 else '0'; end Behavioral;
Think about when the terminal count output is set high in relation to the count value.
The terminal count output (tc) is assigned '1' when the count reaches 9. After 10 clock cycles, the count reaches 9 once, so tc is '1'.
Given the same timer design, what is the value of the count signal after reset is deasserted (reset = '0') and 5 rising clock edges?
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity timer is Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; count_out : out unsigned(3 downto 0)); end timer; architecture Behavioral of timer is signal count : unsigned(3 downto 0) := (others => '0'); begin process(clk, reset) begin if reset = '1' then count <= (others => '0'); elsif rising_edge(clk) then if count = 9 then count <= (others => '0'); else count <= count + 1; end if; end if; end process; count_out <= count; end Behavioral;
Count increments by 1 each clock cycle after reset is released.
After reset is '0', the count starts at 0 and increments by 1 each clock cycle. After 5 cycles, count = 5.
In the following VHDL code, the terminal count output (tc) never goes high. What is the cause of this problem?
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity timer is Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; tc : out STD_LOGIC); end timer; architecture Behavioral of timer is signal count : unsigned(3 downto 0) := (others => '0'); begin process(clk, reset) begin if reset = '1' then count <= (others => '0'); elsif rising_edge(clk) then if count = 10 then count <= (others => '0'); else count <= count + 1; end if; end if; end process; tc <= '1' when count = 9 else '0'; end Behavioral;
Check the maximum value a 4-bit unsigned signal can hold.
A 4-bit unsigned signal can only represent values 0 to 15, but the count is compared to 10 to reset. Since count increments from 0 to 9, it never reaches 10, so the reset condition never triggers and count never resets. This causes tc to never be '1' because count never equals 9 at the right time.
Which of the following code snippets will cause a syntax error in the timer process?
Look for missing semicolons or keywords in the if-elsif statement.
Option A is missing a semicolon after the first assignment, causing a syntax error. All other options have correct syntax.
Given a timer counting from 0 to 9 with terminal count output (tc) going high when count = 9, how many clock cycles are needed for tc to pulse high twice starting from reset?
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity timer is Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; tc : out STD_LOGIC); end timer; architecture Behavioral of timer is signal count : unsigned(3 downto 0) := (others => '0'); begin process(clk, reset) begin if reset = '1' then count <= (others => '0'); elsif rising_edge(clk) then if count = 9 then count <= (others => '0'); else count <= count + 1; end if; end if; end process; tc <= '1' when count = 9 else '0'; end Behavioral;
Count how many cycles it takes for the count to reach 9 twice starting from 0.
The count starts at 0 after reset. It takes 10 clock cycles to reach 9 the first time (counts 0 to 9). After resetting to 0, it takes 9 more cycles to reach 9 again. So total cycles = 10 + 9 = 19.
