MOULDLKnowledge BaseElectrical Knowledge Base3D Model DownloadsMembership
中文版Model Store »
Knowledge Base › Electrical Knowledge Base › What is the difference between timed and external interrupts, and when is each used?
HomeModels
Table of contents

On this page

PLC & Programming (100 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)(每月更新中)

What is the difference between timed and external interrupts, and when is each used?

Interrupts are the "don't wait for the scan, handle it now" channel: timed interrupts insert on a fixed period, external interrupts trigger on an input's edge. They solve different problems — timed interrupts handle "it is time, must do", external interrupts handle "the signal arrived, do it now". Used right they achieve what the scan cannot; used wrong they become a priority disaster. The sections below compare mechanisms, uses, discipline and taboos.

1. Mechanism comparison

AspectTimed interruptExternal interrupt
Trigger sourceTimer expiry (e.g. every 10/20 ms)Edge on a designated input X
TimingFixed period, asynchronous to the scanInserts as the signal edge arrives
Typical carrierFX I6□□ timer interrupts; IEC platform tasksFX I0□0~I5□0 input interrupts (X0~X5)
Response latency≤ 1 interrupt periodSub-millisecond (versus scan times of several to tens of ms)
Right forPeriodic sampling, comms polling, pulse-width controlEncoder Z phase, home signal, capture-type instant events

The rule of thumb: events arriving on a time schedule → timed interrupt; events decided by an external instantaneous signal → external interrupt; neither is urgent → ordinary scan code, and leave interrupts alone.

2. Typical uses of timed interrupts

① Fixed-period sampling: temperature and pressure every 10 ms for filtering — scan jitter does not bend the sample rhythm, so filter windows stay true; ② pulse-width / proportional control: duty computed on a 10 ms cycle, steadier than scan code; ③ communication polling: high-priority slave exchanges on schedule; ④ time accumulation decoupled from the scan: run-seconds counted on true time (scan-based timers drift when long tasks stretch the cycle).

Setting rule: the interrupt period must clearly exceed the interrupt program's execution time (generally ≤ 30% of the period), or the interrupt re-triggers continuously, starves the main program, and the scan time balloons into a watchdog trip.

3. Typical uses of external interrupts

① Home-signal capture: on servo/stepper homing, latch the current position the instant the home switch edges — far more accurate than scan polling; ② encoder Z-phase counting: revolutions accumulate on the Z edge without losing counts; ③ instant event logging: time-stamping microsecond-to-millisecond events like probe trips or camera exposure-done. The external interrupt's creed is "in fast, out fast": the interrupt only latches (move the needed data, set a flag) and all processing waits for the main scan.

4. Universal discipline for interrupt programs

RuleReason
Short: a few to a few dozen instructionsInterrupt time is deducted directly from the main scan
Latch only, process neverProcessing belongs to the main program; the interrupt moves data and sets flags
Dedicated data areaInterrupt and main both writing one device = a race; values may tear
No long instructionsComms instructions or bulk moves in an interrupt freeze the main program
Flag handshakeInterrupt sets "new data"; main processes and clears the flag

On "dedicated data area": the interrupt writes D100 (position latch), the main reads it and never writes; the main writes its consumed result to D110 — writers separated, readers free. Sharing one D for both read and write occasionally delivers a half-written value, a race bug that is rare and nearly impossible to reproduce.

5. When not to use interrupts

① Ordinary buttons and in-position signals: a scan cycle of a few milliseconds is imperceptible — interrupts add complexity for nothing; ② control logic sharing lots of state across places: interrupt isolation makes synchronisation harder; ③ cases that need "certainty" more than "speed": timed sampling with flag handshakes beats interrupts for controllability. The principle: confirm the scan genuinely cannot do it before reaching for interrupts — they are special equipment, not standard kit.

6. Common errors

SymptomCauseFix
Main scan time balloonsInterrupt program too long / period too shortSlim the interrupt, widen the period
Watchdog tripsInterrupt re-triggers continuously, saturating the CPUPeriod ≥ 3× execution time
Latched value occasionally wrongInterrupt and main writing the same deviceDedicated areas + flag handshake
Interrupt never firesInterrupt not enabled / input filter too coarseEnable per manual, reduce the input filter
Glitches trigger false interruptsFast signal line picking up noiseShield earthing + hardware filter setting

7. Notes

Both interrupt types share one philosophy: "in fast, out fast". The interrupt only seizes the instantaneous fact (time's up / signal came) and its data; judgement and action all stay in the main program. Hold that boundary and interrupts are a speed tool; cross it and they become a random-fault generator.

8. References

Interrupt instructions, pointers and settings follow the PLC's programming manual (e.g. Mitsubishi FX interrupt functions, Q-series I/O and timer interrupts); IEC platforms correspond to tasks and event mechanisms in the CODESYS/TwinCAT task documentation; the relation of interrupts to safety follows GB 5226.1 / IEC 60204-1 — safety response never depends on PLC interrupts; the safety circuit stays hard-wired.

9. Cautions

⚠️ Three traps to avoid:
① Alarm processing stuffed into an interrupt — it grows, and the main scan loses control;
② Interrupt latch and main sharing one D — occasional torn values, faults that never reproduce;
③ Input-filter setting left coarse on an input interrupt — millisecond signals eaten by the filter and the interrupt "never fires".

Before adding any interrupt, do two sums: the interrupt's execution time and the main scan's headroom — three times margin each, and the interrupt stays obedient.

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