Relay Memory and Failed Steps: What It Actually Remembers
In this article
- Background: Where Relay Memory Comes From
- How Relay Memory Works in a PLC
- What "Failed Steps" Means in This Context
- How to Choose the Right Memory Type
- Common Problems and Misconceptions
- Comparing Relay Memory to Other Memory Types
- Cost and Practical Considerations
- Safety: Why Memory Alone Is Not Enough
- Frequently Asked Questions
Relay memory, in the context of programmable logic controllers (PLCs) and industrial automation, does not remember the failed steps themselves; it remembers the last known state of each input, output, and internal relay (coil) at the moment of a power loss or controller fault. When power is restored or the PLC restarts, it uses this stored state to resume operation from the point of interruption, rather than starting from scratch. This is a critical distinction: the memory holds a snapshot of the logic states, not a log of errors or a history of what went wrong.
Background: Where Relay Memory Comes From
Relay memory is a term borrowed from the era of hardwired relay logic, where physical electromechanical relays were used to control machinery. Each relay had a coil and contacts; when the coil was energized, the contacts changed state. If power was lost, the relays would drop out and the system would have to be manually reset to a known safe state. Early PLCs, introduced in the late 1960s, replaced these physical relays with software-based logic, but they kept the same conceptual model: a program scans inputs, executes logic, and sets outputs. To mimic the behavior of a latching relay (one that stays in its last state after the coil is de-energized), PLCs use memory bits that retain their value across power cycles. This is the origin of the term "relay memory" – it is the digital equivalent of a latching relay's mechanical hold.
How Relay Memory Works in a PLC
In a modern PLC, relay memory is implemented as a portion of non-volatile RAM (often backed by a battery or a supercapacitor) or as EEPROM/flash memory. The memory is organized into addressable areas: input image table, output image table, and internal relays (also called markers, flags, or bit memory). During each scan cycle, the PLC reads physical inputs, updates the input image, executes the user program (which reads and writes to internal relays and output coils), and then writes the output image to physical outputs. When a power failure occurs, the PLC saves the current state of these memory areas to non-volatile storage. On restart, it restores that state and resumes scanning. The key is that it does not remember the sequence of steps that led to the failure; it only remembers the final state of each bit. If a step failed because an output did not actuate, the memory will still show that output as "on" if it was commanded on, even though the physical device may not have moved. The PLC has no way of knowing that the step failed – it only knows what it commanded.
What "Failed Steps" Means in This Context
The phrase "failed steps" usually refers to a sequence in a machine cycle (e.g., a robotic arm moving to a position, a conveyor indexing, a valve opening) that did not complete successfully. In a PLC program, such sequences are often implemented using a state machine or a step sequencer, where each step is represented by a bit or an integer value. When a step fails (e.g., a limit switch is not reached within a timeout), the program may jump to an error routine or set an alarm. But the relay memory does not store a history of these failures. It only stores the current step number and the states of all relevant bits at the moment of the failure. So if you power-cycle the machine, the PLC will resume at the failed step, not at the beginning. This can be dangerous if the physical system is not in the state that the memory assumes. For this reason, many PLC programs include a "power-up" routine that checks the actual state of inputs against the stored state and forces a safe reset if there is a mismatch.
How to Choose the Right Memory Type
When selecting a PLC for an application, the type of relay memory is a key consideration. Here are the common options:
- Battery-backed RAM: Fast and unlimited write cycles, but requires a battery to retain data when power is off. If the battery dies, memory is lost.
- EEPROM (electrically erasable programmable read-only memory): Retains data without a battery, but has a limited number of write cycles (typically 100,000 to 1 million). Suitable for data that changes infrequently.
- Flash memory: Similar to EEPROM but written in blocks; also has limited write cycles. Often used for program storage, not for frequent runtime changes.
- Supercapacitor-backed RAM: Retains data for a few days to weeks after power loss, no battery to replace, but not indefinite.
For applications that require frequent writes (e.g., counters, shifting registers), battery-backed RAM is the standard choice. For data that must survive long power outages without battery maintenance, EEPROM or flash is better, but you must manage the write cycles carefully.
Common Problems and Misconceptions
One common misconception is that relay memory acts like a black box that records errors. It does not. Another is that a PLC will always resume where it left off after a power failure. In reality, the behavior depends on the program. If the program does not have a defined power-up routine, the PLC may start scanning from the beginning, but the memory will still contain the old states, which can cause unexpected outputs to energize. This is why safety standards (like IEC 61131-3) recommend that programs include a safe restart procedure. Another issue is memory corruption: if the battery voltage drops too low, the RAM contents can become invalid, leading to unpredictable behavior. Most PLCs have a battery status bit that can be monitored, and some have a checksum to detect corruption.
Comparing Relay Memory to Other Memory Types
In a PLC, there are several memory areas with different purposes:
- Retentive memory: This is the relay memory described above – it retains values across power cycles. It is used for counters, timers (with retentive option), and internal flags that must survive a power loss.
- Non-retentive memory: This memory is cleared on every power-up. It is used for temporary variables and for data that should always start from a known state.
- Program memory: Stores the user program itself, usually in flash or EEPROM. It is not changed during runtime.
- Data memory (registers): Stores numeric values like analog readings, setpoints, and recipe data. Some of this may be retentive, some not, depending on the configuration.
Understanding the difference is crucial: if you want a counter to reset on power-up, you should use non-retentive memory. If you want it to continue where it left off, use retentive memory.
Cost and Practical Considerations
The cost of relay memory is not usually a separate line item – it is built into the PLC. However, the type of memory affects the overall cost. Battery-backed RAM requires a battery that must be replaced periodically (often every 2-5 years), which is a maintenance cost. EEPROM and flash have no battery but may require more expensive hardware to handle wear leveling. For small PLCs, the memory size is often fixed, but for larger systems, you can choose the memory configuration. When planning a project, consider how often the machine will be powered down and whether the retained data is critical. If a machine is rarely turned off, battery-backed RAM is fine. If it is frequently de-energized and must retain data for months, you may want EEPROM.
Safety: Why Memory Alone Is Not Enough
Relying solely on relay memory to resume after a failure can create safety hazards. For example, if a press is mid-cycle and power is lost, the memory might indicate that the press is in the "down" position, but the actual ram may have drifted. Restarting from that state could cause a crash. Therefore, safety-rated PLCs and programs use redundant safety relays or safety PLCs that have dedicated safety memory that is monitored and validated. They also require a manual reset after an emergency stop or power failure. Always follow the machine's safety instructions and never assume that a PLC's memory will protect you from physical misalignment. The memory is a tool, not a safety device.
Frequently Asked Questions
Does relay memory store the exact step that failed?
No. It stores the state of all bits at the moment of failure, which includes the step number if that is part of the logic. But it does not store an error code or a log of the failure. The program can be written to save an error code to a retentive register, but that is separate from the relay memory itself.
What happens if the battery in a PLC dies?
If the battery dies, the contents of battery-backed RAM are lost. When power is restored, the PLC will start with all retentive memory cleared (or with default values), which can cause the machine to behave as if it were a cold start. This can be dangerous if the program assumes memory is retained. Many PLCs have a battery error flag that can be monitored to alert maintenance.
Can I make a PLC forget a failed step?
Yes, you can clear the retentive memory or write a program that resets the step sequencer to a safe state on power-up. This is often done by using a non-retentive step counter or by having a power-up routine that forces the step to zero. The exact method depends on the PLC brand and programming software.
Is relay memory the same as a hard drive?
No. A hard drive or SSD is used for bulk storage of programs and data files. Relay memory is a small, fast, bit-addressable area used for the runtime state of the logic. It is more like the CPU's registers, but with the ability to retain data across power cycles.
How do I know if my PLC has retentive memory?
Check the PLC's manual or programming software. Most PLCs have a designated area for retentive memory (often marked with an "R" or "retain" attribute). You can also test it: set a bit, power off, power on, and see if it is still set. Always refer to the manufacturer's documentation for your specific model.