LOGO! Quadrature Encoder Design for LogSaw Length Measurement

David Krause16 min read
Sensor IntegrationSiemensTechnical Reference
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

1. Problem Statement: DIY Encoder for a Sawmill Carriage

A LogSaw (portable or stationary sawmill) requires accurate measurement of log length as the carriage feeds the log through the bandsaw or chainsaw. The carriage is driven by a crank or by a motor, and the operator needs a digital readout in millimetres that survives vibration, dust, and sawdust. Off-the-shelf draw-wire encoders work, but a low-cost alternative is a wheel rolling along the log or a slotted disc on the carriage axle, sensed by two or three inductive proximity switches feeding a Siemens LOGO! 8 logic module.

Field experience shows that the most common mistakes on this kind of project are:

  • Using three sensors instead of two to "improve" resolution or direction detection.
  • Choosing a controller whose digital inputs cannot sample fast enough for the maximum wheel speed.
  • Omitting a reference sensor, so the counter drifts after power cycling.
  • Forgetting that the LOGO! is a logic relay, not a high-speed counter module.

This reference explains the geometry, the sensor selection, the LOGO! program structure, and the verification steps that make a DIY encoder behave like a real industrial solution.

Read before you build: the LOGO! 8 base module digital inputs I3–I6 (on a LOGO! 12/24RCE or LOGO! 24CE) support high-speed counting up to 5 kHz per the LOGO! 8.1/8.2 system manual. The remaining inputs are limited to 4 Hz. Any encoder design must route the A and B channels to these high-speed inputs, otherwise the counter will skip pulses at modest carriage speeds.

2. Why Three Inductive Sensors Do Not Solve Direction Detection

A common proposal is to mount three sensors around the encoder disc so that one is always triggered while the others change state. In theory this gives more transitions per revolution; in practice the proposal is geometrically wrong for direction detection.

Direction is encoded in the phase relationship between two square-wave signals. To obtain phase, the two signals must be offset by exactly one quarter of a tooth period (90° electrical). Three evenly spaced sensors produce a 120° offset. The firmware can only tell that a tooth has arrived, not which direction the wheel is rotating, because the rising edges of channels A and B occur in the same order regardless of rotation direction.

The failure mode reported on real sawmill builds is consistent: the count is correct during slow manual cranking, but at motor speed the count either over-shoots (both sensors read high simultaneously) or under-shoots (a transition is missed). Resolution does not help; quadrature does.

3. Quadrature Principle: Two Sensors 90° Apart

A quadrature encoder produces two square waves, A and B, where the rising edge of one channel leads the rising edge of the other by 90° (one quarter tooth period). The relative phase tells the controller the direction of rotation:

State Channel A Channel B Direction
S0 0 0 Idle
S1 0 1 Reverse
S2 1 1 Reverse
S3 1 0 Forward
S4 1 0 Forward
S5 1 1 Forward
S6 0 1 Reverse
S7 0 0 Reverse

For a disc with N teeth per revolution, one full mechanical turn produces 4×N edges, so a 30-tooth disc yields 120 counts per turn. If the wheel circumference is 200 mm, one count equals 1.67 mm of log travel; with a 60-tooth disc and a 200 mm wheel the resolution improves to 0.83 mm/count.

A third sensor is only useful as the reference (home / index) pulse, fired once per revolution to reset cumulative drift. That role is covered in section 10.

4. LOGO! Hardware Selection

Siemens currently ships LOGO! 8 with three firmware generations in service: 8.0, 8.1 (FS:01–FS:04), 8.2 (FS:01–FS:04), and 8.3. They differ in high-speed counter capability and number of web clients, but all share the same counter instruction set.

Module Order Number (6ED1 052-) Display High-Speed Inputs Max Count Frequency Notes
LOGO! 12/24RCE 1MD00-0BA8 6ED1 055- I3, I4, I5, I6 5 kHz Relay outputs, 12/24 V supply
LOGO! 24CE 1HB00-0BA8 6ED1 055- I3, I4, I5, I6 5 kHz Solid-state outputs, 24 V supply
LOGO! 230RCE 1FB00-0BA8 6ED1 055- none (mains supply) 4 Hz on all inputs Not suitable for any encoder above ~60 rpm
LOGO! DM8 24R 1BH00-0BA2 none 4 Hz Use only for digital I/O, never for the encoder channels
LOGO! AM2 RTD 1KA00-0BG0 Analogue module, irrelevant for encoders

