Challenge - 5 Problems
BCD Counter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of a simple BCD counter process
What is the output value of the signal
count after 12 clock cycles in the following BCD counter process?VHDL
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity bcd_counter is Port ( clk : in STD_LOGIC; reset : in STD_LOGIC; count : out STD_LOGIC_VECTOR (3 downto 0)); end bcd_counter; architecture Behavioral of bcd_counter is signal cnt : unsigned(3 downto 0) := (others => '0'); begin process(clk, reset) begin if reset = '1' then cnt <= (others => '0'); elsif rising_edge(clk) then if cnt = to_unsigned(9, 4) then cnt <= (others => '0'); else cnt <= cnt + 1; end if; end if; end process; count <= std_logic_vector(cnt); end Behavioral;
Attempts:
2 left
💡 Hint
Remember the counter resets to 0 after reaching 9.
✗ Incorrect
The counter increments from 0 to 9 and then resets. After 12 clock cycles, it counts 0 to 9 (10 cycles), then 0 and 1 for the next two cycles, so the count is 2 (binary 0010).
🧠 Conceptual
intermediateUnderstanding BCD counter reset behavior
In a BCD counter implemented in VHDL, what is the main reason for resetting the count to 0 when the count reaches 9?
Attempts:
2 left
💡 Hint
Think about what decimal digits a BCD counter should represent.
✗ Incorrect
A BCD counter counts decimal digits 0 through 9. Resetting at 9 ensures the counter stays within valid decimal digit range.
🔧 Debug
advancedIdentify the error in this BCD counter code snippet
What error will occur when running this VHDL BCD counter code?
VHDL
process(clk, reset)
begin
if reset = '1' then
cnt <= (others => '0');
elsif rising_edge(clk) then
if cnt = 10 then
cnt <= (others => '0');
else
cnt <= cnt + 1;
end if;
end if;
end process;Attempts:
2 left
💡 Hint
Check the data type and value used in the comparison.
✗ Incorrect
The signal 'cnt' is unsigned(3 downto 0), so comparing it to integer 10 directly is invalid. It should be compared to unsigned("1010") or converted properly.
📝 Syntax
advancedSyntax error in BCD counter process
Which option contains the correct syntax to increment a 4-bit unsigned BCD counter in VHDL?
VHDL
process(clk, reset)
begin
if reset = '1' then
cnt <= (others => '0');
elsif rising_edge(clk) then
-- increment logic here
end if;
end process;Attempts:
2 left
💡 Hint
Consider the data type of 'cnt' and how to compare it properly.
✗ Incorrect
Since 'cnt' is unsigned(3 downto 0), it must be compared to an unsigned value. Option A uses 'to_unsigned(9,4)' which is correct syntax.
🚀 Application
expertDesign challenge: Extending a BCD counter to count from 0 to 59
You want to design a VHDL counter that counts from 0 to 59 in BCD format (two digits). Which approach correctly implements this?
Attempts:
2 left
💡 Hint
Think about how BCD digits represent decimal numbers and how to handle carry between digits.
✗ Incorrect
BCD counting from 0 to 59 requires two digits: units (0-9) and tens (0-5). Increment units each clock, and when units reach 9, reset units and increment tens. Tens resets at 5.
