IMDTouchKnowledge BaseShop main store

Troubleshooting

Why a Retained PLC Setpoint Resets to Zero on the First Scan

HMI and touchscreens Published 6 min read

Short answer

The setpoint is not leaking away; something writes zero over it every scan. Retain only protects the storage location it is set on, so an unconditional MOVE of 0, a non-retained M-memory word feeding the block input, an HMI tag start value or a recipe load wins. Carry operator setpoints in a retained global DB with a typed start value, then clear every other write with a cross-reference sweep.

On this page
  1. Why retention does not save the value
  2. The four writers that put zero back
  3. Move the setpoint into a retained global DB
  4. Sweep the cross-references for every other write
  5. Worked example: the tank setpoint
  6. The decision
  7. Questions asked

A retained setpoint that falls back to 0 was not lost — it was overwritten. Retention protects a storage location; it does nothing against a write that runs every scan. The tank-fill case shows the fingerprint cleanly: the value reads 250 right after the download, then collapses to 0 on the next cycle, so the writer sits in cyclic code, not in the power-down path. Four sources do this: an unconditional MOVE of 0, a non-retained M-memory word feeding a block input, an HMI tag start value pushed at connect, and a recipe load. The fix is to carry operator setpoints in a retained global DB with a typed start value and to remove every other write in a cross-reference sweep.

Why retention does not save the value #

Siemens defines retentive memory as non-volatile storage for a limited quantity of work-memory values, and data marked retentive keeps its content through a power failure, during CPU startup and when a modified program is loaded. Retention is a property of the storage location, nothing more. The retain setting on a block interface entry says nothing about the M-memory tag that feeds it: if the M word sits outside the retentive setup in CPU properties, it comes back as 0 at startup and after a download, and the block copies that 0 onward exactly as it was written to do. Ticking Retain on the input cannot help, because the setpoint never reaches retentive storage in the first place.

The timing separates the two fault families. Correct for one cycle after a download or a STOP-to-RUN transition, then 0: the writer is in the cyclic program, and no retention setting will touch it. Correct until a power cycle, then 0 forever: the carrier itself is not retained, and the carrier is what has to move.

The four writers that put zero back #

Cross-reference the tag before changing anything; every one of these shows up as a write access.

  • An unconditional MOVE of 0 into the carrier word, in OB1 or in any block the every-scan path reaches. Only writes hidden behind a condition — a first-scan bit, an edge, a command — are safe, because scan position decides who writes last.
  • A non-retained M-memory word as the carrier. The retentive setup in CPU properties decides which M bytes survive, and a block input's retain setting does not transfer to the word feeding it.
  • A DB tag with no start value typed in. Retention preserves whatever is stored; if nothing was typed, what is stored is 0, and the tag faithfully retains 0 through every power cycle.
  • The panel side. An HMI tag start value is written into the PLC when the runtime connects, and transferring a recipe writes the recipe entry over the PLC tag, so a tag that belongs to a recipe has one more writer than the program shows.

The panel-side twin of this fault — a numeric entry that writes zero over a preset — is broken down in Why an HMI numeric entry writes zero to a counter preset.

Move the setpoint into a retained global DB #

This is the fix, and the layout to keep for every parameter that follows:

  1. Create one global DB for machine settings — call it DB_Settings in the example — with optimized block access left on.
  2. Declare each setpoint once, with a type and a start value: FillLevelSP as Real, with 250.0 typed into the Start value column. The start value is what the CPU loads when the block initializes, before any operator touches the screen.
  3. Tick the Retain checkbox on the tags that must survive power-off and downloads, and only on those: the retentive budget is 2 KB on an S7-1200, so retention is for setpoints, counters and tuning constants, not for everything.
  4. Repoint every read in OB1, the FBs and the FCs from the M word to the DB tag, and address the HMI numeric field directly on the DB tag. The operator's write becomes the only writer.
  5. Compile, download, then power-cycle the bench. The value must come back at the typed start value with the panel untouched.

Keep M memory for what it is good at — edge bits, step flags, interlocks — and never split one setpoint between an M word and a DB tag. One carrier, one writer. The same pattern keeps HMI-entered timer presets in PLC memory alive across a power cycle, and it scales into UDTs as the parameter set grows. The same split between retention and start values decides this fault on other platforms too; MicroLogix 1400 retaining HMI setpoints across a power cycle is worked through separately.

Sweep the cross-references for every other write #

With the DB in place, prove that no other writer remains:

  1. Open the cross-references for the setpoint tag and list every access. The first write hit is usually the old M-word path.
  2. Classify each write as unconditional or conditional. An unconditional write in cyclic code has to go; a conditional one has to be a write you actually want.
  3. Follow block calls one level up. An FB input left at its interface default contributes that default on every call, so ask what writes the word feeding the input, not only what the input writes.
  4. Check the panel project the same way: the HMI tag's start-value field, and whether the tag is a recipe member whose entry is transferred toward the PLC.

