Wiring an Open-Collector Encoder to a Siemens Digital Input

David Krause14 min read
S7-300SiemensTutorial / How-to
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

Overview

This reference describes how to interface a 64 pulse-per-revolution (PPR) incremental rotary encoder with an open-collector (NPN, voltage-sink) output stage to a Siemens SIMATIC S7-300 digital input module. The application runs at a maximum of 40 RPM, producing a 22 ms pulse period and approximately 11.7 ms semiperiod at the output. We cover the required external pull-up resistor, the input-filter timing budget of the SM 321 digital input, A/B quadrature decoding in the PLC program, and the conditions under which a dedicated Siemens counter module such as the FM350-2 becomes mandatory. The wiring principles also apply to ET 200M stations and S7-400 systems using the same SM 321 module family.

Working pulse rate at the rated speed:

f_pulse = (RPM × PPR) / 60 = (40 × 64) / 60 = 42.67 Hz T_period = 1 / f_pulse = 23.4 ms T_semiperiod = T_period / 2 = 11.7 ms (at 50% duty cycle)

Encoder Signal Characteristics

The specified encoder is a 64 PPR incremental rotary encoder with an open-collector output stage. Open-collector outputs do not source current; the output transistor only pulls the line to ground when active and floats (high impedance) when inactive. Without a pull-up resistor, the PLC input reads an undefined voltage and produces erratic counts. A pull-up must be wired between each signal line (A, and optionally B) and the positive supply rail (24 V DC in this case).

Parameter Typical value
Pulses per revolution 64
Mechanical speed (application) 40 RPM
Output type Open collector / NPN (voltage sink)
Supply voltage 10-30 V DC
Maximum sink current 20-40 mA
Output saturation V_OL ≤ 0.6 V at rated sink current
Output leakage current ≤ 10 µA (output off)
Channels A, B (90° electrical offset), Z index optional

The 90° electrical offset between channels A and B enables quadrature decoding and direction discrimination. Most industrial 24 V SM 321 modules source current into the input (Type 1 / Type 3 per IEC 61131-2), which means a PNP (sourcing) encoder could be wired directly without modification; an NPN (sinking) encoder like the one in this application always requires a pull-up.

Prerequisites

  • Siemens SIMATIC S7-300 (or ET 200M / S7-400) station with an SM 321 digital input module — for example 6ES7321-1BH02-0AA0 (16 DI, 24 V DC, hardware-selectable input filter) or 6ES7321-1BL00-0AA0 (32 DI, 24 V DC, fixed filter).
  • 24 V DC encoder supply derived from the same power supply feeding the rated voltage of the SM 321 module (common 0 V reference required between the encoder and the input module).
  • Two 1.47 kΩ resistors (1/4 W minimum, 1% or 5% tolerance) — one per channel used (A and B).
  • Free digital inputs on a module with the required scan/filter capability, and a common ground reference.
  • Shielded twisted-pair cable (e.g., LiYCY 2×0.34 mm²) with shield grounding hardware.
  • STEP 7 V5.x or TIA Portal project with the PLC station hardware configured and online to the CPU.

Pull-Up Resistor Sizing

The 1.47 kΩ pull-up value recommended for 24 V open-collector encoders balances three requirements:

  1. Adequate sink current for clean saturation of the open-collector transistor. Most 24 V encoder outputs specify a minimum sink current of 10 mA to guarantee V_OL ≤ 0.4 V. At 1.47 kΩ the sink current is 24 V / 1470 Ω ≈ 16.3 mA, comfortably above the typical 10 mA minimum.
  2. Limited steady-state current in the active (output on) state. 16.3 mA is well within the 20-40 mA rating of typical 24 V open-collector encoder outputs.
  3. Acceptable RC time constant when combined with cable capacitance. For a 20 m run of shielded twisted pair at roughly 100 pF/m, the cable capacitance is about 2 nF. τ = R × C = 1470 Ω × 2 nF ≈ 2.94 µs, which is negligible compared with the 11.7 ms semiperiod.
Pull-up R (Ω) Sink current (mA) V_OL (typ) Rise time at 2 nF Recommended use
470 51.1 0.3 V 0.94 µs High noise immunity, short cables — exceeds typical 40 mA sink rating
1000 24.0 0.4 V 2.0 µs General purpose, short to medium cables
1470 16.3 0.5 V 2.94 µs Recommended for 24 V open-collector on SM 321
2200 10.9 0.6 V 4.4 µs Long cables, low-current encoders — verify minimum sink current spec
4700 5.1 1.0 V+ 9.4 µs Not recommended: V_OL may exceed the SM 321 V_IL threshold margin
Note: The SM 321 digital input threshold for a 24 V module is V_IL ≤ 5 V (logic low) and V_IH ≥ 15 V (logic high). The pull-up must guarantee that the off-state voltage clears V_IH with margin; the on-state voltage must clear V_IL with margin. A 1.47 kΩ pull-up from each output to +24 V DC satisfies both conditions with at least 10 V of noise margin on each side.

