BitFlow

Mod-N Counter

intermediate · sequential · 150 XP

Sign in to write your solution, run it in the simulator and submit it for grading.

Sign in or create a free account →

Problem

Mod-N Counter A **Mod-N counter** counts from 0 to N-1 and then resets back to 0. Unlike a power-of-2 counter, it can count to any arbitrary modulus. Implement a **Mod-6 counter** (counts 0→1→2→3→4→5→0→...): **Interface** | Port | Direction | Width | Description | |-----------|-----------|-------|--------------------------| | `clk` | input | 1 | Clock | | `rst` | input | 1 | Synchronous reset | | `count[3:0]`| output | 4 | Current count (0 to 5) | **Behaviour:** - Counts 0 → 5, then wraps to 0 on the next clock - When count reaches N-1 (5), the **next** clock resets to 0 **Use case:** Divide-by-6 clock divider (the output toggles every 3 counts → 6 count period). BCD counters are Mod-10. Seconds/minutes are Mod-60 chains. **Generalisation:** Replace the constant 6 with a parameter for a fully generic Mod-N counter.

Constraints

  • Synchronous design — always @(posedge clk).
  • Count must not exceed 5 at any time.
  • Wrap from 5 → 0 on the next clock edge.

Examples

Input: After 6 clocks from reset

Output: count=0 (wrapped)

Input: After 11 clocks from reset

Output: count=5

Common questions

What does the Mod-N Counter problem ask you to build?
Mod-N Counter A **Mod-N counter** counts from 0 to N-1 and then resets back to 0. Unlike a power-of-2 counter, it can count to any arbitrary modulus.
What constraints does Mod-N Counter have?
Synchronous design — always @(posedge clk).; Count must not exceed 5 at any time.; Wrap from 5 → 0 on the next clock edge.
What is an example input and output for Mod-N Counter?
Input After 6 clocks from reset gives output count=0 (wrapped).
Which Verilog concepts does Mod-N Counter practise?
sequential, counter, mod-n, modulo, interview.