The end state is mechanical: each operator setpoint has exactly one writer — the screen — and everything else in the chain reads.

Worked example: the tank setpoint #

The example machine is an S7-1200 driving a KTP700 Basic panel, with the fill setpoint carried two ways, before and after the fix.

Carrier Retained Start value After download After the first cyclic write After a power cycle
M word feeding the FB input No none 250.0 until the first cycle 0 0
DB_Settings.FillLevelSP, Real Yes 250.0 250.0 250.0 — no writer left 250.0

The declaration, with example names, and the test that proves the bottom row:

// Example names, declared in DB_Settings (optimised global DB)
FillLevelSP : Real := 250.0;   // Start value column, Retain ticked

Download, go online, power-cycle the CPU, then go online again: FillLevelSP must still read the typed start value, and the HMI field must show it without a reconnect. The example DB carries five Real setpoints, so the retentive cost is 5 × 4 = 20 bytes of the 2,048-byte budget, about 1 percent; the same budget holds 2,048 / 2 = 1,024 Int values or 2,048 × 8 = 16,384 Bool flags, which is the arithmetic to run before marking the next tag Retain.

The decision #

Commit it case by case:

  • Setpoint must survive power-off and a modified download: retained global DB tag with a typed start value, M word deleted from the path. Retention on a block input alone never holds.
  • Process wants the default back at every power-up: leave Retain off and keep the typed start value; the CPU reloads the default on each startup by design.
  • Panel must seed a value at connect: leave the HMI tag start value empty, or set it equal to the DB value so the panel never writes over the PLC uninvited.
  • Tag lives in a recipe: the recipe entry is a writer, so give it the same number as the DB or take the tag out of the recipe.
  • Anything else writing the tag every scan: delete it or hide it behind a real condition. One setpoint, one writer — the operator.

One boundary: a retained operator setpoint is not a safety function. A limit that protects people or hardware belongs in safety-rated or hard-wired protection, not in a value a screen can overwrite.

Questions asked

If retention survives a download, why did the value vanish right after one?

Because retention only preserves what already sits in retentive storage. If the setpoint lived in an M word outside the retentive setup, or arrived through a block input fed by that word, the download loaded 0 into the path and retention kept the path intact, not the number. Watch the tag online after a download: correct for exactly one cycle, then 0, means the writer is in cyclic code.

Why did the typed start value disappear even though it was in the DB?

A start value is loaded once, when the block initializes. After that the cyclic program decides the content, so a MOVE of zero or a non-retained feeder word overwrites it on the first cycle. Both halves have to be right: the start value typed into the DB, and every other write removed from the cross-reference list. Retention without removing the writers only preserves the zero.

How much retentive memory does an S7-1200 have?

The retentive budget is 2 KB, or 2,048 bytes. At 4 bytes per Real that is 512 setpoints, at 2 bytes per Int it is 1,024 values, and at 1 bit per Bool it is 16,384 flags. Machine parameters fit comfortably in that. Trend or log data does not, so logging belongs on the CPU's memory card instead.

How do I set the panel side so it never writes over the PLC?

In the HMI tag's properties, leave the start value empty unless the panel genuinely must seed the PLC, and then make it equal to the DB value. Check the tag's recipe membership in the recipe editor: a recipe can read a tag without writing it, and only a transfer toward the PLC overwrites. Any recipe entry that carries a setpoint should match the DB value.

Can the program and the operator both write the setpoint safely?

Yes, if only one of them runs per event. A startup network that seeds the tag once behind a first-scan bit, with the operator writing afterward, does not conflict. Two unconditional writers never work, because the last one in the scan wins every cycle. If the program must clamp the entry, clamp it where the value is used instead of rewriting the tag each scan.

Keep reading

  • Troubleshooting

    PanelView Plus logic module shows question marks on live values

    Question marks on live values while graphics keep working mean the terminal cannot reach the controller, not that the .MER is corrupt. The same runtime running on another logic module proves the application is serviceable. Compare the two modules with the same cable, switch port and runtime, then fix the original's IP settings or its FactoryTalk Linx controller path; replace the module only when its network interface will not link.

    HMI and touchscreens

  • Troubleshooting

    Why HMI point updates run slow on an Ethernet PLC link

    When a screen value updates every 10 s while twin machines update in 0.4 s, run the same read load test on both paths. A slow machine reading 2,500 words/s against 56,000 words/s, with clean link counters, points at the controller: here the installed CPU was a 374 where the project specified a 374+. Verify the physical CPU identity before tuning any scan setting.

    HMI and touchscreens

  • Troubleshooting

    Fixing Data Table Too Small Errors After a PanelView Plus Conversion

    When a converted PanelView Plus application reports a data table too small or missing for every imported tag, the fault is the runtime communication path, not the PLC data files. Set up the runtime shortcut manually after import and give the gateway card and its alias unique IP addresses; in one documented upgrade that single change made the online tag folders appear immediately.

    HMI and touchscreens