0
0
Verilogprogramming~10 mins

Down counter design in Verilog - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Down counter design
Start with initial count
Check if count > 0?
NoStop or reset
Yes
Decrease count by 1
Output current count
Wait for next clock pulse
Back to Check
The down counter starts from an initial value, checks if it is greater than zero, decreases it by one each clock cycle, outputs the count, and repeats until zero.
Execution Sample
Verilog
module down_counter(
  input clk,
  input reset,
  output reg [3:0] count
);
  always @(posedge clk or posedge reset) begin
    if (reset) count <= 4'd10;
    else if (count > 0) count <= count - 1;
  end
endmodule
This Verilog module counts down from 10 to 0 on each clock pulse, resetting to 10 when reset is high.
Execution Table
Stepclk edgeresetcount beforeCondition (count > 0)Actioncount afterOutput
1rising1X (undefined)N/AReset active, count set to 101010
2rising010Truecount = 10 - 199
3rising09Truecount = 9 - 188
4rising08Truecount = 8 - 177
5rising07Truecount = 7 - 166
6rising06Truecount = 6 - 155
7rising05Truecount = 5 - 144
8rising04Truecount = 4 - 133
9rising03Truecount = 3 - 122
10rising02Truecount = 2 - 111
11rising01Truecount = 1 - 100
12rising00FalseNo decrement00
💡 Count reaches 0, condition count > 0 is False, counting stops.
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6After 7After 8After 9After 10After 11Final
countX (undefined)1098765432100
Key Moments - 3 Insights
Why does the count not go below zero?
Because the condition 'count > 0' is checked before decrementing (see execution_table step 12), so when count is 0, it stops decrementing.
What happens when reset is active?
At step 1 in the execution_table, reset sets count to 10 immediately regardless of previous value.
Why is the output the same as count after each step?
Because the output is directly the current count value after decrement or reset, shown in the 'Output' column matching 'count after'.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 5, what is the count after decrement?
A5
B7
C6
D8
💡 Hint
Check the 'count after' column at step 5 in the execution_table.
At which step does the condition 'count > 0' become false?
AStep 12
BStep 10
CStep 11
DStep 1
💡 Hint
Look at the 'Condition (count > 0)' column in the execution_table.
If reset is activated again at step 6, what would be the count after that step?
A5
B10
C6
D0
💡 Hint
Reset sets count to 10 immediately as shown in step 1 of the execution_table.
Concept Snapshot
Down counter in Verilog:
- Use always block triggered by clock and reset
- On reset, set count to initial value
- On clock, if count > 0, decrement count
- Output current count
- Stops at zero, no negative values
Full Transcript
This visual execution traces a Verilog down counter module. It starts with an undefined count, then reset sets it to 10. On each rising clock edge, if count is greater than zero, it decreases by one. The output shows the current count after each decrement. When count reaches zero, the condition to decrement fails, so the count stays at zero. Reset can be triggered anytime to restart the count at 10. The variable tracker shows count values step by step. Key moments clarify why count never goes below zero and how reset works. The quiz tests understanding of count values at specific steps and reset behavior.