Wiring Procedure

  1. Confirm the encoder data sheet specifies an open-collector (NPN) output. If the encoder is PNP (sourcing), no pull-up is required; Siemens SM 321 24 V inputs source current and read PNP outputs directly.
  2. Connect the encoder's V+ terminal to the 24 V DC supply rail that also feeds the SM 321 input module.
  3. Connect the encoder's GND terminal to the same 24 V DC common (M) terminal used by the SM 321 module. Common ground is mandatory — separate supplies require a dedicated common reference.
  4. Connect one end of a 1.47 kΩ resistor to the encoder's A output terminal.
  5. Connect the other end of the same resistor to +24 V DC.
  6. Wire the encoder's A output (the resistor-output junction) to the SM 321 input terminal (e.g., I0.0). The PLC input "sees" the resistor-output node.
  7. Repeat steps 4-6 for channel B if quadrature decoding is required.
  8. Terminate the cable shield at one end only — typically the cabinet-side shield ground bar near the SM 321 module. Do not terminate the shield at the encoder end unless the encoder housing is itself bonded to cabinet ground.
  9. Verify wiring with a multimeter before applying power: confirm continuity from V+ to encoder supply, GND to encoder supply M, and A/B outputs isolated from V+ and GND when the encoder is unpowered.
  10. Apply 24 V DC. Measure the voltage on the A output with a DMM — should read approximately 24 V when the output transistor is off and approximately 0.3-0.6 V when the encoder mark is opposite the sensor.

SM 321 Filter Configuration and Pulse Timing Budget

On SM 321 modules with hardware-selectable filters (1BH02 family), the filter is set by a rotary switch on the rear of the module. For S7-300 module specifications and input-delay curves refer to the SIMATIC S7-300 Automation System Manual (ST70), chapter 4.

Module Order number Input delay (typ) Configurable filter Max pulse frequency (50% duty)
SM 321-1BH02 6ES7321-1BH02-0AA0 1.2-4.7 ms 0.5 / 3 / 15 ms (hardware selector) 1 kHz / 166 Hz / 33 Hz
SM 321-1BL00 6ES7321-1BL00-0AA0 1.2 ms (typ) None (fixed) ~400 Hz
SM 321-1CH00 6ES7321-1CH00-0AA0 0.1 ms (typ) None (fixed, fast) ~5 kHz
SM 321-1FH00 6ES7321-1FH00-0AA0 0.05 ms (typ) None (fixed, very fast) ~10 kHz

Switch position mapping on the 1BH02:

Switch position Filter time Maximum frequency Use case
A 0.5 ms 1 kHz High-speed counters, fast interrupts
B 3 ms (standard) 166 Hz General-purpose digital inputs (default)
C 15 ms 33 Hz Noise-immune contact debounce, relay inputs

For 42.67 Hz operation, switch position B (3 ms filter) is the correct choice. Position A also works but provides no noise benefit. Position C must not be used — it suppresses every legitimate pulse.

Even with the input filter correctly configured, the PLC program cycle can still miss pulses. In an S7-300, OB1 scan time is typically 5-15 ms. If the scan time approaches 11.7 ms, polled counting becomes unreliable. Three reliable alternatives:

  1. Hardware counter module (FM350-2 or ET 200S 1Count) — counter runs in hardware, no scan-time dependency.
  2. Edge-interrupt inputs (e.g., SM 321-7BH01 with interrupt capability) — the encoder triggers hardware interrupt on each transition, OB40 executes immediately.
  3. Fast cyclic interrupt OB (OB35 at ≤ 5 ms) — sample A and B inputs faster than the pulse semiperiod.

Quadrature Decoding with Two Digital Inputs

A single digital input only counts pulse edges; it cannot distinguish direction and cannot reject noise-induced transitions. Wiring both A and B channels to two digital inputs enables quadrature decoding in the PLC program:

  • A leads B by 90° (A rising edge while B is low): increment counter (forward direction).
  • B leads A by 90° (A rising edge while B is high): decrement counter (reverse direction).

Quadrature decoding also provides 4× resolution: a 64 PPR encoder becomes 256 counts per revolution in 4× mode. Implementation in STEP 7 SCL, called from a fast cyclic OB:

