Limit an HMI INC/DEC button value with PLC ladder logic

6 min read · Published November 11, 2026

An INC/DEC button that writes the V-memory word directly has no range to set. Hand the write to the PLC: the button sets a request bit, ladder takes one edge per press, adds or subtracts the step, clamps at the minimum and maximum, and writes. The rungs, a worked example with a 5-unit step over 0 to 400 units, and the boundary test are below.

An INC/DEC button that writes the V-memory word straight into the PLC has nothing to hold it at the limits when the object carries no minimum and maximum fields. The fix is to stop letting the panel write the value. Retag the button as a request bit and let the ladder do the arithmetic: one edge per press, add or subtract the step, clamp the candidate between the limits, write the word. The panel becomes a keypad and the PLC owns the number. This page shows the handoff, the rungs, a worked example with a 5-unit step over a 0 to 400 range, and the boundary test to run before the machine goes back into production.

Check the button object before you build anything

Open the INC/DEC object's configuration in the HMI project first. If the version on your panel has minimum and maximum fields, set them to the approved limits, test one press past each boundary, and stop here; nothing below is needed. Many small-panel versions of the object offer only the adjustment amount, so the button counts up or down by its configured step with no range check of its own. On those panels the function keys are usually bound to the object as well, so plan the replacement around ordinary screen pushbuttons that set bits and leave the bound keys where they are. If the approved minimum, maximum and step are not written down for your machine, get them written down before you enable adjustment. The logic below is only as good as those three numbers.

Make the PLC the only writer of the word

A clamp rung placed after the write only cleans up afterward: the out-of-range value has already landed in the word, and every rung that executes between the bad write and the clamp reads the bad number. A recipe transfer or a communications write to the same word lands outside the clamp completely. So give the write to the ladder.

Search the program for every instruction that writes the word, and point the HMI's numeric display at the word as a read-only object. If a recipe or a stage needs the value frozen, lock a PLC V-memory value from HMI writes during a stage covers the hold. If your starting point is a typed numeric entry instead of a button, the same clamp applied to entered values is in enforce HMI increment decrement value limits in PLC logic.

What you need

  • The approved minimum, maximum and step size from the machine's operating requirements. The worked example uses 0 and 400 units with a 5-unit step.
  • Two momentary pushbutton objects on the HMI screen, one for increase and one for decrease, each configured to set its own request bit while pressed and clear it on release.
  • The target V-memory word as a 16-bit signed integer, the INT type defined in IEC 61131-3, which holds -32,768 to +32,767. Two more registers hold LOW_LIMIT and HIGH_LIMIT so maintenance can change the range without editing logic.
  • A clamp instruction if your platform has one. LIMIT, MIN and MAX appear across common instruction sets, and a LIMIT-style box performs both boundary compares at once.
  • Online monitoring, so you can watch the word, the candidate and the pulse bits during the boundary test.

Tag names below such as LOW_LIMIT, HIGH_LIMIT, STEP_SIZE, word and candidate stand in for the names your project already uses.

Wire and program it, step by step

  1. Retag the button. Remove the direct-write INC/DEC object and place two momentary pushbuttons, one setting an increase-request bit, one setting a decrease-request bit. Keep them as two separate bits, because one shared bit with a direction flag leaves the ladder guessing when both requests arrive at once.
  2. Add an edge rung for each request bit. A rising-edge (positive-transition) contact drives a one-scan pulse bit. The edge contact is what turns a held press into one event: take a press that holds the bit on for 150 ms against a 10 ms scan cycle and the rung sees it on for about 15 scans in a row, so a plain 'request on, add step' rung would add 15 steps per press. How long the bit really stays on depends on the panel's write rate and your scan time; how many PLC scans an HMI momentary button bit stays on works the count through.
  3. Gate the arithmetic on a healthy word. On the increase pulse, when the word is already between LOW_LIMIT and HIGH_LIMIT, compute candidate = word + STEP_SIZE. On the decrease pulse, compute candidate = word - STEP_SIZE. One candidate register serves both directions. The gate keeps a corrupted word from being adjusted further; the startup rung in step 6 is what recovers it.
  4. Clamp the candidate. If candidate > HIGH_LIMIT, set candidate = HIGH_LIMIT. If candidate < LOW_LIMIT, set candidate = LOW_LIMIT. A LIMIT-style instruction performs both compares in one box on platforms that have it.
  5. Write the word. On each pulse, word = candidate. From here on, no operator-facing object writes the word; this rung is the only path an adjustment can take.
  6. Initialize at startup. On a first-scan bit, write a valid default whenever the word sits outside LOW_LIMIT to HIGH_LIMIT. Give recipe and communications writes the same treatment: route them through the same candidate-and-clamp block, or validate them at startup.

