Overview
Analog sensors such as ultrasonic (sonar) level probes produce a continuous 0-10 V or 4-20 mA signal that changes every scan. To detect a slowly developing fault such as a pump running dry, the controller must remember what the level was, what it is now, and compute a delta. The challenge for a new PLC programmer is not the math, it is the data retention: a regular tag is overwritten every cycle, so the historical value disappears before it can be compared.
This reference documents a working pattern for a Siemens LOGO! 0BA7 (and the mechanically compatible 0BA8 generation) deployed on a submersible pump station. The same architecture ports cleanly to a BRX Do-more, a Keyence KV, or any controller that exposes a retentive memory area, an edge-triggered latch, and a real-time clock. The article covers:
- How a PLC scan overwrites an analog tag and why a "last value" copy is required.
- The Math block's Retentive / Last value parameter and the Min/Max block as the two smallest viable retention primitives.
- Edge-triggered comparison logic that raises a dry-run warning after a configurable negative trend.
- Configuring the LOGO! onboard data log to write the trend to the SD card as CSV for offline post-mortem.
- Cross-platform equivalents on BRX Do-more Designer and a short note on dedicated data loggers.
Problem Definition: Pit Level Trend Monitoring
Application envelope used throughout this article:
- One submersible pump rated for the pit working volume, controlled by a single digital output Q1 of the LOGO!.
- One ultrasonic level transducer, 4-20 mA, wired to AI1 (the 0BA7 base module exposes two analog inputs AI1 and AI2, both 0-10 V or 0-20 mA selectable in the hardware configuration).
- Pit geometry: 2.0 m maximum head, 0.2 m minimum (pump suction inlet).
- Control bands: pump ON at 1.4 m, pump OFF at 0.6 m. The hysteresis prevents short cycling.
- Failure mode to detect: pump continues to run, but the level is not rising inside the expected window. This is the "running dry" signature and it is what destroys the mechanical seal of a submersible pump within minutes.
The required decision is therefore: while the pump is running, is the level rising? If the level is flat or falling for more than T seconds, raise a warning. That decision is impossible to make from a single instantaneous reading. It requires retention of an earlier reading and a delta.
How PLC Memory Overwrites Scan-by-Scan
A LOGO! executes FBD (Function Block Diagram) or LAD (Ladder) networks top-to-bottom, left-to-right, once per cycle. A network that reads AI1 into a Math block output simply overwrites that output each cycle; nothing is preserved between cycles. The same is true of every data type that maps to volatile work memory.
There are three families of memory in a LOGO! 0BA7:
| Memory Class | Symbol in LSC | Retention on Power Cycle | Use Case |
|---|---|---|---|
| Volatile work memory (VW) | Unmarked analog tag | Lost | Calculations, scratch values |
| Retentive flag / marker | M-flag (e.g., M1, M2) | Kept (backed by super-cap on 0BA7, optionally by battery / SD card) | Latched states, accumulated counters |
| Retentive analog | Analog flag AM1..AM8 (0BA7 supports 8 analog markers) | Kept | Stored analog references, last good value, min/max retained across scans |
To retain an analog value the programmer must route it into an analog marker (AM) or a block parameter that supports a last-value (German: "letzter Wert") mode. This is the foundation of every trend and comparison function discussed below.
Retention Primitive 1: Math Block With Last-Value
The LOGO! Math block (BM, "Basic Math" or "Extended Math" depending on firmware) computes one of several arithmetic operations on two analog inputs. It carries a property named Retentivity with three settings:
| Setting | Behavior | Typical Use |
|---|---|---|
| Off | Output = 0 on power-up / STOP-RUN transition. | Calculations that must start clean. |
| On | Output keeps its last computed value forever until next computation. | Step integrators, ramp references, leak integrators. |
| Last value | Output keeps the last input value it saw before the block became disabled or before a fault. The block re-evaluates the expression as soon as the condition is met again. | "Freeze the last good level while the sensor is in fault" - the canonical use for dry-run detection. |
Pattern A: keep the level that existed at the moment the pump last started.
- Wire a positive edge of the pump-run coil (a one-shot from Q1) into the enable input of a Math block configured as
A=BwithA = AI1andB = AM1(analog marker). - Set the block's retentivity to Last value.
- When the rising edge of Q1 occurs, the block samples AI1 and stores it into AM1. AM1 is then frozen until the next rising edge.
- Subtract the current AI1 from AM1 in a second Math block to obtain Delta = AM1 - AI1.
- Pass Delta through a threshold comparator (Analog Threshold block, hysteresis 0.05 m) to raise the warning output if Delta < 0 for longer than T.
That is the smallest possible dry-run detector: two Math blocks, one threshold, one on-delay timer.
Retention Primitive 2: Min/Max Block
The Min/Max block (block ID 044 in LSC) tracks the running minimum and maximum of an analog input across every scan. It exposes three outputs: AI, AMin, AMax. The block has an internal Reset input; while Reset is high, the running min and max track the input; when Reset goes low, AMin and AMax hold their last values.
Pattern B: capture the lowest and highest level that occurred while the pump was running.
- Route AI1 to the Min/Max input.
- Drive the Reset input with the inverted Q1 (pump not running). While the pump is OFF, Reset = 1 and the block continually samples, so the very first scan after the pump turns ON latches the previous pit level into AMin = AMax = AI1.
- The instant the pump starts, Reset drops to 0. AMin and AMax now track AI1 but never decrease below the level seen at start, never increase above the peak reached.
- If the pump is healthy, AMax - AMin (i.e., the drawdown in this topology, or rise in a fill application) should grow by at least 0.10 m within 10 seconds of starting.
- A second Math block computes Gain = AMax - AMin. If
Gain < 0.10 mafter the timer expires, output the dry-run warning.
The Min/Max block is preferred when the level is noisy (ripples from inflow turbulence) because the running max smooths high-frequency spikes and the running min smooths sensor dropout.
Retention Primitive 3: Edge-Triggered Sample-and-Hold
If the application needs a sample taken at a specific elapsed time rather than at a logic event (for example, "remember the level exactly 5.0 seconds after the pump started"), the cleanest construct is a sample-and-hold built from an edge-triggered one-shot and a single Math block configured for retentivity = On:
- One-shot on the rising edge of Q1, 5.0 s pulse width (On-delay + Off-delay, or use the Pulse Generator block).
- Wire AI1 into the input of a Math block
y = x(identity function) with retentivity = On. - Enable the Math block only when the one-shot is high.
- The output of the block is the level that existed during the 5 s window, frozen for as long as retentivity is set and the block is enabled.
This pattern is also how an integration window is built. Replace the identity Math block with a Summing block: Sum = Sum + AI1 * dt. Reset the sum on the rising edge of Q1. The result is the volume that has flowed into the pit while the pump has been running - directly useful for detecting a blocked discharge line.
Implementing the Comparison: Delta + Hysteresis
A dry-run detector must ignore the small oscillations that are always present in a wet well. The recommended comparator cascade is shown in the table below; all values are scaled to engineering units (meters of head) so that the same thresholds apply regardless of transducer span.
| Parameter | Symbol | Typical Value | Meaning |
|---|---|---|---|
| Sample-to-compare delay | T_s | 10.0 s | How long the pump is allowed to draw water before the trend is judged. |
| Required rise | dH | 0.10 m | Minimum level increase that proves the pump is moving water. |
| Hysteresis on the comparator | h | 0.03 m | Prevents flicker when the level hovers near the threshold. |
| On-delay to alarm | T_a | 30.0 s | Operator grace period before the alarm is latched to the HMI. |
| Pump-rated minimum submergence | H_min | 0.20 m | Hard-wired safety - independent dry contact from a float switch in series with the contactor. |
The comparator expression in the LOGO! Analog Threshold block is:
Output = (AMax - AMin) < (dH - h) after T_s has elapsed since the rising edge of Q1.
Two parameters are deliberately redundant: the analog dry-run warning and a mechanical float-switch interlock. The PLC alone is not a safety function. The float switch is the SIL-1 layer; the PLC dry-run detector is the diagnostic and trending layer.
Configuring the LOGO! 0BA7 Data Log
Trend data is only useful if it survives the trip. The 0BA7 base module has a micro-SD slot (Siemens 6ED1057-1AA00-0BA0 card or compatible, FAT16/FAT32, up to 32 GB tested). Configure the data log in LOGO! Soft Comfort (LSC) as follows:
- In the project tree, open Tools > Data Log Profile and create a new profile named
PUMP_TREND. - Add three columns:
Timestamp(real-time clock),AI1_level_m(scaled analog),Q1_run(digital, packed into 0/1). - Set the recording session to Circular with a 60 s sample period. The 0BA7 will buffer up to 2000 records in RAM and flush to the SD card automatically when the buffer is full or when power is lost.
- Map the profile to the LOGO! via Tools > Transfer > Data Log. The transfer writes a
LOG.csvfile in the root of the card. - To export: remove the SD card, open the CSV in Excel, plot the level column with a moving-average filter of 5 samples to suppress the transducer noise floor (typical 0.005 m peak-to-peak on an ultrasonic sensor).
The data log survives a power cycle and is the audit trail that proves whether a pump failure was preceded by a dry-running signature. Treat the SD card as a finite-life consumable: industrial-grade cards rated for at least 100,000 write cycles are mandatory; consumer cards will fail in months.
Sample Ladder / FBD Code
The smallest complete program in FBD notation is reproduced below. The order of evaluation matters: the Min/Max block must be wired before the Q1 contact that resets it so that the rising edge of Q1 captures the level at the moment of switch-on.
Network 1 - Pump start/stop hysteresis:
AI1 (level m) --> [ Analog Threshold On=1.40 Off=0.60 ] --> Q1
Q1 feedback through OR with manual override (I1) for hand mode.
Network 2 - Trend retention (Min/Max):
AI1 --> [ Min/Max block, Reset = NOT Q1 ]
AMax output --> AM1 (analog marker)
AMin output --> AM2 (analog marker)
Network 3 - Sample-after-5s (identity Math, retentive):
Q1 rising edge --> [ On-delay 5.0 s ] --> pulse
pulse * AI1 --> [ Math y=x, retentive=On ] --> AM3
Network 4 - Dry-run warning:
Q1 rising edge --> [ On-delay T_s=10 s ] --> M_flag "ARMED"
ARMED AND ( (AM1 - AM2) < 0.10 ) --> [ On-delay T_a=30 s ] --> Q2 (warning)
Network 5 - Independent safety:
Float-switch input I2 (NC contact) in series with Q1 output driver.
Hardwired. Not implemented in software.
Network 6 - Data log:
Tools > Data Log Profile: Timestamp, AM1, AM2, AM3, Q1, Q2 --> SD card
For structured-text readers used to PLC-5 or ControlLogix, the equivalent RSLogix-style rungs would map the Min/Max to an FFL/FFU pair, the analog markers to F8:1, F8:2, and the threshold to a GRT instruction. The principle is identical.
Cross-Platform: BRX Do-more Designer
The same algorithm on a BRX Do-more uses the STRUCT primitive to bundle the trend data so that the historian reads one contiguous block rather than three individual tags. The Do-more designer allows a single MATH instruction with a LastValue option; it also exposes a built-in MINMAX instruction that writes into two DWord locations. The SD card on a BRX is mounted as a removable drive, and the DTLLOG instruction writes CSV directly without an intermediate transfer step.
| Function | LOGO! 0BA7 block | BRX Do-more instruction | Notes |
|---|---|---|---|
| Retentive sample | Math, retentivity=On | MATH with LastValue option | Do-more can address up to 16 Mbit of retentive user data without a battery. |
| Min/Max tracker | Min/Max (block 044) | MINMAX | Both latch on a Reset input. |
| Trend log | Data Log Profile -> SD | DTLLOG -> SD / USB | Do-more supports Modbus TCP, MQTT and FTP push natively. |
| Edge one-shot | Pulse Generator / edge | ONS / ONS-RST | Equivalent. |
When to Use a Dedicated Data Logger Instead of the PLC
PLCs are general-purpose controllers. They can log analog data, but they should not be the primary long-term historian in a system that is audited against a regulated standard. A dedicated data logger such as the Keyence NR-X series or the Hioki LR8400 brings: 1 MS/s sample rates that are impossible from a 10 Hz LOGO! scan, isolated channels with their own ADC, and storage volumes measured in gigabytes rather than the 32 GB ceiling of an industrial SD card. The right architecture is therefore: PLC for control, data logger for forensics. Wire the same transducer to both. Let the PLC take action; let the logger take the audit trail.
Verification & Commissioning Checklist
- Force Q1 OFF. Verify that AM1 and AM2 (Min/Max outputs) update every scan and equal the current AI1 value.
- Manually command Q1 ON. Verify that the Min/Max block freezes its previous min/max and begins tracking the new range.
- Wait 5 s, read AM3 (delayed sample). It should equal the AI1 value that existed at t=5 s, not the value that exists at the moment of read.
- Power-cycle the LOGO!. Verify that AM1..AM3 are restored (retentive). If they are zero, the retentivity flag is not set on the block.
- Simulate a dry run by clamping the transducer to a constant value. Verify that the warning output asserts after T_s + T_a = 40 s.
- Remove the SD card and confirm the CSV has rows; the most recent row should be no more than 60 s old.
- Validate the float-switch interlock by manually opening the level; the pump contactor must drop out within 100 ms regardless of the PLC state.
Troubleshooting Matrix
| Symptom | Likely Cause | Diagnostic Step | Fix |
|---|---|---|---|
| Dry-run warning never asserts even with constant level | Min/Max Reset is wired active-high but pump is OFF, so the block always resets | Online > Watch table: read AMin and AMax while Q1 is ON | Invert the Reset to NOT Q1
|
| Warning asserts on every pump start | Level has not yet risen 0.10 m within T_s, but the test pump is rated for slower priming | Check transducer span against pump curve | Increase T_s to match worst-case priming time |
| AM1 reads zero after a power cycle | Retentivity was set to "Off" on the Math block | Open block properties in LSC | Change retentivity to "On" or "Last value" |
| CSV on the SD card is empty | Data log profile was not transferred to the LOGO! | Tools > Transfer > Data Log Profile | Re-transfer the profile and reboot |
| False warning during heavy inflow turbulence | Single-sample Min/Max is too jittery | Look at AMax - AMin in the CSV | Add a moving-average block ahead of the Min/Max input, or increase hysteresis h |
| Pump continues to run with the warning asserted | Software dry-run detector wired to an indicator only, not to the contactor | Trace the Q1 rung | Wire the warning output in series with the pump command, AND maintain the hardwired float switch |
Field-Proven Caveats
What is the minimum LOGO! firmware to support analog data retention and SD logging?
Firmware 0BA7 (ES7) or later, paired with LOGO! Soft Comfort 8.x. The 0BA6 and earlier base modules do not expose the data log profile. The 0BA7 supports up to 8 analog markers (AM1..AM8) and a micro-SD card of up to 32 GB formatted FAT16 or FAT32.
How do I stop a Math block from resetting to zero on power-up?
Open the block properties in LSC and set Retentivity to either On (keeps the last computed value) or Last value (keeps the last input value at the moment the block was last enabled). Pair this with the optional LOGO! battery to survive a multi-day power outage.
Can I use a regular contact to reset a pair of counters in a LOGO! program?
Yes, but the reset coil must be wired to a discrete output of the counter block, not in parallel with the count input. In FBD, place the counter's Reset pin on the same network as the contact that you want to issue the reset. The contact must be a digital input or a marker (M-flag) that is true for at least one full scan to be recognized.
Is the LOGO! SD card safe to leave inserted in a vibrating panel?
Use a card with a mechanical lock or, better, an industrial-grade SLC card with a rated operating temperature of -40 to +85 C and vibration tolerance per IEC 60068-2-6. Consumer cards can work loose and corrupt the file system. Always keep a backup of the LOGO! project on the card as LOGO_UPS.bin so that the program can be re-flashed in the field.
How do I export the logged CSV without removing the card?
On the 0BA7 you must remove the card; the 0BA8 and BM (Base Module with Ethernet) variants support FTP push to a server. An alternative is to use the LOGO! Web Server to expose the analog markers as read-only tags, then poll them with a Python script and write a parallel CSV on the engineering workstation. This keeps the audit trail on the workstation and uses the SD card only as a fail-safe.