// Quadrature counter — call from OB35 (≤ 5 ms)
IF "DI_A" AND NOT "DI_A_prev" THEN      // rising edge on A
    IF "DI_B" = FALSE THEN              // A leads B → forward
        "Position_count" := "Position_count" + 1;
    ELSE                                 // B leads A → reverse
        "Position_count" := "Position_count" - 1;
    END_IF;
END_IF;
"DI_A_prev" := "DI_A";
Critical limitation: OB35 at 10 ms cannot reliably decode 11.7 ms semiperiod transitions — some transitions will be missed. Use OB35 at ≤ 5 ms, an edge-interrupt OB, or — preferably — a hardware counter module.

Counter Module Alternatives

When the application requires reliable counting, direction discrimination, or noise immunity, a dedicated Siemens counter module is the correct choice. The FM350-2 counter module manual and the FM350-2 configuration package cover parameter assignment, hardware configuration, and example projects.

Module Order number Channels Max frequency Quadrature Use case
FM350-2 6ES7350-2AH01-0AE0 8 10 MHz 1×, 2×, 4× S7-300 high-speed counting, motion-related positioning
FM350-1 6ES7350-1AH03-0AE0 1 500 kHz 1×, 2×, 4× Single-axis fast counting on S7-300
ET 200S 1Count 24V/100kHz 6ES7138-4DA04-0AB0 1 100 kHz 1×, 2×, 4× Distributed I/O, 24 V encoder input
ET 200S 1Count 5V/500kHz 6ES7138-4DE02-0AB0 1 500 kHz 1×, 2×, 4× Distributed I/O, TTL (5 V) encoder input

Use a counter module when any of the following apply:

  • Pulse frequency exceeds the ratio of digital-input filter time to OB cycle time.
  • Quadrature decoding with direction discrimination is required.
  • Vibration may generate spurious pulses that software filtering cannot reliably reject.
  • Measurement accuracy and repeatability are critical (the FM350-2 and 1Count modules integrate hardware chatter suppression).

Vibration and Noise Considerations

If the driven machine can come to rest with the encoder positioned near a transition threshold (e.g., adjacent to a ferromagnetic tooth or with the optical disk partially covering the photodetector), vibration can cause the encoder output to oscillate between high and low states while mechanically stationary. A digital input will count each transition, causing the position register to drift while the system is stopped. This is a well-documented field problem for conveyors and indexing tables driven by adjacent vibrating equipment.

Mitigation strategies, in priority order:

  1. Use a counter module with built-in chatter suppression. The FM350-2 and ET 200S 1Count include configurable minimum pulse-width parameters that reject transitions shorter than a defined time window (typically 0.1-100 ms).
  2. Implement A/B quadrature validation in software. Only count when both A and B transition in the expected sequence within a defined time window; reject sequences that violate the quadrature state machine.
  3. Apply a velocity gate. If the time since the last legitimate pulse is shorter than the minimum semiperiod expected for the actual speed range, discard the pulse.
  4. Mechanically isolate the encoder from vibration sources with a flexible coupling, vibration-damping mount, or rubber isolator.
  5. Use a Schmitt-trigger input with hysteresis to reject noise near the switching threshold.

Verification Procedure and Distance Calculation

  1. With power off, verify all wiring against the schematic: V+, GND, A, B (if used), shield.
  2. Apply 24 V DC. Measure voltage at the SM 321 input terminal for channel A — should read approximately 24 V when the output transistor is off and approximately 0.5 V when on.
  3. Open a STEP 7 / TIA Portal watch table online with the CPU in RUN. Force the input address (e.g., I0.0) to be monitored.
  4. Manually rotate the encoder shaft one full revolution. The input should toggle 64 times on channel A. In 4× quadrature (A and B), the counter should advance by 256 counts.
  5. Spin the encoder at the rated 40 RPM and verify the count rate: 42.67 Hz on channel A (one transition every 23.4 ms).
  6. Stop the encoder. Observe the count for 60 seconds — should remain stable (no vibration-induced false counts).
  7. Reverse the rotation direction. In quadrature mode, the counter should decrement; the direction bit should toggle.
  8. Run a full operating cycle and verify the calculated distance matches the expected travel.

Distance calculation from the pulse count:

distance_per_pulse = π × D_wheel / PPR total_distance = pulse_count × distance_per_pulse

Example: a 100 mm diameter wheel with a 64 PPR encoder gives distance_per_pulse ≈ 4.91 mm. After 1000 counts, total distance ≈ 4.91 m. In 4× quadrature, distance_per_pulse = π × D_wheel / 256 ≈ 1.23 mm per count.

Troubleshooting Matrix

