Generating Binary Output Sequences on LOGO! 0BA7 for Test Benches

David Krause10 min read
HMI ProgrammingSiemensTutorial / 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

Application Overview

Binary-coded output sequences are required to validate end-of-arm tooling, integrated positioners, valve islands, and rotary cam limit switches whose command set is a parallel BCD or Gray-free position word. A typical sequence of eight positions expressed in straight binary looks like:

Step Decimal Q4 (MSB) Q3 Q2 Q1 (LSB)
1 1 0 0 0 1
2 3 0 0 1 1
3 8 1 0 0 0
4 5 0 1 0 1
5 2 0 0 1 0
6 6 0 1 1 0
7 4 0 1 0 0
8 7 0 1 1 1

The challenge is implementing this sequence on a controller with limited resources. The Siemens LOGO! 0BA7 (12/24 V variant) provides 24 digital inputs and 16 digital outputs in its base configuration, which is sufficient to drive four data lines, one strobe line, and reserve inputs for Start/Stop/Reset pushbuttons. This article documents the recommended implementation strategy, the zero-exclusion problem with the LOGO! random generator, and a deterministic alternative using the shift-register and counter blocks in LOGO! Soft Comfort.

Prerequisites

  • LOGO! 0BA7 base module with display: 6ED1052-1MD00-0BA7 (LOGO! 12/24 RCE) or compatible variant.
  • LOGO! Soft Comfort V8.x (or later) installed on the engineering PC.
  • Ethernet or USB programming cable (LOGO! 0BA7 supports the Ethernet RJ45 port on the back of the base module).
  • A digital I/O expansion module if more than 5 outputs are required downstream of the test bench wiring.
  • Reference manual: LOGO! 0BA7 System Manual (Siemens Industry Online Support).

I/O Allocation

Reserve inputs and outputs before writing the program. The following table is the recommended mapping for an eight-position sequence with hand-jog controls:

LOGO! Address Signal Direction Function
I1 START_PB DI 24 V Rising edge starts the sequence run
I2 STOP_PB DI 24 V Stops the sequence, resets state machine
I3 RESET_PB DI 24 V Forces the program back to step 0
I4 STEP_BWD DI 24 V Manual decrement during commissioning
I5 STEP_FWD DI 24 V Manual increment during commissioning
I6 SEQ_SEL_8 DI 24 V Selector switch: 8-position mode
I7 SEQ_SEL_12 DI 24 V Selector switch: 12-position mode
Q1 BIT0_LSB DO 24 V / 0.3 A Bit 0 of the position word
Q2 BIT1 DO 24 V / 0.3 A Bit 1 of the position word
Q3 BIT2 DO 24 V / 0.3 A Bit 2 of the position word
Q4 BIT3_MSB DO 24 V / 0.3 A Bit 3 of the position word (covers values 8-15)
Q5 STROBE DO 24 V / 0.3 A One-cycle pulse after each step change
Q6 RUN_LAMP DO 24 V / 0.3 A Indicates sequence is active
Q7 END_OF_SEQ DO 24 V / 0.3 A Latches when the final step is reached
Resource budget: The 0BA7 12/24 base module has 16 transistor outputs rated 24 V / 0.3 A per channel. The current sourcing limit per group of four outputs on the 0BA7 base module is typically 0.6 A; if the device under test requires higher currents, route the LOGO! outputs through external interposing relays or use a digital output expansion such as 6ED1055-1NB10-0BA2.

Why a Random Generator Is Not the Right Tool

LOGO! Soft Comfort ships a Random number generator block (function block ID B22 in the legacy toolchain). Its output range is 0..N, and N is entered by the user. For an eight-position device the engineer typically enters 8 and expects values 1..8, but the block includes 0 in the uniform distribution. Two consequences follow:

  1. The downstream positioner is driven to an undefined index (decimal 0 maps to all outputs low, which most BCD decoders treat as "no valid position").
  2. Validation tests become non-reproducible: a regulatory test bench must produce the same stimulus sequence on every trial.

For these two reasons a deterministic sequence driven by an up-counter and a BCD-to-binary encoder is the correct architecture.

Sequence Engine Architecture

The recommended topology replaces the random block with three cascaded logic stages:

Up/Down Counter (B01) Comparator (B05) < 8 or < 12 Decoder (B11) 1-of-N routing Q1..Q4 + STROBE

