Edge detection catches "the instant of change", but field signals bounce: buttons chatter for tens of milliseconds, sensors loiter at the threshold, inverter noise sprays glitches. Bounce manufactures a stream of false edges — counts double, states flip madly. The cure is one sentence: filter first, then take the edge — debounce and filtering wash the signal, edge detection only works on clean signal. The sections below cover bounce sources, debouncing, filtering choice and the chain order.
| Source | Typical duration | Victims |
|---|---|---|
| Mechanical button bounce | 5~20 ms | Counting, one-button toggling |
| Relay contact bounce | Several to ~15 ms | Feedback-signal edges |
| Proximity switch at the edge of detection | Varies with part sway | Part counting, in-position logic |
| Analog alarms hovering at threshold | Varies | Alarm edges firing repeatedly |
| EMI glitches | Microseconds to milliseconds | Any fast edge detection |
A PLC scans in milliseconds, so during a bounce it samples a string of ON/OFF alternations — the edge detector reports an edge for every one of them. That is the mechanism behind "one press, three counts".
Debouncing is a "confirmation window": after the signal changes, it must hold for a period (usually 20~50 ms) to count. In ladder: X0's rising edge starts timer T0 (K20); when T0 completes and X0 is still ON, set the "valid ON" flag M10; X0 falling likewise debounces before clearing M10. All downstream logic uses M10's edges, never X0's.
| Signal type | Suggested debounce | Basis |
|---|---|---|
| Panel buttons | 20~30 ms | Bounce ceiling plus margin |
| Relay feedback | 20~50 ms | Contact bounce + operate time |
| Proximity in-position | 10~30 ms | Steady without blunting the takt |
| Fast process signals | ≤ 10 ms or hardware filtering | Response must not be sacrificed |
High-speed signals (encoders, high-speed counters) go through hardware channels with their own filters — never software-debounce them; the software timers cannot keep pace and pulses are lost wholesale.
Digital filtering is the debounce timer above; analog values (or anything judged against a threshold) use numeric filtering: a sliding average over the last N samples, or a first-order lag. The key for alarm edges: judge the edge on the filtered value, and give the threshold hysteresis (alarm at 90 °C, clear at 85 °C) — then the alarm edge never flutters at the boundary.
The order cannot be shuffled: taking the edge before filtering hands every glitch a pass; filtering before the edge dissolves the glitch at the filter stage. Two canonical combinations:
① Counting: sensor → 20 ms debounce → rising edge → counter. Counting goes from luck to deterministic. ② One-button toggle: button → debounce → rising edge → toggle. One press, one flip, no double-jumps ever.
| Symptom | Cause | Fix |
|---|---|---|
| One press counts two or three | Edge detection straight on the button | Add 20 ms debounce before the edge |
| Part counts occasionally high | Part loitering at the sensing edge, multiple edges | Relocate the sensor + debounce + sample in the stable zone |
| Alarm fires repeatedly near threshold | No filtering, no hysteresis on the alarm edge | Filtering + hysteresis band |
| High-speed pulse counts low | Software debounce on a fast signal | Move to the high-speed counter hardware channel |
| Debounced response too dull | Debounce time picked arbitrarily large | Follow the type table, verify the takt live |
| Glitches still trigger occasionally | Software fine, wiring and shielding bad | Fix the hardware layer: shield earthing, cable separation |
Filtering, debouncing and edge detection are three layers of one job: filtering makes the signal clean, debouncing makes the state confirmed, edge detection catches the change. The order is always filter → debounce → edge. Wrap the whole chain in one standard function block (input + debounce-time parameter + edge output) and reuse it project-wide — bounce-class faults then vanish for good.
Edge instructions and timer usage follow the PLC's programming manual; input filter parameters follow the hardware manuals; signal cabling and interference control follow GB 5226.1 / IEC 60204-1; drawing counting chains to GB/T 4728 symbols eases design review.
Remember the division of labour: electrical noise is fixed by wiring, mechanical bounce by debouncing, duplicate logic by edge detection — software is the last line, never asked to repay wiring's debts.