0
0
Verilogprogramming~10 mins

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

Choose your learning style9 modes available
Concept Flow - Up counter design
Start: Reset counter to 0
Wait for clock rising edge
Increment counter by 1
Check if counter reached max
Hold new value
Back to Wait for clock
The counter starts at zero, increments by one on each clock pulse, and resets to zero when it reaches its maximum value.
Execution Sample
Verilog
module up_counter(
  input clk,
  input reset,
  output reg [3:0] count
);
  always @(posedge clk or posedge reset) begin
    if (reset) count <= 0;
    else if (count == 4'd15) count <= 0;
    else count <= count + 1;
  end
endmodule
A 4-bit up counter that increments on each clock pulse and resets to zero when reset is high or when the count reaches 15.
Execution Table
Stepclk edgeresetcount beforecount afterAction
1rising001Increment count from 0 to 1
2rising012Increment count from 1 to 2
3rising023Increment count from 2 to 3
4rising130Reset count to 0 due to reset
5rising001Increment count from 0 to 1
6rising012Increment count from 1 to 2
7rising023Increment count from 2 to 3
8rising034Increment count from 3 to 4
9rising045Increment count from 4 to 5
10rising056Increment count from 5 to 6
11rising067Increment count from 6 to 7
12rising078Increment count from 7 to 8
13rising089Increment count from 8 to 9
14rising0910Increment count from 9 to 10
15rising01011Increment count from 10 to 11
16rising01112Increment count from 11 to 12
17rising01213Increment count from 12 to 13
18rising01314Increment count from 13 to 14
19rising01415Increment count from 14 to 15
20rising0150Overflow: count resets to 0 (4-bit max reached)
💡 Counter resets to 0 after reaching maximum 4-bit value 15, then continues counting.
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6After 7After 8After 9After 10After 11After 12After 13After 14After 15After 16After 17After 18After 19After 20
count012301234567891011121314150
Key Moments - 3 Insights
Why does the counter reset to 0 when it reaches 15?
Because the counter is 4-bit wide, it can only count from 0 to 15. After 15, it overflows and resets to 0 as shown in execution_table row 20.
What happens if reset is high during a clock edge?
The counter immediately resets to 0 regardless of its previous value, as shown in execution_table row 4.
Why do we use 'posedge clk' in the always block?
Because the counter increments only on the rising edge of the clock signal, ensuring synchronous counting as shown in the concept_flow.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of count after step 5?
A3
B0
C1
D5
💡 Hint
Check the 'count after' column in execution_table row 5.
At which step does the reset signal cause the count to go to zero?
AStep 3
BStep 4
CStep 10
DStep 20
💡 Hint
Look for the row where reset is 1 in execution_table.
If the counter was 3-bit instead of 4-bit, what would happen at step 20?
ACount resets to 0 after 7
BCount resets to 0 after 15
CCount increments to 16
DCount stays at 15
💡 Hint
A 3-bit counter max value is 7, so overflow happens after 7.
Concept Snapshot
Up Counter Design in Verilog:
- Use always @(posedge clk or posedge reset) block
- If reset is high, set count to 0
- Else if count reaches max (15), reset to 0
- Else increment count by 1 on each clock rising edge
- Counter width limits max count (e.g., 4-bit max 15)
- After max, counter overflows back to 0
Full Transcript
This visual execution traces a 4-bit up counter in Verilog. The counter starts at zero and increments by one on each rising clock edge. If the reset signal is high, the counter resets to zero immediately. The counter counts from 0 up to 15, then overflows back to 0 due to its 4-bit width limit. The execution table shows each clock step, the reset state, the count before and after increment, and the action taken. The variable tracker follows the count value through each step. Key moments clarify why the counter resets at 15, how reset works, and why the clock edge is used. The quiz tests understanding of count values at specific steps and the effect of reset and bit width. The snapshot summarizes the Verilog code pattern for an up counter.