MOULDLKnowledge BaseElectrical Knowledge Base3D Model DownloadsMembership
中文版Model Store »
Knowledge Base › Electrical Knowledge Base › Building a counter of any modulus with flip-flops
HomeModels
Table of contents

On this page

Electrical & Electronic Basics (600 articles)

Quick Reference

  • PLC & Programming
  • Electrical & Electronic Basics (monthly)(每月更新中)
  • Electrical Control & Drawings (monthly)(每月更新中)
  • Drives & Actuators (monthly)(每月更新中)
  • Sensors & Detection (monthly)(每月更新中)
  • Industrial Communication & Networks (monthly)(每月更新中)
  • HMI & Host Systems (monthly)(每月更新中)
  • Industrial Robots & Motion Control (monthly)(每月更新中)
  • Mechatronic System Integration (monthly)(每月更新中)
  • Fault Diagnosis & Standards (monthly)(每月更新中)

Building a counter of any modulus with flip-flops

Not every count is a power of two or a decade: 60 seconds, 24 hours, 7 days. This page shows the reset method and the preset method for an arbitrary N modulus.

1. How it works

Reset method (feedback clear): take an M-bit binary counter with 2^M at or above N, let it count freely from 0, and when it reaches N, or N minus 1 for the synchronous variant, a gate detects that state and drives the clear input, so the counter only ever cycles 0 to N minus 1. An asynchronous clear acts the instant N appears and the state may flash briefly; a synchronous clear waits for the next edge.

2. Numbers and practice

Preset method (feedback load): start from an initial value, count to full scale, then reload the initial value, skipping the surplus states. For a divide-by-6 on 3 bits, start at 0000, count to 0101, five, and on the next beat load 0000 back in. The synchronous preset produces no transient glitch, cleaner than the reset method and the first choice in engineering; changing N only means changing the detect or the preset value.

3. Pitfalls and fixes

Worked example, modulus 60: seconds counting uses two decades, units 0 to 9 and tens 0 to 5, and when the tens digit reaches 6, 0110, the feedback clears or reloads the pair to 00. The same pattern makes 24 hours: clear when tens equals 2 and units equals 4. Clocks and timers live on this feedback logic, and after building it you verify every beat against a state table.

4. Arbitrary modulus design comparison

MethodPrincipleGlitchSuitability
Reset methodClear at NBrief flash, asynchronousSimple
Preset methodReload initial value at NNoneEngineering first choice
Synchronous clearClears at the edgeFewHazard free
Asynchronous clearClears instantlyTransient presentFast but unclean
CascadeSeveral chips combinedDepends on typeLarge N
VerificationState tableMandatoryError proofing

5. Notes

Prefer the synchronous preset method in engineering, it is glitch free. After building, walk the state table beat by beat to prove the cycle length is exact and no code is skipped.

6. References

The quantities and component characteristics discussed here follow current national standards and the corresponding IEC documents: Arbitrary modulus counting per GB/T 4728 and IEC 60617 symbols. Always check the device datasheet and the product design file for ratings and derating.

7. Cautions

⚠️ Three common pitfalls:
① Reset detect state off by one:the cycle length is wrong, 60 becomes 59
② Asynchronous clear transient:the downstream stage samples the forbidden N state
③ Preset value not decremented:the cycle gains or loses one count and timing drifts

Locate the issue with the approach above, then confirm with measurements; safety-related circuits must follow the standards and manufacturer requirements.

Related reading

Related 3D models: Ready to build it? Download free 3D models & CAD drawings at MOULDL »
MOULDL · Electrical Knowledge Base · free self-study reference for electrical & automation engineers, 3D CAD models at MOULDL