The full pinout and counter specification is documented in the LOGO! 8 system manual (Siemens Support, entry ID 109751607). Always select the 24 V DC variant (12/24RCE or 24CE) when wiring inductive proximity switches; the 230 V variant cannot accept 24 V sensor signals without external potential isolation.

5. LOGO! High-Speed Counter Limits in Practice

The published limit of 5 kHz on I3–I6 is for a single channel with a 50 % duty cycle. Quadrature uses two channels, but the counter block in LOGO! Soft Comfort only registers the edges, not the phase, so the firmware must sample both channels every cycle. With a LOGO! 8.3 base module the cycle time is 0.6 ms, giving a usable edge rate of approximately 1.6 kHz per channel before edges collide. Translated into carriage speed:

v_max [mm/s] = (f_max [Hz] / 4 / N [teeth]) × C [mm]
            = (1600 / 4 / 30) × 200
            = 2666 mm/s  (≈ 2.7 m/s)

That is well above any human-driven sawmill carriage. For a motorised carriage the speed should be limited by parameter to stay below 1 kHz per channel, i.e. < 1.7 m/s for a 30-tooth / 200 mm wheel. The LOGO! 8.3 product brochure (PDF) confirms the count limit remains 5 kHz per channel on 8.2 and 8.3.

Field caveat: the LOGO! 230RCE and the DM8 expansion module are limited to 4 Hz on every input because their optocouplers are not the high-speed type. Wiring the encoder to those terminals will produce a count that is wildly wrong as soon as the wheel exceeds 1 turn per second. Always verify the printed symbol on the terminal block: high-speed inputs are marked with a small triangle or the suffix /DI in the wiring diagram.

6. Sensor Selection: Inductive Proximity Switches

Two M12 or M18 PNP, normally-open, 10–30 V DC inductive sensors are needed, one for channel A and one for channel B. The encoder disc must be ferrous (mild steel) or carry ferrous targets, not aluminium or stainless.

Vendor Part Number Diameter Sensing Range Switching Freq. Output
SICK IME12-04BPSZW2K M12 4 mm 1000 Hz PNP NO, 3-wire
IFM IF5932 M12 4 mm flush 1500 Hz PNP NO
Pepperl+Fuchs NBB4-12GM50-E2 M12 4 mm 1500 Hz PNP NO
Turck BI4-M12-AP6X M12 4 mm 1000 Hz PNP NO
Balluff BES016A M12 4 mm 1500 Hz PNP NO
Autonics PR12-4DN M12 4 mm 500 Hz NPN NO (avoid with LOGO!)

Switching frequency of the sensor must be at least 4× the maximum edge rate you expect at the wheel. A 1 kHz sensor caps a single channel at 250 edges/second, which is fine for a human cranked carriage at one turn per second, but borderline for a geared motor at 10 turns per second. Choose a 1500 Hz sensor for headroom.

Mount the two sensors on a rigid aluminium bracket so the air gap to the disc targets is constant. A typical target is a 6×6×3 mm mild-steel key glued or screwed into a slot milled in the disc. A target on a non-ferrous disc will not trigger an inductive sensor at all.

7. Encoder Disc Geometry

The disc must satisfy three geometric constraints:

  1. Equal tooth pitch around the full circumference.
  2. Channel A and Channel B targets offset by 90° electrical (i.e. 90°/N of full revolution) so the phase is preserved across the entire disc.
  3. A single reference target per revolution, mechanically positioned so it cannot be confused with a regular tooth.

For a 30-tooth disc the B-channel target sits 3.75° mechanical from the A-channel target (one quarter of 15°). For a 60-tooth disc the offset is 1.875°. The narrower the offset, the more critical the bracket alignment becomes. In practice, a 20-tooth disc with two 5 mm diameter targets at 4.5° offset is the easiest geometry to fabricate on a small lathe.

