Problem Definition
A magnetic level gauge on a process tank produces a continuous 0 to 10 V analog signal proportional to the liquid height. A Siemens LOGO! 8 base module reads this signal on analog input AI1, scales it to engineering units (liters), and writes the result to the on-board display or a connected LOGO! TDE / HMI panel. The engineering requirement is more specific than a simple level display: count only liters added to the tank, ignoring liters removed.
Concrete example from the source application:
- Tank capacity: 1000 L
- Fill cycle 1: +800 L (level rises to 800 L)
- Drain cycle: -500 L (level drops to 300 L)
- Fill cycle 2: +300 L (level rises to 600 L)
- Required 'Total Filled' readout: 800 + 300 = 1100 L
- Forbidden readouts: 600 L (instantaneous level) or 600 L (algebraic sum)
This is a directional integration problem. The PLC must distinguish rising level from falling level, accumulate only the positive increments, and persist the cumulative total across power cycles.
Prerequisites
Hardware
- Siemens LOGO! 8.3 base module with on-board analog inputs. Recommended part numbers: 6ED1052-1MD08-0BA1 (LOGO! 8.3 24 RCE, 8 DI / 4 DO / 4 AI) or 6ED1052-2MD08-0BA1 (LOGO! 8.3 24 RCEo without on-board display). Refer to the LOGO! 8 System Manual on Siemens Support for the full catalog matrix and module compatibility.
- Analog input module if 4 to 20 mA signaling is used instead of 0 to 10 V. Order code 6ED1055-1MA00-0BA2 (LOGO! AM2, two channels, software-selectable 0 to 10 V or 0/4 to 20 mA).
- Battery / retentivity cartridge 6ED1057-1BA00-0BA0 if cumulative total must survive 24 V power loss.
- Magnetic level gauge with 0 to 10 V or 4 to 20 mA transmitter output. Reference designs from ABB Level Measurement describe the float-and-reed-chain transmitter typical of these gauges. Omega Engineering's level measurement overview covers the 4 to 20 mA linearization pattern that most gauge vendors follow.
- 24 VDC power supply rated for the LOGO! base plus the sensor loop (typically 100 to 250 mA combined).
Software
- LOGO! Soft Comfort V8.3 or later (Windows programming environment, free download from Siemens Support).
- Web-based LOGO! Web Editor for online monitoring once the base module is connected to the plant Ethernet.
Signal Inventory
| LOGO! Block | Source | Signal | Range |
|---|---|---|---|
| AI1 (on-board) | Magnetic gauge transmitter | Voltage | 0 to 10 V DC |
| I1 | 'Reset Total Filled' pushbutton, NO | Digital | 24 V |
| I2 | 'Capture Sample' pushbutton, NO | Digital | 24 V |
| Q1 | Optional 'Fill in progress' indicator lamp | Relay / solid-state | 24 V / 0.3 A |
System Architecture
The signal chain is one analog path, three latching math blocks, one comparator, and one accumulator. The drawing below shows how the level signal flows from the sensor through the LOGO! program.
Analog Signal Scaling
The on-board AI inputs of the LOGO! 8 return a raw integer 0 to 1000 representing 0 to 10 V at 10-bit resolution (about 9.77 mV per step). The first block in the program is therefore an Analog Amplifier (B002) that linearizes raw to liters.
| Parameter | Value | Notes |
|---|---|---|
| Sensor range | 0 to 10 V | 4 to 20 mA variant requires AM2 module and offset adjustment |
| Raw AI scaling | 0 to 1000 | LOGO! internal representation, 10-bit |
| Engineering range | 0 to 1000 L | Match the tank chart provided by the gauge vendor |
| Gain (slope) | +1.0 | Set in Analog Amplifier properties |
| Offset | 0 initially | Use offset to trim the empty-tank zero (e.g. sensor reads 0.2 V at empty, enter -20 L offset) |
| Output | 0 to 1000 L | Tag this as LiveLevel_L
|
Net Fill Detection: Three Strategies
There are three common ways to integrate 'liters added' from a single level signal. The trade-off table below guides selection.
| Strategy | Hardware/Blocks | Pros | Cons |
|---|---|---|---|
| Periodic delta (sample-and-hold) | Clock generator, 2 math blocks, 1 comparator, 1 adder | Fully automatic, no operator input | Sensitive to scan timing and noise |
| Fill-cycle bracketing (Capture) | Analog threshold trigger (B004) with hysteresis, 2 math blocks, 1 subtractor | One-shot per fill, easy to audit, deterministic | Requires operator action or threshold tuning |
| Pulse-counted batches | Comparator with offset, up/down counter (B005), multiplier | Simple ladder logic, easy to verify | Loses resolution between pulses |
This article covers the first two strategies, since both rely on the LOGO! math block memory trick the field report proposed. The sample-and-hold approach is fully automatic; the bracketing approach is operator-friendly and easier to validate in regulated environments.
The Math Block Memory Pattern
The discussion's central insight is that a LOGO! Math Instruction block (B001) can be used as a sample-and-hold register when its Enable (En) input is wired to a control signal and the block is configured with the option Keep last value when En = 0. This option is documented in the LOGO! 8 System Manual under 'Math instruction / Retentivity'.
- When En = 1, the block continuously evaluates its expression and the output tracks the inputs in real time.
- When En = 0, the block freezes its most recent output. The frozen value persists through subsequent program execution and through power cycles if the block is flagged Retentive.
- The pattern turns the math block into a one-cell register that can be written by a pulse on En and read by another block via reference.
By chaining three math blocks — one for 'previous level', one for 'current sample' subtractor, one for 'cumulative total' — the program implements the recursive relation Total(n) = Total(n-1) + max(0, Level(n) - Level(n-1)). The max(0, ...) gate is what rejects drain cycles.
Step-by-Step Implementation: Sample-and-Hold Method
- In LOGO! Soft Comfort, open the project and locate AI1 on the on-board input connector. Insert an Analog Amplifier (B002). Set Gain = 1.0, Offset = 0 initially. Name the output tag
LiveLevel_L. - Insert a Clock Generator (B003, pulse-output mode). Set the pulse period to the integration timestep. Use 500 ms for fast fills (over 10 L/s), 2 s for slow fills. Use this same pulse as the master tick for the rest of the program.
- Insert the first Math Instruction block, B001a. Set the function to
A(passthrough). In block properties, tick Retentive and enable Keep last value when En = 0. Wire the En input to the clock pulse from step 2. Wire input A toLiveLevel_L. This block becomesPrevLevel_L. - Insert a second Math Instruction block, B001b. Function =
A - B. Input A =LiveLevel_L, Input B = reference to B001a (PrevLevel). Name this outputDelta_L. The result is signed; the comparator in the next step gates the sign. - Insert an Analog Comparator (B003 — LOGO! Soft Comfort reuses B-numbers across function categories; here it is the Analog Comparator / Threshold Trigger family). Set threshold ON = +0.5 L, threshold OFF = -0.5 L, hysteresis band = 1 L. Wire A =
LiveLevel_L, B = reference to B001a. The outputRisingEdgeis high while level is climbing, low while falling, and holds while the level is stable. - Insert the third Math Instruction block, B001c. Function =
A + B. Input A = reference to B001c's own output (recursive feedback for accumulation), Input B =Delta_L. Tick Retentive and enable Keep last value when En = 0. Wire the En input to the AND ofRisingEdgeand the clock pulse. The outputTotalFilled_Lupdates only when level is rising. - Wire
LiveLevel_L,Delta_L, andTotalFilled_Lto a LOGO! message text block or to the TDE / HMI tag list. Most installations expose three values: current level, current fill-cycle delta, cumulative fill since last reset. - Wire digital input I1 (Reset) through an On-Delay (1.5 s) to debounce accidental presses, then to the retentive-reset of B001c. The total resets to zero only on a deliberate 1.5-second press.
- Compile and download the program to the LOGO!. Use Soft Comfort's Online Test to verify each block's live value while manually lifting the float to known positions on the magnetic gauge.
Step-by-Step Implementation: Capture-Bracketed Method
- Configure the Analog Amplifier and LiveLevel_L tag exactly as in step 1 of the sample-and-hold method.
- Insert Math Block A (B001a) configured as passthrough, Retentive, Keep last value when En = 0. Wire its En to a rising-edge detector on I2 (Capture pushbutton). The output tag is
StartLevel_L. - Insert Math Block B (B001b) configured as passthrough, Retentive, Keep last value when En = 0. Wire its En to the same rising-edge detector on I2 with a one-pulse divider: the first press writes to A, the second press writes to B. The output tag is
EndLevel_L. - Insert Math Block C (B001c) configured as
A - B. Input A = reference to B001b (End), Input B = reference to B001a (Start). Output isFillDelta_Lfor the current cycle. - Insert Math Block D (B001d) configured as
A + B. Input A = reference to B001d's own output, Input B =FillDelta_L. Tick Retentive. The output is the cumulativeTotalFilled_L. - Press I2 once at the start of fill to latch StartLevel_L. Press I2 again at the end of fill to latch EndLevel_L. The cumulative total updates automatically on the second press.
Direction Detection with Hysteresis
A single-bit 'is level rising?' signal must not chatter when the float bobs at a steady level. Use the LOGO! Threshold Trigger with Hysteresis pattern (B004):
- Compute a short-window derivative
dLevel/dtusing two math blocks: current sample at time t, previous sample at time t-2 s, subtract. - Trigger ON when dLevel/dt > +0.2 L/s (tunable per tank); trigger OFF when dLevel/dt < -0.2 L/s.
- Inside the band (between -0.2 and +0.2 L/s), the trigger holds its last state — that is the hysteresis. This prevents pulse-train misfires from surface ripples or pump pulsation.
- For tall tanks with slow fills, widen the band to +/- 0.05 L/s. For agitated tanks with surface waves, narrow the integration window to 5 s and add a moving-average filter.
HMI / Display Integration
The on-board LOGO! display or a connected LOGO! TDE (6ED1055-4MH08-0BA1) can show four useful values via message text blocks:
| Line | Tag | Format | Purpose |
|---|---|---|---|
| 1 | LiveLevel_L | 0000 L | Current tank level |
| 2 | Delta_L | +000 L | Increment in the last sample window |
| 3 | TotalFilled_L | 000000 L | Cumulative fill since last reset |
| 4 | Filling flag | FILL / IDLE | Rising-edge comparator state |
If a full HMI is available, map these tags to numeric display objects and use the comparator output to drive a color change on the level indicator (green while filling, gray while idle).
Verification and Commissioning
- Apply 0 V to AI1. Verify LiveLevel_L reads 0 +/- 1 L. Adjust Analog Amplifier offset if not.
- Apply 5.00 V to AI1 (mid-scale). Verify LiveLevel_L reads 500 +/- 2 L.
- Apply 10.0 V to AI1. Verify LiveLevel_L reads 1000 +/- 2 L.
- With tank stable, press I2 twice with no fill in between. Verify TotalFilled_L does not change (delta = 0).
- Simulate a fill by raising AI1 from 2.0 V to 7.0 V in 1 V steps over 30 seconds. Verify TotalFilled_L increments by approximately 500 L and Delta_L tracks the per-step rise.
- Simulate a drain by lowering AI1 from 7.0 V to 4.0 V. Verify TotalFilled_L does NOT decrease (drain rejected by the comparator gate).
- Power-cycle the LOGO! (24 V off for 10 seconds). Verify TotalFilled_L restores to last value (retentivity confirmed).
- Press I1 for 1.5 s. Verify TotalFilled_L returns to 0.
Troubleshooting Matrix
| Symptom | Likely Cause | Diagnostic | Fix |
|---|---|---|---|
| Total counts negative increments during drain | Comparator wired backwards, RisingEdge flag stuck low | Monitor comparator output in Online Test while draining | Swap A/B inputs of comparator or invert RisingEdge logic |
| Total resets every scan | Retentive flag not set on B001c | Open B001c properties, check 'Retentive' | Tick Retentive, redownload program |
| Total increases during fill but loses value between fills | 'Keep last value when En=0' not enabled | Inspect B001a/B001b properties | Enable the flag on every math block used as memory |
| Total increments in 1000-L jumps on small float movement | Sample rate too slow relative to fill rate; no hysteresis on comparator | Clock generator pulse is > 2 s | Reduce pulse to 200 to 500 ms; widen hysteresis to 1 L |
| Total is zero even though LiveLevel_L is correct | Math block feedback reference points to wrong block | In Online Test, hover each math block to inspect computed value vs. stored reference | Reassign reference to correct block number; recompile |
| Counts drift overnight by tens of liters | Sensor zero drift, or float hysteresis on the magnetic gauge | Empty the tank; read AI1; compare to initial calibration | Re-zero the Analog Amplifier offset |
| Display shows overflow / negative numbers | Total exceeds LOGO! 16-bit signed integer range (+/- 32 767) | Monitor TotalFilled_L for value > 32 000 | Insert a /10 scaling block and add a decimal point (display in 0.1 L units), or move to S7-1200 |
Performance and Resource Notes
The LOGO! 8.3 base module supports up to 400 function blocks per program. The implementation described here uses 8 blocks (1 amplifier, 1 clock, 3 math, 1 comparator, 1 on-delay, 1 message text) — well within limits. Scan time on a 6ED1052-1MD08-0BA1 is approximately 8 ms with this block count; for fills above 100 L/s consider the LOGO! 8.4 platform or migration to a S7-1200 CPU 1212C for higher analog scan rates.
Field-Commissioning Checklist
- Confirm shield grounding at the LOGO! end only; sensor-end shield isolated.
- Use twisted-pair shielded cable, less than 30 m to AI1 on-board; for longer runs, use the AM2 module at the panel.
- Calibrate at three points: empty, half, full. Record AI raw value, scaled L value, and trim offset.
- Set the LOGO! real-time clock (if equipped with the battery option) so retentive data is timestamped by SCADA / HMI.
- Document the empty-to-full tank chart from the gauge vendor and store it with the program file.
- Verify the 'Capture' pushbutton wiring is fail-safe (NC contact or guarded routing) so a broken wire does not silently latch a stale level.
FAQ
Why does my total jump to the full tank level on the first fill?
The 'Keep last value when En=0' flag is not enabled on the previous-level math block, so it returns 0 while idle and the first fill computes Delta = LiveLevel - 0 = full tank. Enable the flag in B001a properties and redownload.
Can I use a 4 to 20 mA sensor instead of 0 to 10 V?
Yes. Add the LOGO! AM2 module (6ED1055-1MA00-0BA2) and select the 4 to 20 mA mode. The Analog Amplifier must then use Gain = (tank capacity L) / (1000 raw units) and Offset = -(0.2 x tank capacity L) to map 4 mA = empty and 20 mA = full.
How accurate is the total compared to a flowmeter?
Typical accuracy is +/- 1 to 2 percent of tank capacity, limited by the 10-bit ADC (about 0.1 percent of full scale) and any non-linearity in the magnetic gauge reed chain. For custody-transfer applications use a calibrated flowmeter and treat the LOGO! total as a check, not a fiscal measurement.
Does the total survive a power outage?
Only if the cumulative math block (B001c) is flagged Retentive and the LOGO! 8.3 base retains its retentive memory on power-down. This requires either the battery cartridge (6ED1057-1BA00-0BA0) or the supercap-backed variant. Without backup the retentive flags are ignored on cold start.
Can I scale to milliliters for small tanks?
The LOGO! 16-bit integer math saturates at 32 767. For a 1000 L tank scaled to 0.1 L resolution the total would overflow at 3276.7 L. Either scale to whole liters, use the LOGO!'s 32-bit analog arithmetic where supported, or move to a S7-1200 for finer resolution.