Resetting a programmable logic controller from a human-machine interface (HMI) is a routine requirement in factory automation: an operator presses a button on a panel, and the controller re-initializes the machine state to a defined starting condition. The intent is rarely to wipe the program or to perform a factory reset of the CPU. In the overwhelming majority of field applications the requirement is to clear running flags, counters, timers, and step-chain markers so the process returns to its initial step while the program, configuration, recipes, and retentive data remain intact. This guide defines the four interpretations of "reset," explains the IEC 61131-3 background for retentive variables, and provides a concrete implementation pattern for Siemens S7-1200 and S7-1500 controllers, with cross-platform notes for Allen-Bradley CompactLogix and Schneider Modicon M340/M580.
1. What "Reset PLC From HMI" Actually Means
Before any code is written, the requirement must be decomposed. "Reset" in PLC vocabulary covers four distinct operations, each with different safety implications and implementation paths. The original poster's question, "reset the PLC program so it starts from the initial stage," almost always means the first row of the table below — a program-variable reset triggered by a user FB call. Understanding why the other three rows exist prevents a maintenance engineer from accidentally wiping a program during production.
| Reset Type | Scope | Trigger | Survives Power Cycle? |
|---|---|---|---|
| Program variable reset (HMI-initiated) | Flags, counters, timers, step markers in work memory | HMI button → user FB call | No for non-retentive; yes for RETAIN unless the FB explicitly clears them |
| Warm restart | Non-retentive data cleared; startup OB executed once | STOP→RUN, power-on | N/A |
| Cold restart / Factory reset | All user program, configuration, and retentive data erased; CPU at factory defaults | MRES button on the CPU, or TIA Portal "Reset to factory settings" | N/A — wipes everything |
| Operating mode change | CPU transitions RUN↔STOP; outputs de-energize per the configured output behavior | HMI "STOP PLC" tag, mode selector | N/A |
2. Prerequisites
- Siemens TIA Portal V17 or later (V19 recommended for S7-1500 CPU firmware 2.9.x and Unified Comfort Panels)
- S7-1200 (CPU 1214C/DC/DC or similar) or S7-1500 (CPU 1515-2 PN or similar)
- HMI panel: SIMATIC Comfort Panel (TP700) or SIMATIC Unified Comfort (MTP700)
- An established HMI-to-PLC connection configured in the HMI device "Connections" editor
- Read/write access to the PLC project in TIA Portal for online debugging
Reference documentation used throughout this guide:
- Siemens Industry Online Support — central portal for manuals, FAQ, and firmware downloads
- SIMATIC S7-1500 product page
- SIMATIC S7-1200 product page
- IEC (International Electrotechnical Commission) — home of IEC 61131 series standards
3. Architecture: Why a Centralized Reset FB Beats Direct Coil Resets
A naïve implementation wires a single HMI tag to the "reset" input of every coil in the program. This breaks at scale: every new coil needs the wiring touched, IEC 61131-3 evaluation-order rules mean a coil reset by the HMI tag is racing against the same tag being set elsewhere in the scan, and the maintenance engineer cannot trace what is being cleared without reading every network. The classic S7-200/300 STL snippet shown in the source thread — A M0.0 / JCN Lab1 / CALL RESET_FC / R M0.0 / Lab1: NOP 0 — illustrates the point: a single rising edge on M0.0 jumps over a reset FC, and the same M0.0 is reset to give an edge on the next press. This pattern is valid for one button, but the moment you have four motors, two conveyors, and a step chain, the FC balloons.
The robust pattern is a single reset function block that owns the initialization of every machine-state variable. The HMI button becomes a single edge-detected input to that FB. This pattern is consistent with the IEC 61131-3 program-organization-unit model and is the standard practice in machine-builder code across all major PLC platforms.
3.1 Program organization units
- OB1 (Main): Cyclic scan; calls the Machine FB and the Reset FB
- FB_Machine (Machine logic): Contains all the coils, step chain, timers; reads from and writes to a shared "machine state" DB
- FB_Reset (Reset routine): Single-purpose FB that zeroes the machine-state DB on a rising edge of the HMI trigger
- DB_MachineState: The global state of the machine (flags, counters, current step, latched alarms)
- DB_Recipe (separate): The active recipe data; never cleared by an HMI reset
4. Step-by-Step Implementation in TIA Portal
4.1 Create the HMI tag
In the HMI device configuration, open HMI tags and create a new tag:
-
Name:
cmd_MachineReset -
PLC connection:
PLC_1(or your CPU connection) - Data type: Bool
-
PLC tag address:
%DB100.DBX0.0(or a symbolic tag in the PLC tag table) - Acquisition mode: Cyclic, 100 ms (adjust to suit scan time)
4.2 Create the matching PLC tag
Inside the S7-1500 project, in DB_ResetInterface, define:
cmd_MachineReset : Bool; // HMI pushbutton, momentary
stat_ResetDone : Bool; // 1-scan acknowledge back to HMI
4.3 Implement the Reset FB in SCL
Create a new function block FB_Reset in SCL (Structured Control Language). SCL is preferred for FB bodies because the symbolic-tag access keeps the code readable:
FUNCTION_BLOCK "FB_Reset"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR
// HMI input
cmd_Trigger : Bool; // Momentary button from HMI
// Edge memory
stat_TriggerPrev : Bool;
stat_RisingEdge : Bool;
// Status output
stat_Active : Bool;
stat_Done : Bool;
// InOut reference to machine state DB
io_State : VARIANT; // typed to DB_MachineState at call site
END_VAR
BEGIN
// Edge detection of HMI button
stat_RisingEdge := cmd_Trigger AND NOT stat_TriggerPrev;
stat_TriggerPrev := cmd_Trigger;
IF stat_RisingEdge THEN
// Clear the non-retentive machine state
"DB_MachineState".Motor1_Running := FALSE;
"DB_MachineState".Motor1_Fault := FALSE;
"DB_MachineState".Motor2_Running := FALSE;
"DB_MachineState".Conveyor_Step := 0;
"DB_MachineState".CycleCounter := 0;
"DB_MachineState".AlarmLatch := FALSE;
// Add every state bit that should be cleared on reset.
// Do NOT touch "DB_Recipe".RecipeNumber — that survives a reset.
stat_Active := TRUE;
stat_Done := TRUE;
ELSE
stat_Active := FALSE;
END_IF;
END_FUNCTION_BLOCK
RETAIN or RETAIN_PERSISTENT in the state DB will keep their values; if the user requirement is to clear those too, they must be explicitly assigned in this FB (for example, "DB_MachineState".PersistedCounter := 0;). See §8 for the IEC 61131-3 retention rules.4.4 Wire the button edge in ladder (alternative)
For engineers who prefer ladder, an equivalent S7-1200/1500 implementation in FBD/LD:
Network 1: HMI button edge detection
| cmd_Trigger (Bool) |
|------|P|-----( stat_RisingEdge )------|
Network 2: Reset call on rising edge
| stat_RisingEdge |
|------||--------------------( CALL FB_Reset )----|
4.5 Configure the HMI button
Drop a Button control on the HMI screen. In the Events tab, configure the button to emulate a physical pushbutton (TRUE only while pressed):
- Open the Button properties → Events
- On the Press event, add the action "SetBit" → tag
cmd_MachineReset - On the Release event, add the action "ResetBit" → tag
cmd_MachineReset - Optionally add a "Confirmation dialog" on the Press event with a 2-second hold-off for safety
The PLC edge-detects the transition and runs the reset FB exactly once per button press, regardless of how long the operator holds the button. This pattern — SetBit on Press, ResetBit on Release — is the standard WinCC event sequence for momentary commands and is documented in the WinCC Engineering V19 help portal under "Configuring buttons and switches."
5. Why Not Just Reset a Single Coil?
The original poster asked for a "reset" of the PLC program. The example given in the source thread — using R M0.0 in S7 STL — clears a single flag. The block-by-block approach is acceptable for a 20-I/O demo machine; it is unmaintainable for a 500-I/O packaging line. A centralized reset FB is the only sustainable pattern when:
- Multiple HMI panels (operator + remote + service) call the same reset
- Recipes must persist but state must clear
- Audit trails must record what was reset, by whom, and when
- Future expansion is expected (new motors, valves, steps)
- Standardization across a fleet of similar machines is a corporate requirement
The HMI-tag-to-coil-reset pattern also collides with the IEC 61131-3 evaluation rule that an FB instance is single-write per scan for a given output coil: a coil reset by the HMI tag in network 50 cannot be re-set by a logic condition in network 100 within the same scan without the programmer explicitly ordering the dependencies. Centralizing the reset in an FB called at a known point in OB1 eliminates this ambiguity.
6. Cross-Platform: Allen-Bradley CompactLogix / ControlLogix
Rockwell's Studio 5000 Logix Designer implements the same pattern with an Add-On Instruction (AOI) rather than an FB. AOIs are the Studio 5000 equivalent of IEC 61131-3 FBs and provide a reusable, parameterized block with encapsulated local tags and a defined I/O interface.
6.1 AOI declaration
AOI Name: AOI_MachineReset
Input: Reset_Trigger (BOOL)
InOut: State (MY_STATE_TAG) // user-defined UDT
Output: Reset_Active (BOOL), Reset_Done (BOOL)
6.2 AOI body (ladder)
Rung 1: Edge memory
[ XIO Reset_TriggerPrev ] [ XIC Reset_Trigger ] ---(OTE Reset_TriggerPrev)
Rung 2: Active and Done flags
[ XIC Reset_Trigger AND XIO Reset_TriggerPrev ] ---(OTE Reset_Active)
---(OTE Reset_Done)
Rung 3: Clear state UDT members
[ XIC Reset_Done ] [ CLR State.Motor1_Running ] [ CLR State.Motor2_Running ]
[ XIC Reset_Done ] [ MOV 0 State.CycleCounter ] [ MOV 0 State.Conveyor_Step ]
Reference: Studio 5000 Logix Designer product page. For AOI syntax and parameter definitions, see the Logix Designer application help under "Add-On Instructions." For retentive tag handling in Logix Designer, see the Logix Designer programming manual under "Tag retention."
7. Cross-Platform: Schneider Modicon M340 / M580
EcoStruxure Control Expert (formerly Unity Pro) uses Derived Function Blocks (DFB) in Structured Text or Ladder. The DFB is the IEC 61131-3 FB equivalent in the Schneider toolchain.
FUNCTION_BLOCK DFB_MachineReset
VAR_INPUT
Reset_Trigger : BOOL;
END_VAR
VAR_INOUT
p_State : ARRAY[0..31] OF BOOL; // machine state bits
p_WordState : ARRAY[0..15] OF INT; // machine state words
END_VAR
VAR
Prev_Trigger : BOOL;
Edge : BOOL;
i : INT;
END_VAR
BEGIN
Edge := Reset_Trigger AND NOT Prev_Trigger;
Prev_Trigger := Reset_Trigger;
IF Edge THEN
FOR i := 0 TO 31 DO p_State[i] := FALSE; END_FOR;
FOR i := 0 TO 15 DO p_WordState[i] := 0; END_FOR;
// Manual clears for any retentive WORDs go here
END_IF;
END_FUNCTION_BLOCK;
Reference: Modicon M340 product range and Modicon M580 product range. For DFB syntax and retentive variable behavior, see the EcoStruxure Control Expert online help under "Derived Function Blocks."
8. IEC 61131-3 Retention and Initialization Rules
The discussion in the source thread asks which clause of IEC 61131-3 covers the HMI-to-PLC reset pattern. The relevant areas of the standard are:
-
Retentive variables: Variables declared
RETAINretain their value across a warm restart. Variables declaredRETAIN_PERSISTENTsurvive a cold restart / power cycle. Both must be explicitly written in the reset FB if the user requirement is to clear them. - Program organization units: Defines FB encapsulation, instance DBs, and the call interface — the reset FB pattern uses this directly.
- Execution model: A single-instance FB with a referenced shared data block is the cleanest way to ensure the cleared values are visible to the calling OB within the same scan.
For Siemens S7-1500, retentive behavior is configured per tag in the optimized DB (the Retain column in the DB editor). For S7-1200, the same applies but with fewer retentive byte areas. Refer to the S7-1200 and S7-1500 system manuals on the Siemens Industry Online Support portal for per-CPU retentive area sizes and online-change behavior.
9. Safety Considerations
Resetting a running machine from an HMI is a safety-relevant operation. The minimum field-proven requirements are:
- Two-step confirmation. A bare "Reset" button press should be inadequate. Use a confirmation dialog or a two-button press pattern on the HMI.
- Permission level. The reset button should be hidden or disabled unless the operator is logged in at the appropriate authority level (e.g., Maintenance). In TIA Portal: User Administration → assign the screen to a function-level that requires the Maintenance role.
- Interlock with running conditions. The reset FB should refuse to execute if any motor is running, or should command a controlled stop first (ramp-down timers) and only then clear the state. Pattern: if any Motor_Running = TRUE → do not reset, raise alarm "Reset blocked — machine running".
- E-stop priority. An active E-stop must always override an HMI reset. The reset FB must check the E-stop flag in its enable path and refuse to clear state if E-stop is active.
- Output behavior during reset. All outputs should fall to a defined safe state (de-energize) the moment the state DB is cleared. If a motor was held on by a latched coil in the state DB, clearing the DB turns it off — but verify this matches your risk assessment; a separately held-on output that does not read the state DB is a residual hazard.
- Audit log. Write a record to the audit log: timestamp, user, before-state hash, reset reason. This is required by 21 CFR Part 11 in pharma and is good practice in any regulated industry.
- Network segmentation. The HMI reset tag should not be writable from outside the operator VLAN. Use the HMI connection's "Write-protection" or a CP 1543-1 firewall rule to restrict the tag to authorized sources.
10. Verification and Testing
After implementation, verify the reset behavior with the following checks before going to a live machine:
-
Watch table test (TIA Portal). Open a watch table, force
cmd_MachineReset = TRUEfor 200 ms, then return to FALSE. Confirm the state DB clears. Check thatstat_Donepulses for one scan. -
HMI simulation. Use TIA Portal's HMI simulation (RT Unified or WinCC Runtime Advanced) to press the button. Verify the visual feedback (color change, message) and that the
stat_Doneis read back into the HMI. - Retentive-variable test. Set a RETAIN tag to a non-zero value, power-cycle the PLC, confirm the tag is still its non-zero value, press reset from HMI, power-cycle again, confirm the tag is now zero (assuming the FB explicitly cleared it).
- Running-machine test. Start the machine, press reset from HMI, confirm the FB raises a "Reset blocked" alarm and does not clear the state.
- E-stop override test. Press E-stop, press reset, confirm the E-stop condition is not cleared by the reset FB.
- Multi-HMI test. Press reset from a second HMI panel; confirm the same FB executes and the state clears consistently.
- Network interruption test. Disconnect the PROFINET cable mid-cycle, reconnect, confirm the HMI re-establishes the connection and the reset tag is back to FALSE.
11. Troubleshooting Matrix
| Symptom | Likely Cause | Diagnostic Step | Corrective Action |
|---|---|---|---|
| Pressing HMI button does nothing | HMI tag not bound to PLC tag; or wrong connection name; or HMI tag address is read-only | WinCC tag diagnostics: status = "Connection Fault"? Tag quality = bad? | Re-check "Connections" in the HMI device; ensure PLC_1 is enabled and the tag address matches the PLC tag; verify the tag is not marked as read-only |
| Button clears state, but state comes back on next scan | Logic upstream re-sets the state on every cycle (e.g., condition is still true) | Cross-reference the state bits; look for unconditional SET in OB1 | Ensure SET conditions reference the rising edge of the input, or guard with state-machine current step |
| Reset works once, then never again | Edge detection memory not updated; or HMI button stuck-on because Release event is missing | Monitor stat_TriggerPrev in watch table; check HMI button Press/Release events |
Verify the HMI button uses SetBit on Press and ResetBit on Release; verify edge memory is updated each scan |
| Retentive data not cleared by reset | RETAIN tag not explicitly written by the reset FB | Watch the RETAIN tag, press reset, watch the same tag | Add explicit assignment in the reset FB: "DB_CycleState".RetentiveCounter := 0;
|
| PLC goes to STOP after reset | Reset FB triggers an illegal operation or an unhandled peripheral access during the first scan | Open PLC diagnostic buffer (Online → Diagnostics → Diagnostic Buffer in TIA Portal) | Guard arithmetic in the reset FB with checks; review the diagnostic event IDs and resolve the underlying cause |
| Reset from one HMI clears state, second HMI still shows old state | Second HMI not reading from the same DB / not subscribed to the state | Check both HMIs' connection list and tag references | Ensure both HMI devices are configured to read from the same PLC connection and the same DB area |
| Reset triggers a peripheral fault on a VFD or remote I/O | Reset clears a "Drive Enable" bit while the drive is in run state | Monitor VFD status word | Sequence the reset: stop drives first (with controlled ramp), wait for feedback "Stopped", then clear state |
| Confirmation dialog appears but pressing OK does nothing | HMI "Click" event not configured; "Change" event used instead | Open button events in HMI editor | Use the "Click" event for confirmation, and the "Press" event for the actual bit write |
| Reset is slow (multiple seconds) to take effect | HMI acquisition cycle too long; or tag poll time is set to 1 s or more | Inspect the HMI connection's cycle time in the HMI device configuration | Reduce the acquisition cycle to 100 ms; ensure the connection is "cyclic operation" not "on-demand" |
| Reset works in TIA simulation but not on the real CPU | Firmware mismatch; or the FB is in a library that was not updated with the latest revision | Compare FB version between simulation and real CPU; check CPU firmware version in online diagnostics | Recompile the project; download all blocks; verify the CPU firmware is on the version specified in the project |
12. Edge Cases and Field Notes
Edge case 1 — Recipe selected vs. recipe running. A common bug: the reset clears the active recipe number. If the requirement is to clear the cycle state but keep the recipe, the reset FB must write only the cycle-state tags and leave the recipe tags untouched. Encapsulate in two DBs: DB_Recipe (never cleared by HMI reset) and DB_CycleState (always cleared).
Edge case 2 — SFC step chain reset. If the program uses SFC (Sequential Function Chart) in Siemens, the "Initialize" transition of the SFC can be triggered by a tag, which is a more native way to reset than zeroing a step counter. See the S7-1500 System Manual on the Siemens support portal for SFC programming.
Edge case 3 — Multiple operators. If two HMI panels exist and two operators press reset within 100 ms, the FB will receive two rising edges 100 ms apart. The first edge clears the state; the second edge clears it again (a no-op). For an extra safety margin, latch the reset with a "ResetInProgress" flag and ignore further triggers until acknowledged.
Edge case 4 — Comfort Panel vs Unified Panel. Comfort Panels use the "SetBitWhilePressed" event pattern; Unified Panels support the same pattern but also expose a tag-based toggle. Refer to the panel-specific WinCC Engineering manual on the Siemens support site under the device's documentation tree.
Edge case 5 — Remote reset via web server. S7-1500 CPUs (firmware 2.6 and later) expose a web server. The reset bit can be made visible on a custom web page; this should be guarded by the same permission level as the HMI button. See the S7-1500 Web Server application manual on the Siemens support portal.
Edge case 6 — Cold restart vs warm restart after a fault. If the CPU has gone to STOP because of a programming error (for example, an OB121 not loaded, or a peripheral access error with no OB122), a "reset from HMI" cannot bring it back to RUN. The HMI button is ignored when the CPU is in STOP. The operator must clear the fault and issue a RUN command. The diagnostic buffer (Online → Diagnostics in TIA Portal) is the first place to look for these event IDs.
Edge case 7 — HMI button works on local panel but not on remote VNC client. The remote client may be a viewer, not a control surface. Verify the runtime instance permits write events from the remote client, and that the HMI project has the "Sm@rtServer" or Unified runtime client connection licensed and active.
13. Related Patterns
The reset FB is one of three closely related initialization patterns in IEC 61131-3 code:
-
First-scan initialization (Siemens: the
"FirstScan"system bit in the system clock memory; CODESYS:__ixFirstRun): Initializes tags to their default values on program start. - Cold-restart / OB100 execution (Siemens S7-1500): Runs once on STOP→RUN transition; can perform deeper initialization than the first-scan bit and can initialize retentive values to defaults if the user does not want them persisted.
- Operator-initiated reset (this guide): Runs only on a deliberate HMI command; clears the cycle state without affecting recipes, configuration, or retentive data unless the FB explicitly clears them.
For most machine-builder code, all three are present: the first-scan initializes defaults, OB100 (or its equivalent) re-initializes on power-up, and the HMI reset clears the cycle state during a running shift. Separating the three concerns avoids the classic bug where a recipe change is wiped on every power-up because the recipe DB is in the first-scan clear list.
What is the difference between a PLC "reset" from HMI and an MRES?
A HMI reset (program variable reset) clears the running machine state in work memory but preserves the loaded program, configuration, recipes, and RETAIN data. An MRES (Memory Reset) is a hardware-button operation on the Siemens CPU that erases the user program, all configuration, and forces the CPU to factory defaults. MRES is used only during commissioning or recovery; it is almost never the correct answer to an operator's "reset" request.
Can the HMI put the PLC into STOP mode?
Yes. Wire an HMI tag to the Siemens "STP" instruction (or use the standard "Stop" operator control in TIA Portal). When the bit is set, the CPU requests a STOP transition, outputs de-energize per the configured output behavior, and the startup OB will run on the next RUN transition. This is a different operation from a variable reset and is typically reserved for maintenance access, and it should be guarded by a permission level.
How do I clear retentive (RETAIN) variables from the HMI?
You must explicitly write the retentive tag in your reset FB, for example "DB_CycleState".RetentiveCounter := 0;. Setting the HMI reset bit alone does not clear RETAIN values because the CPU restores them on every power-up regardless. For a true cold-restart that erases all retentive data, follow the Siemens MRES sequence or issue a "Reset to factory settings" from TIA Portal online.
Why does my HMI button stop working after a power cycle?
The HMI tag is most likely configured as "non-retentive" on the HMI side, or the HMI's connection to the PLC is not being re-established automatically. In TIA Portal, verify the HMI connection has "Establish connection automatically" enabled, and check the HMI's Start Center → Settings → Connection status. A red "Connection Fault" indicator means the HMI is not talking to the PLC.
Can I reset multiple PLCs from one HMI button?
Yes, but each PLC needs its own reset bit and its own reset FB. Wire the HMI button to set the reset bit on every PLC in the network (use separate connections for each PLC, or a multi-cast tag if supported). Each PLC will then run its local reset FB on the rising edge. Add a "ResetAll_Ack" status bit from each PLC to the HMI and only show "Reset complete" when all ACKs are present.
Which clause of IEC 61131-3 covers the HMI-to-PLC reset pattern?
The relevant areas of IEC 61131-3 are the program organization unit model (FBs, instance DBs, the call interface), the retentive variable behavior (RETAIN and RETAIN_PERSISTENT), and the execution model that defines when FBs see updates. The standard does not prescribe a specific "reset from HMI" routine; the pattern is a convention layered on top of those mechanisms and is documented by each manufacturer in their programming manuals.