8. Wiring, Grounding, and EMC in the Sawmill Environment

Sawmills are electrically hostile: variable-frequency drives for the carriage motor, contactors for the saw motor, and chainsaw-style high-frequency vibration. A clean wiring practice is essential or the counter will accumulate phantom counts.

  • Run the three sensor wires (brown 24 V, blue 0 V, black signal) in a shielded 3-conductor cable, e.g. igus chainflex CF Robot or Lapp Ölflex FD.
  • Ground the shield at the LOGO! end only; leave the sensor end floating to avoid ground loops.
  • Keep the encoder cable at least 200 mm away from the VFD output cables.
  • Add a 100 nF X2 capacitor across each sensor's 24 V supply to suppress VFD common-mode noise.
  • Use a dedicated 24 V power supply (e.g. Siemens 6EP1332-1LB10) for the sensors, not the LOGO! internal rail, to keep the high-current saw contactors from sagging the supply.

For sawmills where the saw motor and the carriage motor are controlled from the same cabinet, install a line filter on the VFD (e.g. Schaffner FN3280) and a surge arrester on the 24 V sensor supply. These two parts eliminate the dominant noise paths reported in field service notes.

9. LOGO! Program Structure (FBD)

The program is built from three standard blocks: a high-speed counter, a direction discriminator, and a scaling block.

9.1 High-Speed Counter (Block B003)

Drop a "High-Speed Counter" block from the Special Functions library in LOGO! Soft Comfort. Wire its input to the A-channel sensor (I3 on a LOGO! 12/24RCE). The threshold, hysteresis, and count direction are configured in the block properties:

  • On threshold: use the value you want to trigger the cutoff (e.g. 12 000 for a 2 m log at 0.167 mm/count).
  • Count direction: leave set to "normal". Direction is handled by the B channel.
  • Counter input: I3 (high-speed input).
  • Reset input: I5 (mapped to the reference sensor).

9.2 Direction Detection (XOR of A and previous A)

LOGO! Soft Comfort does not provide a dedicated quadrature decoder, so the direction is derived from the B channel. Wire the B sensor to I4. In FBD, the direction is computed as:

forward  = A_now AND NOT A_prev AND B
        OR NOT A_now AND A_prev AND NOT B
reverse = A_now AND A_prev AND B
        OR NOT A_now AND NOT A_prev AND NOT B

Implement this with a latch for A_prev (use a Set/Reset flip-flop with feedback through a 10 ms on-delay), two AND gates, and one OR gate. The forward and reverse signals control the up/down input of the high-speed counter (when the counter block is set to bidirectional mode in the block properties).

9.3 Scaling to Millimetres

The counter value in pulses is multiplied by a constant. With a 30-tooth disc, a 200 mm wheel, and quadrature, one count equals:

mm_per_pulse = wheel_circumference / (4 × teeth)
             = 200 / (4 × 30)
             = 1.667 mm

Use the "Arithmetic" block (B004) to multiply the counter value by 1667 and divide by 1000. The result is the log length in millimetres, displayed on the LOGO! built-in TDE or on an external text display.

9.4 Sample Program (Ladder Excerpt)

|  I3 (A ch.)  I4 (B ch.)  I5 (Ref)  |
|    |          |           |        |
|    +---[ ]----+---[ ]-----+  B003  |   // High-speed counter, 30 pulses/rev
|    |          |           |  CNT   |
|    |          |           |  RST   |
|    +---[ ]----+---[/]-----+  B004  |   // Direction discriminator
|    |          |           |  ADD   |
|    +---[ ]----+---[ ]-----+  B005  |   // Scaling × 1667 / 1000
|    +--------  B006  ----+ MUL    |
|    +-------------------+ DIV    |
|                          B007  |   // Compare to cutoff, energise relay Q1
|                          CMP   |

This skeleton is provided as illustrative logic; the same logic in FBD uses the "High-Speed Counter" and "Arithmetic" blocks directly. Always validate the compiled program against the actual I/O assignment shown in LOGO! Soft Comfort's "I/O Status" view.

