Level Up Your PLC Logic: Clock Pulses Explained

Your PLC has bits you never wrote. One of them is on for exactly one scan, the moment the program starts. Others flash on and off all day at fixed rates, whether your program uses them or not. They are called PLC system bits, and once you know them you can initialise a program, blink a light and keep time without a single timer.

By the end of this post you will know what the first scan bit is for, why the clock pulse bits make great flashers but poor timers, and how to combine a clock with last week’s rising edge contact to build a steady one-second time base. We will build it all on the free ACC PLC Simulator with the 3D Control Panel scene: a power-up acknowledge, a timed motor run, and one pilot light that tells the operator three different things.
Level Up Your PLC Logic: Clock Pulses Explained

Watch it on YouTube:
Level Up Your PLC Logic: Clock Pulses Explained

Previously, we examined…


Bits You Never Wrote

What a system bit is

Every PLC keeps a small block of status bits that the processor maintains for you. Your program reads them with ordinary contacts, but it cannot turn them on or off. They answer questions the program cannot easily answer for itself: is this the very first scan?, which half of the second are we in?, is a scene connected?

In the ACC PLC Simulator they are the SB addresses. They are refreshed once at the top of every scan, so every rung in that scan sees the same value. You will find them all, live, on the SYS tab of the I/O panel.

Address Name What it does
SB1 Always ON ON on every scan
SB2 Always OFF OFF on every scan
SB3 First scan ON for one scan after STOP → RUN
SB4 Scan toggle Flips ON/OFF every scan
SB5 0.5 s clock 250 ms ON, 250 ms OFF
SB6 1 s clock 500 ms ON, 500 ms OFF
SB7 1 min clock 30 s ON, 30 s OFF
SB9–SB12 Error flags Math overflow, divide by zero, range fault, any error
SB17 Scene linked A 3D scene is connected
SB18 Gamepad A gamepad is connected

The SYS tab also shows the system words SW1–SW19: the real-time clock, scan time and scan count. Those deserve their own post; today is about the bits.

The ACC system bit tab

Always ON and always OFF

SB1 looks pointless until you need an instruction to run on every scan. Some instructions need something in front of them on the rung, and an always-ON contact says plainly “this runs every scan, on purpose.” SB2 is the opposite: drop it in series to hold a rung off while you test, without deleting anything.

The first scan bit

SB3 is ON for exactly one scan: the first scan after the PLC goes from STOP to RUN. On a real controller that also covers the first scan after power-up. Any rung that starts with an SB3 contact runs once and is then skipped until the next start. That makes it the right place to put the program into a known state.

Why would the program not already be in a known state? Because some memory survives a stop. When the simulator goes to STOP it clears the Y outputs, C relays and AY analog outputs. It does not clear the D registers, timer accumulators or counter counts. On a real PLC, retentive memory survives a power cycle the same way. A total, a step number or a setpoint from the last run is still sitting there when you press RUN, and the first scan is where you decide which of those to keep and which to reload.

one shot / one scan bit

Clock pulses

SB5, SB6 and SB7 are free-running square waves, half on and half off. The simulator derives them from real time, not from the scan count, so they stay accurate when a scan runs a little long. There is deliberately no 100 ms clock: the simulator scans every 100 ms, so a clock that fast could not be seen reliably.

A clock contact straight onto an output is the simplest flasher there is: SB6 → Y1 blinks Y1 once a second. No timer, no reset, no seal-in.

A clock is not a timer

A clock does not start when something happens. It was already running before you pressed the button, and it will keep running after. So the first rising edge after an event arrives somewhere in the next period. Count ten pulses of the 1 s clock and you get somewhere between 9 and 10 seconds, not 10.0.

That is fine for flashing a light, a slow heartbeat, or a run-hours total. When the time has to start on an event, like a 2-second warning horn before a motor starts, use a TON timer.

Level Up Your PLC Logic: Clock Pulses Explained

What other PLCs call them

Every brand has these bits; the names change.

  • AutomationDirect Click: the System Control relays. SC1 is _Always_ON, SC2 is _1st_SCAN, SC3 is the scan clock, and SC4 to SC9 are clocks from 10 ms up to 1 hour (SC7 is the 1 s clock).
  • Rockwell Studio 5000 (Logix): the first scan bit is S:FS. There are no built-in clock bits; you build a flasher from a timer.
  • Siemens S7-1200/1500: turn on the system memory byte (FirstScan, AlwaysTRUE, AlwaysFALSE) and the clock memory byte (eight clocks from 0.5 Hz to 10 Hz) in the CPU properties. They are off until you do.
  • IEC 61131-3 Structured Text has no standard first-scan variable. A common pattern is a BOOL declared with an initial value of TRUE that the program clears at the end of its first cycle.

Always check the manual for your controller before relying on a system bit.


STEP 1 — Define the Task

