Challenge - 5 Problems
Modulo-N Counter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of a simple Modulo-4 counter process
Consider the following VHDL process for a Modulo-4 counter. What is the value of
count after 5 rising clock edges?VHDL
process(clk) variable count : integer range 0 to 3 := 0; begin if rising_edge(clk) then if count = 3 then count := 0; else count := count + 1; end if; end if; end process;
Attempts:
2 left
💡 Hint
Count cycles from 0 to 3 and resets after 3.
✗ Incorrect
The counter starts at 0. After 1st clock edge: 1, 2nd: 2, 3rd: 3, 4th: 0 (reset), 5th: 1, so after 5 edges count is 1. But since variable count is updated inside process, the value after 5 edges is 1. The correct answer is 1.
🧠 Conceptual
intermediateUnderstanding Modulo-N counter range
If you want to design a Modulo-10 counter in VHDL using an integer variable, what should be the correct range declaration for the counter variable?
Attempts:
2 left
💡 Hint
Modulo-10 means counting 10 states starting from 0.
✗ Incorrect
A Modulo-10 counter counts from 0 up to 9, then resets to 0. So the range should be 0 to 9.
🔧 Debug
advancedIdentify the error in this Modulo-5 counter code
What error will this VHDL code cause when synthesizing a Modulo-5 counter?
process(clk)
variable count : integer range 0 to 4 := 0;
begin
if rising_edge(clk) then
if count = 5 then
count := 0;
else
count := count + 1;
end if;
end if;
end process;
Attempts:
2 left
💡 Hint
Check the variable range and the condition in the if statement.
✗ Incorrect
The variable 'count' is declared with range 0 to 4, so it can never be 5. The condition 'if count = 5' is unreachable and causes a range check error.
📝 Syntax
advancedSyntax error in Modulo-N counter process
Which option contains the correct syntax for a Modulo-3 counter process in VHDL?
VHDL
process(clk) variable count : integer range 0 to 2 := 0; begin if rising_edge(clk) then if count = 2 then count := 0; else count := count + 1; end if; end if; end process;
Attempts:
2 left
💡 Hint
Check for missing semicolons and correct assignment operator.
✗ Incorrect
Option B has correct syntax with semicolons and uses ':=' for assignment. Option B misses semicolon after variable declaration. Option B uses '=' instead of ':=' for assignment. Option B misses semicolon after 'count := 0'.
🚀 Application
expertDesign behavior of a Modulo-6 counter with asynchronous reset
Given this VHDL code snippet for a Modulo-6 counter with asynchronous reset, what will be the value of
count after the following sequence: reset asserted (count resets), then 7 rising clock edges?
process(clk, reset)
variable count : integer range 0 to 5 := 0;
begin
if reset = '1' then
count := 0;
elsif rising_edge(clk) then
if count = 5 then
count := 0;
else
count := count + 1;
end if;
end if;
end process;Attempts:
2 left
💡 Hint
Count starts at 0 after reset, then increments modulo 6.
✗ Incorrect
After reset, count is 0. Then 7 clock edges increment count: 0->1->2->3->4->5->0->1. After 7 edges, count is 1. But since variable updates inside process, after 7 edges count is 1. The correct answer is 1.