The three blocks provide the deterministic stepping, the upper-limit guard that excludes 0 and excludes values greater than the selected sequence length, and the routing of the counter value into the four output bits.

Block 1 - Up/Down Counter (Function Block B01)

  • Set On = 1 so the count increments on each rising edge.
  • Set Start = 1 (preset value) so the first step is decimal 1, not decimal 0.
  • Set Direction = Up (default).
  • Feed the trigger input with a 100 ms or 200 ms clock generator (LOGO! block B06 - On/Off delay or B08 - Pulse generator). 100 ms is a safe minimum that respects the 0BA7 scan cycle of ~10 ms and gives the positioner time to latch the word.

Block 2 - Comparator for Upper Limit (Function Block B05)

Two comparators wired in parallel produce the reset signal that wraps the counter back to 1 when the sequence is complete:

  • Comparator 1: counter value >= 8 with SEQ_SEL_8 = 1 forces Cnt = 0 on the next clock.
  • Comparator 2: counter value >= 12 with SEQ_SEL_12 = 1 forces Cnt = 0.
  • Both comparator outputs go through an OR gate (function block B07) so that exactly one path is active at any time, depending on which selector input is high.
Mutual exclusion: Wire the two selector inputs through a two-pole selector switch on the test bench panel. If both are HIGH simultaneously the OR gate will force an immediate reset and the sequence will appear stuck; this is the desired safety behavior.

Block 3 - Decoder to Binary Bits

Rather than using BCD-decoder blocks, take advantage of the counter's integer output and feed it into four parallel comparators (function block B05) to derive each bit directly:

Output Active Condition Logic
Q1 (LSB) Counter value is odd B05: Cnt Mod 2 == 1
Q2 Bit 1 of counter is set B05: Cnt AND 2 == 2
Q3 Bit 2 of counter is set B05: Cnt AND 4 == 4
Q4 (MSB) Bit 3 of counter is set B05: Cnt AND 8 == 8

LOGO! 0BA7 comparators accept integer operands at the parameter dialog, so the bit-extraction math is entered directly without ladder of AND gates. Reference: LOGO! 0BA7 System Manual, chapter on arithmetic / comparator blocks.

Strobe Pulse Generation

The positioner under test expects a one-shot strobe that latches the four-bit word. Implement this with the Edge-triggered Pulse Generator (LOGO! block B08) configured as a single-shot of 50 ms duration, triggered on every counter increment:

  1. Detect the rising edge of the counter output change using a one-bit memory (B04 - Set/Reset latch wired in toggle mode).
  2. Differentiate the memory's output using B08 with a 50 ms pulse width.
  3. Route the differentiated pulse to Q5 (STROBE).

The 50 ms pulse width must be longer than the slowest expected DUT latch time. Verify the actual value against the device datasheet before final commissioning.

Zero-Exclusion Implementation Detail

The original problem - "the random generator also generates zero (0)" - is solved at two layers in this architecture:

  1. Preset value on the up/down counter is set to Start = 1. The counter never sits at 0 between cycles because the comparator resets it from the upper limit back to 1, never to 0.
  2. Comparator guard: any time the counter is being read by an external HMI or by the decoder, the bit extraction ignores the zero range naturally - the binary representations of 1..8 contain no need for a zero bit. If the DUT must absolutely never see 0000, wire a NAND gate (B37) across Q1..Q4 so that all-four-low produces an inhibit on Q5 (STROBE).

Step-by-Step Commissioning Procedure

  1. Open LOGO! Soft Comfort and select Tools > Select Hardware > 0BA7. Confirm the part number matches the installed module.
  2. Build the program block-by-block: counter, two upper-limit comparators, four bit-extraction comparators, strobe pulse, run lamp. Save as testbench_sequence.lsc.
  3. Switch the 0BA7 to STOP mode (press ESC on the display until the main menu appears, then select Stop).
  4. Connect the engineering PC via the Ethernet RJ45 port and click PC → LOGO! in LOGO! Soft Comfort to download the program.
  5. Switch the LOGO! back to RUN. The RUN_LAMP (Q6) should illuminate within one scan cycle.
  6. Set the selector switch to SEQ_SEL_8 and press START_PB. Use an oscilloscope or the LOGO! online monitor to confirm Q1..Q4 step through 1, 3, 8, 5, 2, 6, 4, 7 in sequence. Press STOP_PB to halt.
  7. Repeat step 6 with SEQ_SEL_12. Confirm the counter wraps at 12 and returns to 1.
  8. Disconnect the engineering cable, lock the cabinet, and sign off the validation report.

