Explainer
PLC input stability timer for multi-bit position commands
Short answer
Compare the three command inputs with their previous-scan states every scan, OR the mismatches into one InputChange bit, and hold a stability timer reset while that bit is true. Accept and decode the 3-bit position command only after the timer expires with the word unchanged. Base the preset on the command source's worst bit-to-bit gap; the example pairs 500 ms against a 200 ms worst gap.

On this page
- Why a fixed-interval check accepts an intermediate code
- Latch the previous scan and OR the mismatches
- Qualify the command with a retriggerable stability timer
- Worked example: from 0,0,0 to 0,1,1 with a 200 ms gap
- What the timer proves and what it does not
- Verify the logic before the machine runs
- Questions asked
Don't poll a multi-bit position command at a fixed interval and move on whatever you read. Sample the three inputs every scan against latched copies of their previous-scan states, OR the three mismatches into a single InputChange bit, and keep a stability timer reset for as long as that bit is true. Accept and decode the 3-bit code only after the timer expires with the word unchanged. That replaces a snapshot that happened to look valid with a code that has been quiet for a chosen interval, which is the property a moving mechanism actually needs.
The fixed one-second check fails for a structural reason: all eight three-bit combinations decode to a legal position, so an intermediate code reads as a genuine command. Derive the interval from the command source's worst measured bit-to-bit gap; the worked example below pairs a 500 ms preset with a 200 ms worst gap.
Why a fixed-interval check accepts an intermediate code #
Three command bits produce eight possible codes (2^3 = 8), and a position selector decodes every one of them to a valid target. The decode logic has no way to flag 0,0,1 as a fraction of 0,1,1; to the PLC it is just another valid command. The external source cannot flip two discrete points in the same instant either: the bits change one per event, so the wiring sits at a partial code for the whole gap between the first and second transitions.
A check that runs on a fixed period lands inside that gap whenever its phase happens to coincide with it. If the gap lasts one fifth of the period, one check in five lands inside it, and each landing reads a partial code that the PLC, decoding immediately, turns into a real move to the wrong position. Polling faster or slower only changes that ratio; the partial code exists on the wire no matter when you look. The scan itself is not the culprit: the input image updates once per scan, so a word read at the start of a scan is exactly what was on the terminals at that moment. A blip shorter than one scan is a different failure mode, covered in why a PLC misses short input pulses and how to catch them.
Latch the previous scan and OR the mismatches #
Keep one copy of each input from the previous scan; three retentive BOOL bits are enough. Compare each current input against its copy and OR the three mismatches into one InputChange bit. A single bit catches both directions on all three inputs, so the six possible transition events (three inputs, each ON-to-OFF or OFF-to-ON) need no separate logic.
In ladder that is two contact pairs per input feeding one coil: Input1 normally-open in series with Latched1 normally-closed, alongside Input1 normally-closed in series with Latched1 normally-open, then the same pair for Input2 and Input3. In structured text the detector is one expression plus the latch update:
(* Illustrative names - use your platform's addressing *)
VAR
Input1 : BOOL; (* command bit 0 *)
Input2 : BOOL; (* command bit 1 *)
Input3 : BOOL; (* command bit 2 *)
Latched1 : BOOL := FALSE; (* previous-scan copy of Input1 *)
Latched2 : BOOL := FALSE; (* previous-scan copy of Input2 *)
Latched3 : BOOL := FALSE; (* previous-scan copy of Input3 *)
InputChange : BOOL := FALSE; (* any bit differs from the last scan *)
END_VAR
InputChange := (Input1 <> Latched1)
OR (Input2 <> Latched2)
OR (Input3 <> Latched3);
Latched1 := Input1;
Latched2 := Input2;
Latched3 := Input3;
Execution order is the entire trick: the comparisons must run before the latch assignments. Reversed, current and stored values are equal before you compare them, InputChange stays false forever, and the qualification disappears without any error message.
If the three bits arrive packed inside an input word rather than as discrete points, copy the word to a buffer and compare the buffer against its latched word with a single not-equal test; one instruction replaces all six contact pairs. Bit access inside words has traps of its own, covered in why a WORD bit reference fails in ladder logic and how to fix it.
Qualify the command with a retriggerable stability timer #
The qualifier is one rung. Put a normally-closed InputChange contact in series with a non-retentive on-delay timer (a TON on IEC 61131-3 platforms). While any bit differs from its latch, the rung is false and the timer holds its accumulator at zero. The scan after the word goes quiet, the rung goes true and the timer accumulates; any later transition drops the rung and clears the accumulator again. That single contact does the work of six timer-reset branches:
VAR
StableTimer : TON; (* non-retentive on-delay *)
InputStable : BOOL := FALSE; (* timer done: command qualified *)
StabilityTime : TIME := T#500MS;
END_VAR
StableTimer(IN := NOT InputChange, PT := StabilityTime);
InputStable := StableTimer.Q;
Choose the preset from the command source, not from habit. Measure the worst gap between consecutive bit transitions - a scope across the inputs, or the PLC's timestamped change log, while the source walks through several position changes - and set the preset to at least twice that gap. Twice covers event-to-event jitter; anything below one times the worst gap lets an intermediate code qualify before the next bit arrives. With a measured 200 ms worst gap the minimum is 400 ms, and the example throughout this article uses 500 ms.
Decode on the rising edge of InputStable, never on the level, and never straight from the physical inputs. Copy the three bits into an accepted-command register, weighted 4-2-1 with the top bit heaviest so that 0,1,1 is code 3, position 4 in a one-based table of eight; set a command-accepted bit; and let the motion logic run only from that register. On the first scan, copy the current inputs into the latched copies - nearly every platform exposes a first-scan system bit for exactly this. If the latches begin false instead, any input already ON produces one harmless InputChange at power-up and costs one extra interval before the first acceptance.
Worked example: from 0,0,0 to 0,1,1 with a 200 ms gap #
The mapping weights the bits 4-2-1 with the top bit heaviest, positions numbered code + 1, so 0,0,0 is code 0 = position 1 and the target 0,1,1 is code 3 = position 4. The scan takes 10 ms, the preset is 500 ms, and the source's measured worst gap is 200 ms.
- t = 0 ms: the source raises bit 0. The wire reads 0,0,1 - code 1, position 2, a fully legal code.
- Within one scan the PLC sees it: InputChange is true for that scan, the timer rung drops, and the accumulator clears.
- t = 200 ms: the source raises bit 1. The wire reads 0,1,1. The timer had accumulated roughly 190 ms and throws it away; the rung resets it to zero.
- t = 210 ms: the word is quiet, the timer accumulates undisturbed.
- t = 710 ms: the accumulator reaches the preset. InputStable rises, the decode latches code 3, and the move to position 4 begins.
The arithmetic: acceptance lands at last transition + preset + at most one scan = 200 + 500 + 10 = 710 ms after the first bit moved, and never earlier than 200 + 500 = 700 ms. Under the old fixed check, any poll landing between t = 0 and t = 200 ms reads 0,0,1 and commands position 2; with a 1000 ms period the chance is 200/1000 = 0.20, one change in five. The preset is not decoration: with a 100 ms preset and this same 200 ms gap, the timer expires about 110 ms after the first transition while the wire still reads 0,0,1, and the logic confidently accepts position 2. The interval must exceed the worst gap, and twice the gap leaves room for jitter.
What the timer proves and what it does not #
The timer proves exactly one thing: the observed word did not change for the interval. It does not prove the source finished its update. An intermediate code the source holds longer than the interval qualifies exactly like a finished command, which is why the preset derives from the source's measured behavior and not from the PLC's convenience. Where a wrong intermediate position can damage product or injure someone, treat a data-valid or strobe line from the command source as a requirement and qualify the code with both the stability interval and that signal.
Verify the logic before the machine runs #
- Feed the detector from three test bits instead of the physical inputs, sequenced in logic: test bit 0 set at t, test bit 1 one gap later, test bit 2 off. That reproduces the real skew without moving a wire.
- Watch InputChange during each transition: it must pulse true for exactly one scan, in both directions.
- Watch the timer accumulator: it returns to zero on every pulse and only accumulates while all three test bits are quiet.
- Confirm the accepted-command register never holds position 2 during the sequence and shows position 4 exactly once, after the full interval.
- Check the acceptance edge against the sequence start: at the example scan time and preset it lands between 700 and 720 ms. An earlier edge means the preset is smaller than your test gap or the latch assignments run before the comparison.
- Repeat with the bit order reversed and with a downward sequence (0,1,1 to 0,0,0) to prove both polarities reset the timer.
Hand the motion logic one latched accepted code and nothing else. Confirming that the axis actually reached the accepted position is a separate check; if you make it with counter window comparisons, see why a high-speed counter position jumps between PLC window comparisons. With the preset at twice the measured worst gap and the decode on the stable edge only, an intermediate code never reaches the motion logic.
Questions asked
Can I apply this if the command arrives as one input word instead of three discrete points?
Yes, and the word form is simpler. Move the input word into a buffer each scan, compare the buffer against its latched copy with a single not-equal instruction, and drive the same stability timer from that one result. Update the latch after the comparison, and decode the accepted word on the rising edge of the timer done bit. It scales from three bits to eight or sixteen without adding contact pairs.
How do I set the stability interval if the command source is not documented?
Log the InputChange pulses while the source walks through every position across its full range, note the longest gap between consecutive pulses, and set the preset to at least twice that gap. If even that is not possible, a 500 ms preset is a defensible value for a hardwired parallel command between controllers, but treat it as an assumption and confirm it with the pulse log at commissioning.
The interval expires but the machine still takes a wrong position occasionally. What do I check first?
Log InputChange and the accepted code around a failure. If the timer expires while the word the source intended differs from the word the PLC accepted, the source held a partial code longer than your interval, and no preset value fixes that. The fix is at the interface: use the source's data-valid or strobe line, or add a handshake in which the source holds the command until the PLC returns an acknowledge generated from the accepted-code edge.
Why does my version accept codes immediately, as if the stability check were not there?
Check execution order first. If the latched copies are updated before the comparison runs, stored and current values are always equal, InputChange never goes true, the timer rung never drops and the done bit is true from the first scan, so the rung behaves as if no check existed. Compare first and assign the latches last. The same symptom appears if the timer is a retentive type that never sees its rung go false.

