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.
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.
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.
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.
| Scheme | Device | Trait |
|---|---|---|
| RS debounce | Dual NAND | Zero delay, no software |
| Schmitt | 74LS14 | Hysteresis, noise proof |
| RC filter | Resistor and capacitor | Simple but slow |
| D latch | 74LS74 | Edge capture |
| Software debounce | MCU | 10ms delay |
| One-shot | 555 or 74 series | Fixed width pulse |
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.
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.
Locate the issue with the approach above, then confirm with measurements; safety-related circuits must follow the standards and manufacturer requirements.