Symptom Probable cause Diagnosis Corrective action
No pulses counted at all Open-collector output not pulled up; PLC input floating Measure voltage on A output with DMM (should toggle 0-24 V) Install 1.47 kΩ pull-up from A to +24 V
Pulses count but position drifts at standstill Vibration-induced chattering Monitor count with encoder stationary; observe drift rate Use FM350-2 or 1Count with chatter suppression; mechanically isolate encoder
Counter sees half the expected count Only counting one edge of pulse train (rising only) Check program logic for edge detection Switch to edge-interrupt mode, or use counter module with both-edge evaluation
Counter sees double the expected count Switch bounce on input (no filter) View raw input signal on oscilloscope Configure input filter to 3 ms; use SM 321-1BH02
Counter increments but direction is wrong A and B channels swapped or wiring crossed Swap A and B connections; observe direction Reconnect A and B per encoder data sheet
Input reads ON even when encoder is stopped Pull-up not connected; input floating high Measure voltage on input terminal Install pull-up resistor
Input reads OFF even with encoder powered Pull-down mistakenly installed; output shorted to 0 V Verify resistor placement Remove pull-down; install pull-up to +24 V
Counts jitter when motor accelerates / decelerates PLC scan time misses pulses near max frequency Check OB1 scan time vs. pulse semiperiod Use FM350-2 counter module; use cyclic interrupt OB at ≤ 5 ms
Counts correctly but direction bit always indicates forward B channel not wired; only A edge detection in program Verify B input status; check program Wire B channel; implement quadrature decode logic
24 V present at encoder V+ but 0 V at output at all times Encoder output transistor shorted; encoder failed Measure resistance from output to GND with encoder unpowered Replace encoder; verify supply voltage is within data sheet range
Counts increment but distance calculation is off by 2× Program uses 1× logic but encoder is 4× quadrature wired Compare actual counts/rev to expected (256 for 4×, 64 for 1×) Adjust PPR factor in distance formula, or move to 1× counting

Frequently Asked Questions

What pull-up resistor value should I use for a 24 V open-collector encoder on a Siemens SM 321 digital input?

Use 1.47 kΩ (1/4 W, 1% or 5% tolerance) from each output (A and B) to +24 V DC. This produces a sink current of approximately 16.3 mA, well within the 20-40 mA sink rating of typical 24 V open-collector encoders, and ensures V_OL ≤ 0.6 V (well below the SM 321 V_IL ≤ 5 V threshold). On long cable runs above 50 m, increase the resistor to 2.2 kΩ to limit current and verify the encoder minimum sink-current specification.

Can a Siemens SM 321 digital input reliably read a 64 PPR encoder at 40 RPM?

Yes. At 40 RPM the pulse frequency is 42.67 Hz (23.4 ms period, 11.7 ms semiperiod). With a 3 ms input filter (SM 321-1BH02 in position B) or no filter (SM 321-1BL00 at 1.2 ms typ), the input delay is well below the 11.7 ms semiperiod. However, the PLC OB1 scan time (5-15 ms typical) is too slow for polled counting — use a counter module (FM350-2, ET 200S 1Count), edge-interrupt input, or fast cyclic OB (OB35 at ≤ 5 ms).

Why does my position count drift even when the conveyor is stopped?

Vibration from adjacent machinery causes the encoder output to oscillate between high and low states at standstill, and each oscillation is counted as a valid pulse. Mitigate by using a counter module with configurable minimum pulse width (FM350-2, ET 200S 1Count), implementing A/B quadrature validation in software that requires both channels to transition correctly, or by mechanically isolating the encoder from vibration sources with a flexible coupling or damping mount.

When should I switch from a digital input to a Siemens counter module like the FM350-2?

Switch to FM350-2 (or ET 200S 1Count) when the application requires any of: pulse frequencies above 100 Hz, reliable quadrature decoding with direction discrimination, hardware-based chatter suppression, or scan-time-independent counting. The FM350-2 (6ES7350-2AH01-0AE0) supports up to 10 MHz and 1×/2×/4× quadrature evaluation in hardware across 8 channels.

What is the maximum pulse frequency an SM 321 digital input can read?

It depends on the module variant. With a 3 ms input filter (SM 321-1BH02 position B), the maximum frequency is approximately 166 Hz at 50% duty. With a 0.5 ms filter (position A), approximately 1 kHz. The faster SM 321-1CH00 (0.1 ms) and 1FH00 (0.05 ms) modules can handle up to 5 kHz and 10 kHz respectively. For higher frequencies, use a dedicated counter module such as the FM350-2 (10 MHz) or ET 200S 1Count 5V (500 kHz).

Back to blog