10. Reference / Homing Sensor

Every counter drifts. Battery-backed RAM on the LOGO! 8 retains the value across power cycles, but a brown-out, a sensor glitch, or a manual override can corrupt the count. A single reference sensor firing once per revolution resets the count to a known length (for example, the position of the saw kerf).

Mount the reference sensor so its target is wider than a regular tooth (typically 2× the tooth width) and located 180° away from the A-channel target. The wider target produces a longer pulse that the controller can debounce and use as an unambiguous "home" event. The reference is wired to I5 of the LOGO! and configured as the reset input of the high-speed counter, with an on-delay of 20 ms to filter bounce.

A proven practice is to place the reference target so it fires when the carriage is in its fully retracted position, and to store the corresponding physical length (e.g. 4 200 mm) in a retentive marker (M-flag). After a reset, the controller loads the marker value rather than zero, so the displayed length always matches the carriage physical position even after a power-down.

11. Tolerance, Calibration, and Drift Budget

The achievable accuracy is the sum of several error sources. For a typical 200 mm wheel with a 30-tooth disc and quadrature (120 counts/rev):

Source Magnitude Comment
Quantisation ±0.83 mm ±½ count
Wheel diameter tolerance ±0.5 % ±1.0 mm/m of travel
Wheel slip on log 0–5 mm per cut Eliminate with a knurled wheel and a leaf spring
Sensor air-gap drift (thermal) ±0.3 mm Negligible if sensor is bolted, not glued
Reference sensor alignment ±0.5 mm Set once at commissioning
Cumulative over 4 m log ≤ ±3 mm Worst-case RSS sum

Calibration procedure at commissioning:

  1. Push a calibrated 1 000 mm steel rule against the carriage and the reference fence.
  2. Use the LOGO! TDE to enter "Calibrate" mode.
  3. Move the carriage 1 000 mm while pressing the calibrate input. The controller computes the actual mm/pulse constant and stores it in a retentive variable.
  4. Verify by repeating the test and checking the displayed length matches the rule within ±1 mm.

12. When the LOGO! Is Not Enough: Alternatives

The LOGO! 8.3 is sufficient for a manually or slowly motorised carriage, but becomes a bottleneck when:

  • The carriage must run faster than 1.7 m/s (motorised production saw).
  • The encoder must support 32-bit count and live position display to a SCADA system.
  • You need actual quadrature decoding (A/B/Z) at full 5 V differential (RS-422) levels from a real encoder.

Better alternatives in the same price band:

Controller Quadrature Decoder Max Frequency Cost (2026, list) When to Use
Siemens S7-1200 CPU 1212C + HSC Yes (4×, onboard) 200 kHz ≈ €320 Any production sawmill; integrate with HMI
Siemens ET 200S 1COUNT 24V Yes (PROFIBUS/PROFINET) 1 MHz ≈ €480 Distributed I/O, multi-axis
Beckhoff EK1100 + EL1502 Yes (EtherCAT) 1 MHz ≈ €350 Twincat 3, fast motion
Wago 750-637 Yes (EtherNet/IP, Modbus) 100 kHz ≈ €320 e!COCKPIT, Modicon-style projects
LOGO! 8.3 (this article) No, software-derived 1.6 kHz per channel ≈ €200 Manually driven carriage, prototype

The 750-637 and 750-638 counter modules from Wago are drop-in replacements in many retrofit applications. The S7-1212C's onboard HSC supports all four quadrature modes (1×, 2×, 4×) directly in TIA Portal without software decoding.

13. Commissioning and Verification

Use this checklist at first power-up:

  1. Confirm the LOGO! is firmware 8.1 or higher (menu: LOGO! → Diagnostics → Firmware).
  2. Verify the A and B sensors are wired to I3 and I4 (not I1, I2, I7, I8).
  3. Use the LOGO! TDE "I/O Status" screen to confirm the sensor LEDs toggle when the disc is rotated by hand.
  4. With the disc rotating slowly, observe the counter incrementing by 1 per quarter tooth (4 edges per tooth) and decrementing when reversed.
  5. Trigger the reference sensor and confirm the counter resets to the configured home value.
  6. Push the carriage 1 000 mm and confirm the displayed length matches within ±1 mm.
  7. Run the carriage for 30 minutes under load, then re-check; the count should not have drifted.