Example: hold a dosing setpoint between 0 and 400 in steps of 5

A pump setting adjusts in 5-unit steps, allowed from 0 to 400 units. LOW_LIMIT holds 0, HIGH_LIMIT holds 400, STEP_SIZE holds 5, and the word is a 16-bit signed integer, so every number in the sequence fits with room to spare.

  • The word reads 390. One press on increase fires one pulse. candidate = 390 + 5 = 395. 395 is not above 400, so the clamp leaves it alone. The write stores 395.
  • A second press: candidate = 395 + 5 = 400. The clamp leaves it, and the word stores 400.
  • A third press: candidate = 400 + 5 = 405. 405 is above 400, so the clamp sets candidate = 400. The pulse and the write both ran, and the word stayed at 400.
  • With the word at 0, one press on decrease: candidate = 0 - 5 = -5. -5 is below 0, so the clamp sets candidate = 0. The word stays at 0.
  • The operator holds the button down for a full second. The request bit stays on the whole time and the edge contact fired once, so the word moved once.

One decision is yours to make. With a range of 0 to 400 and a 5-unit step, every press moves a full step or lands exactly on a boundary, because 400 is an exact multiple of 5. With a range of 0 to 402, a clamp would store 402, a value no full step can reach. Clamp when landing on the limit is valid for the process; hold the word unchanged when values between steps are wrong, a tray count for instance, and treat the press as refused.

Recommendation: build the adjustment as request bit, edge contact, gated arithmetic, clamp, write, with the limits in registers, on any panel whose INC/DEC object carries no range fields. Clamp to the boundary wherever the process accepts landing on the limit; refuse the press only where a value between steps would be wrong.

Check that the clamp holds

Run the test with the machine in a safe state and the word, candidate and pulse bits visible online.

  1. From a mid value, press increase once: the word moves up exactly 5. Press decrease once: down exactly 5.
  2. From 395, press increase twice. After the first press the word reads 400; after the second it still reads 400.
  3. From 0, press decrease: the word stays at 0.
  4. Hold a button down for a full second: one step moves, not a run of them.
  5. Write 405 into the word from the programming tool during setup, cycle power, and confirm the startup rung brings it back inside 0 to 400.
  6. Fire a recipe write to a value inside the range during setup and confirm the screen shows the number the ladder holds.

If any press moves the word past a boundary, the button still has a direct write path to the word; find it and remove it. A corrected number on the screen over an uncorrected word is not a repair.

Questions

Can I keep the INC/DEC button and just clamp the word later in the scan?

You can, and the screen will look right, but the out-of-range value still lands in the word first, and every rung that executes between the write and the clamp reads it. Where the write lands inside the scan is a timing race between the panel and your logic, so you do not control which rungs see the bad number. A recipe or communications write to the same word skips the clamp completely. Route the button through a request bit and let the ladder make the only write.

What happens if the operator keeps pressing increase at the top of the 16-bit range?

In the worked example the clamp holds the word at 400 long before the type limit matters. A word allowed up to +32,767 has a second trap: 32,767 + 5 wraps to -32,764 in a 16-bit signed integer, and a negative candidate passes a greater-than-HIGH_LIMIT test without tripping it. Keep the approved limits well inside -32,768 to +32,767, and gate the arithmetic rung on the word sitting between the limits, as step 3 does.

Can the button apply steps while it is held down?

Yes, if hold-to-repeat suits the job. Keep the request bit and replace the single edge contact with a timer: while the bit is on, fire a pulse every 250 ms and run the same gated arithmetic, clamp and write rungs. At 250 ms the panel applies 4 steps per second, so a 1-second press near a limit lands on the clamp. The boundary test at the end applies unchanged.

Planning information, not legal or engineering advice. Rules differ by place: check codes and permits with your local authority and your licensed trades.

Keep reading

Build your signAsk for a quote