The Control Panel scene is a floor-mounted panel with Start, Stop and Jog pushbuttons and a motor run pilot light. In plain English, with no timers allowed:

  1. Power-up acknowledge. Every time the PLC starts, the run light flashes fast and Start is blocked until an operator presses Jog to acknowledge.
  2. Known values. Every start loads the run time preset (10 s) and clears the run-seconds count.
  3. Timed run. Start runs the motor. After 10 seconds of running it stops by itself. Stop always stops it.
  4. One light, three meanings. Steady = running. Fast flash = acknowledge needed. Slow flash = run time done.

Number 1 is a real pattern: after a power failure, many machines refuse to restart until someone has looked at them and pressed a reset.


STEP 2 — Define the I/O

Address Description Type Modbus
X1 Start pushbutton (N.O.) Input DI 10001
X2 Stop pushbutton (N.C. — ON when not pressed) Input DI 10002
X3 Jog pushbutton (N.O.), used here as Acknowledge Input DI 10003
Y1 Motor run pilot light Output Coil 00001
C1 Motor run (would drive the contactor on a real machine) Internal bit —
C2 Power-up flag Internal bit —
C3 Run time done Internal bit —
D1 Run seconds Data register (INT) —
D2 Run time preset (s) Data register (INT) —
SB3 First scan System bit —
SB5 0.5 s clock System bit —
SB6 1 s clock System bit —

The scene supplies X1 to X3 and shows Y1. The system bits come from the simulator itself, so there is nothing to wire.

Level Up Your PLC Logic: Clock Pulses Explained


STEP 3 — Develop the Sequence

Level Up Your PLC Logic: Clock Pulses Explained

  1. First scan (SB3): latch C2, move 10 into D2, move 0 into D1.
  2. While C2 is ON, Y1 follows the 0.5 s clock (fast flash) and Start is blocked.
  3. Jog (X3) unlatches C2. The light goes out.
  4. A rising edge on Start (X1) moves 0 into D1. C1 seals in.
  5. Every rising edge of the 1 s clock (SB6) while C1 is ON adds 1 to D1.
  6. When D1 ≥ D2, C3 turns ON. C1 drops out. Y1 follows the 1 s clock (slow flash).
  7. Stop (X2) drops C1 at any time.

Two questions before you build it: if rung 7 used a plain SB6 contact instead of its rising edge, how fast would D1 count? And if you press Start, then Stop, then put the PLC in STOP and back to RUN, what does the light do and what is in D1? (Answers in STEP 5.)


STEP 4 — Develop the PLC Program

Level Up Your PLC Logic: Clock Pulses Explained

Nine rungs, every one commented.

Rung Logic Comment
0 SB3 → OTL C2 First scan: latch the power-up flag
1 SB3 → MOV 10 → D2 First scan: load the default run time
2 SB3 → MOV 0 → D1 First scan: clear the run seconds
3 X3 → OTU C2 Acknowledge clears the flag
4 P X1 AND NOT C2 → MOV 0 → D1 New run: zero the run seconds
5 GEQ D1 ≥ D2 → C3 Run time done
6 ( X1 OR C1 ) AND X2 AND NOT C2 AND NOT C3 → C1 Motor run seal-in
7 P SB6 AND C1 → INC D1 One count per second
8 C1 OR ( C2 AND SB5 ) OR ( C3 AND SB6 ) → Y1 One light, three meanings

To build it yourself, drag XIC from the CONTACTS section onto a rung and type SB3 as the address. The simulator labels system bits for you, so the contact shows First scan underneath without a comment. MOV is in MOVE / DATA, GEQ in COMPARE and INC in MATH. For rung 7, drag Rising Edge (-|P|-) and give it the address SB6.

Or skip the typing: download acc-example-system-bits.json and import it with LOAD.

Three things to notice:

  • Rungs 0 to 2 run once. On every other scan SB3 is OFF and they are skipped. Rung 0 uses OTL, not OTE: an OTE would turn C2 back off on the second scan.
  • Rung 7 needs the P. SB6 is ON for 500 ms, which is five 100 ms scans. A plain contact would add 5 to D1 every second. The rising edge turns the clock into one pulse per second. This is the one-shot from last week doing a new job.
  • Rung 8 is three ideas in one rung. Put a clock bit in series with a condition and the condition flashes. Two clocks give two flash rates, so the operator can tell “acknowledge me” from “finished” at a glance.

Level Up Your PLC Logic: Clock Pulses Explained

The Same Program in Structured Text

ST - Structured Text Version of program

VAR
  StartRise   : R_TRIG;   // rising edge of Start
  SecondPulse : R_TRIG;   // rising edge of the 1 s clock
  MotorRun    : BOOL;     // seal-in
  PowerUp     : BOOL;     // power-up flag, needs acknowledge
  TimeDone    : BOOL;     // run time reached
  RunSeconds  : INT;      // seconds the motor has run
  RunPreset   : INT;      // run time preset
END_VAR

IF SB3 THEN                             // first scan
  PowerUp := TRUE;
  RunPreset := 10;
  RunSeconds := 0;
END_IF;

IF X3 THEN                              // acknowledge
  PowerUp := FALSE;
END_IF;

StartRise(CLK := X1);                   // new run
IF StartRise.Q AND NOT PowerUp THEN
  RunSeconds := 0;
END_IF;