Verification Checklist

Check Expected Pass Criteria
Q1..Q4 at step 1 0001 Only Q1 high
Q1..Q4 at step 3 0011 Q1 and Q2 high
Q1..Q4 at step 8 1000 Only Q4 high
Q5 STROBE width 50 ms ± 5 ms Measured on scope
Counter wrap (8 mode) 8 → 1 Q1..Q4 = 1000 → 0001 in one cycle
Counter wrap (12 mode) 12 → 1 Q1..Q4 = 1100 → 0001 in one cycle
Zero exclusion 0000 never presented to DUT Strobe inhibited or step skipped
STOP_PB behavior Q1..Q4 freeze, RUN_LAMP off Counter output held
RESET_PB behavior Counter returns to 1 Q1..Q4 = 0001 on next strobe

Troubleshooting Matrix

Symptom Likely Root Cause Corrective Action
Counter never increments Trigger source not connected or B06 pulse generator set to 0 Verify B06 Th = 0.1 s, Tl = 0
Sequence stuck on step 1 Comparator reset path always true Inspect B05 parameter: should be >=, not =
Output bits flicker Scan-time race with the DUT latch Increase the strobe pulse width to 100 ms
Zero value appears on DUT Selector switch in neutral, both SEQ_SEL inputs low Implement an interlock that holds the counter at 1 when no sequence is selected
LOGO! reports SD card error Program larger than base module program memory Reduce function-block count or upgrade to LOGO! 8 (0BA8) for larger memory
Ethernet download fails Wrong IP subnet on the PC Set PC to 192.168.0.10/24; default LOGO! address is 192.168.0.1

Scaling Beyond the 0BA7

If the test bench is later expanded to more than 12 positions, or if additional deterministic sequencing tasks are added, the recommended migration path is to LOGO! 8 (0BA8) or to a SIMATIC S7-200 / S7-1200 controller:

Controller DI / DO Program Memory Positioner Test Use Case
LOGO! 0BA7 12/24 24 / 16 400 blocks Up to 12-position sequences, single DUT
LOGO! 0BA8 12/24 24 / 16 850 blocks Up to 16 positions with HMI text display
S7-200 CPU 224 24 / 16 12 KB Multi-DUT rack with recipe selection
S7-1200 CPU 1214C 24 / 16 100 KB Production test stand with PROFINET diagnostics

Reference manuals for the migration candidates: S7-1200 Programmable Controller System Manual and LOGO! 0BA7 System Manual.

FAQ

How do I prevent the LOGO! 0BA7 random generator from outputting zero on a positioner test?

Replace the random generator block (B22) with a deterministic Up/Down counter (B01) configured with Start = 1 and an upper-limit comparator that wraps the count back to 1 instead of to 0. This guarantees the four output bits never present 0000 to the device under test.

What scan time should I use for the bit-rate clock on a binary sequence test?

Use a pulse generator (B06) of 100 ms on / 0 ms off as a safe starting point for 8- and 12-position validation. Slow the clock to 200 ms if the DUT latch window requires more time, and verify with an oscilloscope before sign-off.

How do I switch between 8-position and 12-position modes without rewriting the program?

Wire a two-pole selector switch to two LOGO! inputs (I6 and I7) and route them into two parallel upper-limit comparators (B05). An OR gate (B07) feeds the counter reset, so only one mode is active at a time and the sequence length changes without modifying the program logic.

Can the LOGO! 0BA7 12/24 source enough current for an integrated positioner?

The 0BA7 base module transistor outputs are rated 0.3 A per channel, with a group limit that must be checked against the device datasheet. If the positioner draws more current, interpose an external relay or use a LOGO! DM8 24R or DM16 24R output expansion module.

What is the next step up from LOGO! 0BA7 for a multi-DUT test bench?

Move to LOGO! 0BA8 for larger program memory and integrated Web server HMI, or migrate to a SIMATIC S7-1200 CPU 1214C when the application grows beyond 16 positions and requires PROFINET diagnostics and recipe management.

Back to blog