MOULDLKnowledge BaseElectrical Knowledge Base3D Model DownloadsMembership
中文版Model Store »
Knowledge Base › Electrical Knowledge Base › How flip-flops handle switch debouncing and pulse shaping
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)(每月更新中)

How flip-flops handle switch debouncing and pulse shaping

A mechanical key bounces when pressed, and raw contact into a counter or interrupt reads as several presses. This page covers debouncing with a basic RS or D flip-flop and pulse shaping with a Schmitt trigger.

1. How it works

Mechanical contacts bounce for 5 to 20ms when they close, the voltage wobbling between high and low several times. Fed straight into a counter or an interrupt, the MCU counts one press as many. The classic cure is RC filtering plus a Schmitt gate, but pure hardware delay is large; latching with a flip-flop is the sturdiest fix: once the first valid edge is captured the state locks and every later bounce edge is masked.

2. Numbers and practice

The RS debouncing circuit: connect the two sides of the key to Sbar and Rbar of a basic RS through pull-up resistors. Pressing forces one side low and sets the latch, releasing forces the other side low and resets it, and during the bounces, with both inputs high, the latch simply holds. It is the textbook debounce: no software, no delay, common on industrial panels.

3. Pitfalls and fixes

Schmitt pulse shaping: when a signal edge is slow or noisy, run it through a Schmitt trigger such as the 74LS14. Its hysteresis, about 1.7V positive and 0.9V negative threshold, declares 0 only below the low limit and 1 only above the high limit, so noise in between is swallowed and the output is a clean square wave. Paired with an RC it also makes one-shots and delays; debounce and shaping usually appear together.

4. Debouncing and shaping device quick reference

SchemeDeviceTrait
RS debounceDual NANDZero delay, no software
Schmitt74LS14Hysteresis, noise proof
RC filterResistor and capacitorSimple but slow
D latch74LS74Edge capture
Software debounceMCU10ms delay
One-shot555 or 74 seriesFixed width pulse

5. Notes

Panel keys are most reliably debounced by an RS latch in hardware; run slow signals through a Schmitt trigger before the MCU. Software debounce needs a 10 to 20ms delay to clear the bounce zone.

6. References

The quantities and component characteristics discussed here follow current national standards and the corresponding IEC documents: Interface and shaping circuits per GB/T 4728 and IEC 60748 series. Always check the device datasheet and the product design file for ratings and derating.

7. Cautions

⚠️ Three common pitfalls:
① Key wired straight to an interrupt with no debounce:bounces count as multiple presses and the tally doubles
② Schmitt thresholds referenced to the wrong rail:hysteresis dead, noise passes to the next stage untouched
③ Software delay shorter than 5ms:the bounce zone is not cleared and false triggers persist

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