Problem Statement: Counting Potentiometer Revolutions on a Single Analog Input
A single-turn potentiometer driven by a lifting mechanism rotates more than 360° during normal operation. The analog voltage at the wiper only describes the position within one revolution, so a measurement system that records only the analog value loses the absolute height whenever the wiper leaves its 0–10 V window. The engineer needs an incremental revolution counter that uses the same analog input, because the LOGO! 8 base module (BM) does not have free digital inputs for a quadrature encoder or a limit switch.
The implementation strategy in this article derives the direction of motion (clockwise / counter-clockwise) directly from the slope of the analog value, then feeds that direction signal into the LOGO! 8 Up/Down Counter (Vor-/Rückwärtszähler) function block. Every crossing of the analog signal through a configured threshold generates a count pulse; the direction input decides whether the internal counter increments or decrements. The result is a 16-bit revolution counter that can be scaled, exported to the LOGO! web server, and logged to the SD card as a CSV column.
Hardware Requirements
| Item | Specification | Notes |
|---|---|---|
| LOGO! 8 BM | 6ED1052-1MD08-0BA1 (24 VDC, 4 AI) or 6ED1052-1HB08-0BA1 (24 VDC, 4 AI, Ethernet) | Provides AI1–AI4 at 0–10 V, 10-bit resolution (0–1000 normalized) |
| Potentiometer | 10 kΩ linear, 0.5 W or larger | Connected between U+ (24 V) and M, wiper to AI1 |
| LOGO! Soft Comfort | V8.3 or later (V8.4 current) | Required for FS:04 firmware blocks and analog filter FB |
| Power supply | 24 VDC, ≥1 A | LOGO! supplies its own U+ rail for sensor excitation |
| SD card (optional) | microSD, ≤32 GB, FAT32 | For data logging of revolution counter to CSV |
Reference the LOGO! 8 System Manual (entry ID 109751612) for terminal assignments, the LOGO! Soft Comfort V8 Operating Manual (entry ID 109751609) for software block references, and the Siemens LOGO! product page for current catalog numbers and firmware releases.
LOGO! 8 Software Environment
LOGO! Soft Comfort V8.4 is the engineering tool for LOGO! 8 base modules running firmware FS:04 or higher. The function block library used in this article resides in the SF (Special Function) palette:
- SF – Counter: Up/Down Counter (B005 family) with Cnt, Dir, R inputs and a 16-bit internal count value.
- SF – Analog: Analog Threshold Trigger, Analog Comparator, Analog Multiplexer, Math (Add/Sub/Mul/Div), PI Controller, and Analog Filter.
- SF – Edge / Pulse: Edge-triggered flag (Flanke) for one-shot pulse generation on signal transitions.
- SF – Latching: RS / SR latching relays for sticky direction state.
- SF – Timers: Pulse generator (Taktgeber) used to pace the analog sample-and-compare cycle.
The full block reference and parameter dialog structure is described in the LOGO! Soft Comfort V8 manual, chapter 4 (function blocks) and chapter 6 (analog value processing). The diagrams in the remainder of this article follow the LOGO! 8 ladder logic (FBD) representation.
Analog Input Configuration
The potentiometer is wired as a voltage divider between U+ and M, with the wiper connected to AI1. The LOGO! 8 BM models 6ED1052-1MD08-0BA1 and 6ED1052-1HB08-0BA1 accept 0–10 V on AI1–AI4 with reference to M. The internal ADC is 10-bit, so the value at the input of any analog block is a normalized integer 0–1000.
To insert the analog input in LOGO! Soft Comfort:
- Open the programming canvas. From the toolbar, drag the Analog Input block (icon: blue triangle) onto the sheet.
- Double-click the block. In the Block Properties dialog, set Input to
AI1, Type to0–10 V, and assign the block number (default AI1). - Check Enable smoothing if available in the firmware version. The smoothing factor (1–255) controls the depth of an internal moving average; a value of 8–16 is appropriate for a 1 Hz mechanical movement.
The AI1 block output (a virtual analog net) is the source for all subsequent threshold and comparator blocks. Do not assign it to a digital coil – the signal is analog, not Boolean.
Direction Detection Theory
A single analog sample cannot indicate direction; direction is a property of two samples. Specifically, if samplen > samplen-1 the value is rising, if samplen < samplen-1 it is falling, and if equal the value is stationary. The classic textbook solution stores samplen-1 in a memory location and subtracts it from samplen; the sign of the difference gives the direction. PLC-class controllers, including LOGO! 8, do not provide explicit analog memory, so the equivalent effect is built from three primitives:
- A fixed-frequency sampling clock that paces when direction is evaluated.
- A pair of analog threshold triggers with hysteresis that act as 1-bit memory cells encoding the “I was above” / “I was below” history of the most recent threshold crossing.
- An edge evaluator on the threshold outputs that produces a single-shot pulse each time the value crosses a threshold in a particular direction.
For a single-turn 0–10 V potentiometer, configure two overlapping thresholds. Use a 250-unit-wide hysteresis band (default LOGO! setting is 250 / Gain 1), which is large enough to suppress contact noise and small enough to resolve a 1° rotation at the steepest part of the pot taper.
Program Structure
The complete FBD program consists of the following net groups, each labelled with a free marker (M1, M2, …) for diagnostics.
| Net group | Inputs | Outputs | Function |
|---|---|---|---|
| N1: Sample clock | — | M1 (1 Hz pulse) | Pulse generator (Taktgeber) pacing the analog sample |
| N2: Low threshold | AI1 | M2 | Analog threshold trigger, ON=200, OFF=100, Gain=1 |
| N3: High threshold | AI1 | M3 | Analog threshold trigger, ON=800, OFF=700, Gain=1 |
| N4: Rising pulse | M1, M2 (prev), M2 (now) | M4 | Edge-triggered flag on rising edge of M2 |
| N5: Falling pulse | M1, M3 (prev), M3 (now) | M5 | Edge-triggered flag on falling edge of M3 |
| N6: Counter | M4, M5, I1 (Reset) | M6 (16-bit count), AQ-1 | Up/Down Counter, Cnt=M4, Dir=NOT(M5) |
| N7: Scaling | M6 | AQ1 (0–10 V) | Analog multiplexer / Math: count × gain + offset |
| N8: Web export | M6 | VM0 (variable memory) | Move block to expose count in the web server |
The two thresholds are deliberately asymmetric: the rising-edge detector watches the LOW threshold (200/100) because the first event in a CW rotation is the analog value crossing 200 going up. The falling-edge detector watches the HIGH threshold (800/700) because the first event in a CCW rotation is the analog value crossing 800 going down. By separating the two regions, the direction is unambiguous even if the user wiggles the mechanism back and forth through a single threshold.
Step-by-Step Implementation
Step 1 – Build the sampling clock
- Insert a Pulse generator (Taktgeber, B002 family). Set the time base to seconds and the pulse width to 0.1 s. Set the period to 0.5 s (2 Hz sample rate) for a slow lifting application; increase to 0.05 s for fast motion.
- Wire the output of the pulse generator to flag M1. This is your sample tick.
Step 2 – Configure the two analog threshold triggers
- Insert two Analog Threshold Trigger blocks from the SF Analog palette.
- Block A: input = AI1, ON threshold = 200, OFF threshold = 100, Gain = 1. Output → M2.
- Block B: input = AI1, ON threshold = 800, OFF threshold = 700, Gain = 1. Output → M3.
- Enable Retentivity only if the LOGO! is restarted mid-motion; otherwise leave disabled so the thresholds reset on power-up.
Step 3 – Generate the rising pulse (count up)
- Insert an Edge-triggered flag (Flanke, B002 family in the SF – Special category). Input = M2, edge type = rising.
- Wire its output to M4. Each time the analog value crosses 200 going up, M4 fires a single scan pulse.
Step 4 – Generate the falling pulse (count down)
- Insert a second Edge-triggered flag. Input = M3, edge type = falling.
- Wire its output to M5. Each time the analog value crosses 800 going down, M5 fires a single scan pulse.
Step 5 – Wire the Up/Down Counter
- Insert the Up/Down Counter (Vor-/Rückwärtszähler) from SF – Counter.
- Wire M4 to the Cnt input, M5 to the Dir input (or, if you want rising = up and falling = down, wire the inverted M5 to Dir via a NOT block), and I1 (or any free digital input) to R for the reset.
- In the parameter dialog set the On threshold to the maximum revolution count (e.g., 9999 for a 0–9999 rev display) and the Off threshold to 0. Enable Retentivity so the count survives a power cycle.
Step 6 – Expose the count
- Right-click the counter block and assign the internal count value to a Variable Memory address (e.g., VW0). This makes the count available to the web server and to any analog output scaling block.
- To drive a 0–10 V analog output proportional to revolution count, add an Analog Multiplexer or Math block:
AQ1 = count × 0.001(with Gain = 0.001 to map 0–9999 → 0–10 V).
Hysteresis and Noise Rejection
Potentiometer wipers generate Johnson noise and contact resistance variations. Without hysteresis the threshold triggers chatter and the counter increments or decrements falsely at rest. The 100-unit hysteresis band chosen in Step 2 corresponds to roughly 100 mV of analog window, which is comfortably above the LOGO! AI noise floor of ±3 LSB (±3 mV) and well below the desired mechanical resolution of one revolution per 360°.
For high-noise environments (VFD cabinets, unshielded motor cables) add a hardware low-pass filter at the wiper: 10 kΩ in series with 100 nF to M creates a 1.6 ms time constant that attenuates 10 kHz noise by 40 dB without affecting the 1–2 Hz motion. The LOGO! 8 software filter (Enable smoothing = 8) provides a second stage of 8-sample moving average, equivalent to a further 18 dB attenuation at 2 Hz.
| Noise source | Mitigation | Implementation |
|---|---|---|
| Wiper contact resistance | 100-unit hysteresis | Analog Threshold Trigger OFF threshold |
| Conducted EMI on 24 V supply | Hardware RC at wiper | 10 kΩ + 100 nF to M |
| Thermal drift of pot | Software smoothing | AI1 smoothing factor = 8 |
| VFD common-mode noise | Shielded cable, single ground at LOGO! M | Cable shield bonded to PE at one end only |
Up/Down Counter Parameter Reference
| Parameter | Value | Meaning |
|---|---|---|
| On threshold | 9999 | Maximum count; when count reaches this value the Cnt output is set |
| Off threshold | 0 | Minimum count; defines the lower display bound |
| Count direction | Up/Down (Dir input) | Counter increments when Cnt is pulsed and Dir = HIGH; decrements when Dir = LOW |
| Retentivity | Enabled | Preserves count through power loss |
| Trigger edge (Cnt) | Rising | Each rising edge on Cnt increments / decrements once |
The Cnt output of the counter block goes HIGH when the count reaches the On threshold, providing a clean “max reached” signal that can drive an alarm coil or a web-server indicator. The full parameter dialog is documented in LOGO! 8 System Manual, section 4.6.5.
Web Server and CSV Logging Integration
LOGO! 8 BM variants with Ethernet (6ED1052-1HB08-0BA1 and the 6ED1052-2HB08-xBA2) expose a built-in web server on port 80. By assigning the counter’s count value to a Variable Memory location (VW0 in the example), the value can be displayed in a user-defined web page. Use the Tools → Web Page Editor in LOGO! Soft Comfort to drag a “Variable” element onto the page and bind it to VW0.
For CSV data logging, place a FAT32-formatted microSD card in the LOGO! BM slot. The web server then appends a row every second to LOGO_SD.csv in the SD root. The CSV columns include all variable memory locations; the revolution counter (VW0) appears as a numeric column. Refer to the LOGO! Soft Comfort manual, chapter 7.4 (data logging) for SD card sizing and column ordering.
Commissioning and Verification
- Connect the potentiometer to AI1 and power the LOGO! 8. Open LOGO! Soft Comfort and go online (Tools → PC → LOGO! Connection or Ethernet).
- Open the online monitor (View → Online Monitor). Observe M2 toggling when the pot passes the 200-unit threshold and M3 toggling at the 800-unit threshold.
- Manually rotate the pot slowly CW. Verify M4 fires once per crossing of 200 going up and the counter increments by 1.
- Manually rotate the pot slowly CCW. Verify M5 fires once per crossing of 800 going down and the counter decrements by 1.
- Cycle the power. Confirm the count is retained (retentivity enabled).
- Drive the mechanism through 5 full revolutions in each direction and verify the count returns to zero (or to the expected absolute position if the count is offset).
- Open the web server page in a browser (http://<LOGO IP>). Verify the revolution counter updates in real time.
Troubleshooting Matrix
| Symptom | Probable Cause | Diagnostic | Corrective Action |
|---|---|---|---|
| Counter counts only up, never down | Dir input wired incorrectly; M5 not reaching the block | Online monitor: toggle M5 with a forced input; check wiring | Swap Dir input to the appropriate signal or insert a NOT block |
| Counter increments by 2 on each threshold crossing | Edge evaluator not configured; counter triggered on level not edge | Online monitor: M4 pulse width | Set Cnt input to “edge-triggered” in counter parameters |
| Counter chatters at rest | Hysteresis band too small or wiper noise | Watch M2 / M3 in online monitor while pot is still | Increase hysteresis to 200 units; add hardware RC; enable AI smoothing |
| Counter misses revolutions at high speed | Sample clock too slow for mechanical rate | Measure max pot velocity in V/s; compare to threshold band | Shorten pulse generator period; widen threshold band proportionally |
| AI1 always reads 0 | Wiper open or 24 V missing at U+ | Measure voltage at AI1 vs M with a multimeter | Check 24 V supply to top of pot; check wiper continuity |
| Counter resets unexpectedly on power-up | Retentivity not enabled | Open counter block properties | Tick the Retentivity box; transfer program to LOGO! |
| Web page shows “---” for VW0 | Variable memory not assigned to counter output | Check the variable memory assignment in the counter block properties | Assign the count to a VW address; rebuild web project |
Alternate Platform Notes
The same algorithmic structure (sampling clock + dual threshold with hysteresis + edge evaluator + Up/Down counter) maps directly to S7-1200 / S7-1500 in TIA Portal using the IEC counter CTUD with a single boolean pulse derived from a comparator on %IW input words. On Allen-Bradley CompactLogix, the equivalent is a CTUD Add-On Instruction driven by a rising-edge transition bit from a GRT comparison. The LOGO! 8 implementation is unique in that the analog memory problem is solved without explicit storage by using two thresholds as 1-bit “was high / was low” memory cells.
Field-Proven Caveats
- The two-threshold method assumes the analog value is monotonic over the range between the two thresholds. If the pot taper is non-linear (audio-taper, log-taper), the direction can become ambiguous in the flat region of the curve. Use a linear-taper (B-taper) pot for this application.
- Counting on threshold crossings gives a revolution resolution equal to the threshold band size in volts, not in degrees. If the user needs 360°/1024 ≈ 0.35° resolution, they must use a multi-turn pot and accept that one threshold crossing = one sub-revolution.
- For a true multi-turn application where the pot value never wraps (e.g., a 10-turn pot), the same algorithm works directly: the threshold at 500 fires once per turn, and the analog value does not wrap, so the counter tracks net revolutions unambiguously.
FAQ
How does the LOGO! 8 Up/Down Counter count when the Dir input changes mid-pulse?
The Cnt input is edge-evaluated. The count increments if Dir is HIGH at the rising edge of Cnt and decrements if Dir is LOW at the rising edge. The pulse generator (1–2 Hz) is slow enough that the direction signal M5 has settled well before the next Cnt pulse, so there is no race condition in this design.
Can I detect direction with only one analog threshold trigger instead of two?
No. A single threshold output is a Boolean that only tells you “above” or “below” the threshold; it does not encode the sign of the velocity. Two thresholds with hysteresis act as 1-bit analog memory and let you resolve rising vs falling unambiguously. The alternative – a real analog memory – is not available in the LOGO! 8 function block library.
What happens when the analog value stays at 0 or 1000 for an extended period?
If the pot is at the end of its mechanical travel, neither threshold fires and the counter does not change. This is correct behavior – the pot has not crossed a threshold, so no revolution is registered. If the mechanism physically rotates past the pot end-stop, the wiper voltage becomes undefined (floating) and the AI may return a mid-scale value; in that case add an end-of-travel limit switch to protect the pot.
How accurate is the revolution count compared to a hardware quadrature encoder?
A quadrature encoder gives 4 counts per mechanical line pair and resolves a fraction of a degree; this method gives one count per 100 mV of analog window, which is typically 10–30° on a single-turn pot. If sub-30° resolution is required, replace the potentiometer with a multi-turn device (10-turn or 25-turn) and use a single threshold at 50% of full scale – one count then corresponds to exactly 1/10th or 1/25th of the mechanical range.
Can the same program be reused on a LOGO! 8 with current (0/4–20 mA) analog inputs?
Yes. Change the Analog Input block type from 0–10 V to 0/4–20 mA in the block properties and adjust the threshold trigger ON / OFF values accordingly (the normalized 0–1000 scale is the same for voltage and current on the 6ED1052-1Mxx08-xBA1 base module). Use a 500 Ω shunt resistor on the AI terminal if the input is voltage-only.