0
0
Verilogprogramming~30 mins

Modulo-N counter in Verilog - Mini Project: Build & Apply

Choose your learning style9 modes available
Modulo-N Counter in Verilog
📖 Scenario: You are designing a simple digital counter that counts from 0 up to a number N-1 and then wraps back to 0. This is useful in many electronics projects like timers, clocks, or event counters.
🎯 Goal: Build a modulo_n_counter module in Verilog that counts from 0 to N-1 and then resets to 0 on the next clock cycle.
📋 What You'll Learn
Create a register to hold the current count.
Use a parameter N to set the modulo value.
Increment the counter on each positive clock edge.
Reset the counter to 0 when it reaches N-1.
Output the current count.
💡 Why This Matters
🌍 Real World
Modulo counters are used in digital clocks, timers, frequency dividers, and event counters in electronics.
💼 Career
Understanding counters is fundamental for hardware design engineers working with FPGAs, ASICs, and embedded systems.
Progress0 / 4 steps
1
Create the module and declare the counter register
Write a Verilog module named modulo_n_counter with inputs clk and rst, and an output count of 4 bits. Declare a 4-bit register called count_reg to hold the current count.
Verilog
Need a hint?

Remember to declare count_reg as a 4-bit register inside the module.

2
Add parameter N for modulo value
Add a parameter N with value 10 to the modulo_n_counter module to set the modulo value.
Verilog
Need a hint?

Use the parameter keyword to define N inside the module.

3
Implement the counting logic with reset and modulo wrap
Inside an always @(posedge clk) block, write code that resets count_reg to 0 when rst is high. Otherwise, increment count_reg by 1. If count_reg reaches N-1, reset it to 0 on the next clock cycle.
Verilog
Need a hint?

Use non-blocking assignments <= inside the always block for registers.

4
Assign the output count from the register and display it
Assign the output count to the value of count_reg. Then write a testbench initial block that resets the counter, runs the clock for 15 cycles, and uses $display to print the count value on each cycle.
Verilog
Need a hint?

Assign count to count_reg using a combinational block or continuous assignment. Use a testbench to simulate and print the count values.