TimeDone := RunSeconds >= RunPreset;
MotorRun := (X1 OR MotorRun) AND X2 AND NOT PowerUp AND NOT TimeDone;

SecondPulse(CLK := SB6);                // one pulse per second
IF SecondPulse.Q AND MotorRun THEN
  RunSeconds := RunSeconds + 1;
END_IF;

Y1 := MotorRun OR (PowerUp AND SB5) OR (TimeDone AND SB6);

System bits are read in ST exactly like inputs: IF SB3 THEN is the first-scan rung, and SB5 and SB6 drop straight into a Boolean expression. They are read-only, so SB3 := FALSE; is rejected by the editor. The rising edge of the clock is an R_TRIG, one instance per edge, the same as last week.

Download the commented file: acc-example-system-bits.st.


STEP 5 — Test the Program

Level Up Your PLC Logic: Clock Pulses Explained

  1. Open the ACC PLC Simulator and load the example program.
  2. Click CONNECT and launch the Control Panel scene.
  3. Press RUN in the simulator.

Keep the D tab of the I/O panel (or the SYS tab) in view while you work through these tests:

Test the first scan. The light starts flashing fast the moment you press RUN. D2 shows 10 and D1 shows 0. Press Start: nothing happens, because C2 blocks the seal-in. Press Jog: the light goes out and the panel is ready.

Test the run timer. Press Start. The light comes on steady and D1 counts up once a second. At 10 the motor drops out and the light flashes slowly. Time it with a stopwatch: the run lasts between 9 and 10 seconds, because the first clock edge arrives some time in the first second. That answers the first question too: change rung 7 to a plain XIC contact (double-click the P contact and pick XIC) and D1 climbs by about 5 every second, so the “10-second” run is over in under 2 seconds.

Level Up Your PLC Logic: Clock Pulses Explained

Test a stop and restart. Press Start, wait a few seconds, then press Stop. D1 holds its count. Now press STOP in the simulator, then RUN. That answers the second question: the light flashes fast again, Start is blocked again, and D1 is back to 0. C2 came back because rung 0 ran on the first scan; D1 is 0 because rung 2 cleared it. Without rungs 0 to 2, D1 would still hold the old count and the panel would be ready to start without an acknowledge.

Test an online edit. While the PLC is in RUN, click EDIT, change the MOV in rung 1 from 10 to 30, and accept the edit. D2 stays at 10. An online edit swaps the program in between two scans without leaving RUN, so there is no first scan. Put the PLC through STOP and RUN, and D2 becomes 30.

Level Up Your PLC Logic: Clock Pulses Explained

Testing with a Real PLC over Modbus

To run the same logic in your own PLC, start the bridge (node acc-modbus-bridge.js), click ⬡ MODBUS → CONNECT in the Control Panel scene, and point your PLC’s Modbus TCP client at the bridge:

Setting Value
IP address Your PC’s LAN IP (127.0.0.1 for Modbus Poll on the same PC)
Port 502 (or 5020 if you started the bridge with --modbus-port 5020)
Unit ID 1
Read inputs FC02 Discrete Inputs 10001–10003 (X1–X3)
Write outputs FC05 Coil 00001 (Y1)

The system bits now come from your PLC, not the simulator: replace SB3, SB5 and SB6 with your controller’s own first scan and clock bits (see What other PLCs call them above). The light reaches the scene through Modbus, so a flash is only as smooth as your write rate. The 0.5 s clock is ON for 250 ms; write the coil every 100 ms or faster or the fast flash will stutter.
Testing on real hardware with Modbus communication


Common System Bit Mistakes

  • Counting with a plain clock contact. It is ON for many scans. Count its rising edge.
  • Using a clock as a timer. The clock was not waiting for your event, so the first pulse can come any time in the first period. Use a TON when the time has to start on an event.
  • Using OTE on a first-scan rung. The bit is ON for one scan and gone on the next. Use OTL, MOV or RES so the result stays.
  • Expecting a first scan after an online edit. The program never left RUN. Initialise on a STOP to RUN, or add your own reset.
  • Writing to a system bit. They are read-only. In the simulator the only exception is clearing the error flags SB9 to SB11 with OTU.
  • Assuming every PLC has them, at the same address. Some must be turned on in the CPU settings, and some brands have no clock bits at all.

PLC System Bits

Try it yourself

Bits you never wrote, and how to trust them:

  • The first scan bit is ON for one scan per start. Use it to latch flags and load registers so every run starts from a known state.
  • STOP clears outputs and relays, not registers. The first scan decides what the registers hold.
  • Clock bits are free-running flashers. Put one in series with a condition and the condition flashes.
  • The rising edge of a clock is a steady time base, but a clock is not a timer: the first pulse is not tied to your event.
  • In Structured Text, system bits read like any other variable.

Next step: load the example into the ACC PLC Simulator, connect the Control Panel scene, and change the preset in rung 1 to 30. Then add a fourth meaning to the light: a fault that flashes with SB4, the scan toggle, and see how fast that looks. Next Monday: the drum sequencer, running a traffic light from one instruction.

Related posts