Verification trick: temporarily set the LOGO! to 4× quadrature in the HSC block by wiring both A and B edges to the up/down input. If the count is now four times the expected value, your direction logic is wrong. If it matches, the direction logic is correct and you are counting only on A edges.

14. Troubleshooting Matrix

Symptom Likely Cause Action
Count increments correctly but never decrements B channel not wired or wired to a low-speed input Re-wire B to I4; verify on TDE that I4 toggles
Count increments in both directions Direction logic inverted (XOR missing) Swap A and B sensor wiring, or invert the AND/OR pattern in FBD
Count drifts by a few counts per minute EMI from VFD, sensor bounce, or air-gap too large Add shielded cable, 100 nF cap, 20 ms debounce, reduce gap to 2 mm
Count is always a multiple of 4 (only A edges counted) B channel stuck low Check B sensor LED, swap A and B to confirm fault follows the sensor
Count resets randomly during operation Reference sensor firing on tooth instead of wider target Increase target width, add 50 ms on-delay, check bracket alignment
Count is 0 after every power cycle No retentive behaviour on the counter Enable "Retentive" in the HSC block properties, or rely on the reference sensor to re-initialize
Display shows 1.67 mm resolution as 5 mm Scaling block constant wrong Verify mm_per_pulse = 200 / (4 × N); enter as 1667/1000 in the arithmetic block
Count is correct for low speed, wrong for high speed Inputs I1, I2, I7, I8 used; cycle time exceeded Re-wire to I3, I4, I5, I6 (high-speed inputs)

15. Field-Notes Summary

The LOGO! 8.3 is a competent, low-cost logic relay for a manually driven LogSaw carriage. It is not a high-speed motion controller, and trying to make it act like one (with three sensors, fast motor, or long wire runs) is the root cause of the failures reported in practice. Two sensors at 90° electrical offset, wired to the high-speed inputs I3 and I4, decoded by an FBD direction block, scaled by the wheel and tooth geometry, and reset by a wider reference target, give a serviceable encoder for a hobby or prosumer sawmill. The moment a real quadrature decoder is needed, migrate to the S7-1200 HSC or the Wago 750-637/638; the LOGO! has reached its limit.

Can I use three inductive sensors to improve the resolution of my LOGO! encoder?

No. Three evenly spaced sensors at 120° do not produce a phase relationship, so direction detection fails. Use two sensors at exactly 90° electrical offset (¼ of the tooth pitch). The third sensor is useful only as a single-per-revolution reference, not as an extra count channel.

Which LOGO! inputs support the high-speed counter?

On the LOGO! 12/24RCE and 24CE base modules, inputs I3, I4, I5, and I6 support counting up to 5 kHz. All other inputs, including those on a DM8 expansion module and on a 230RCE base module, are limited to 4 Hz. Always wire the A and B channels to I3 and I4 respectively.

How accurate is a DIY LOGO! encoder on a sawmill?

With a 200 mm wheel and a 30-tooth disc decoded in 4× quadrature, expect a worst-case RSS error of about ±3 mm over 4 m of log travel. Calibration against a 1 000 mm steel rule and a knurled wheel that does not slip on the log are the two main levers for improving accuracy.

Do I need a reference sensor on the encoder disc?

Yes, in any application where the counter must survive a power cycle or a brown-out. The reference sensor fires once per revolution and resets the counter to a known physical position (for example, the saw kerf). Use a target that is visibly wider than the regular teeth to avoid false triggers.

When should I replace the LOGO! with a more capable controller?

When the carriage must run faster than ~1.7 m/s, when the encoder must feed a SCADA system over Ethernet, or when an actual 5 V RS-422 differential encoder is being used. The Siemens S7-1200 HSC, the Beckhoff EL1502, and the Wago 750-637/638 are the standard migrations in this class of machine.

Back to blog