Sysmac Studio · NJ/NX · the heartbeat

The Task Cycle

Your code doesn't run top-to-bottom once — it runs again and again, on a fixed clock. Read the inputs, run the logic, write the outputs, repeat. Understand this loop and everything else clicks.

🔄 refresh → run → outputPrimary Periodic Task
01 · The loop

Three phases, on repeat

An NJ/NX controller runs your Primary Periodic Task on a fixed period (say 1 ms). Every period it does the same three things. Step through one cycle, or let it run.

📥
1 · Input refresh
Copy real input terminals into the input process image.
⚙️
2 · Execute
Run your program against that frozen snapshot.
📤
3 · Output refresh
Write the output image out to the real terminals.

Input image  sensors

Output image  actuators

The logic here: out[i] := in[i] — each lamp mirrors its sensor, but only the values captured at phase 1.

02 · Why it matters

The snapshot rule & the watchdog

📸 Inputs are frozen for the whole scan. If a sensor flips during Execute, your code won't see it until the next cycle's refresh. That consistency is a feature — your logic reads one coherent snapshot, never a value mid-change.

🐶 The watchdog guards the clock. If your program ever takes longer than the task period to execute, the controller trips a watchdog fault. Task execution time must always fit inside the period — that's the budget you design to.

🔋 And after power-off? Normal variables reset to their initial values. Only variables you mark Retain keep their last value across a power cycle — the topic that opens the Variable Scope deep dive.

03 · Check yourself

One quick question

A sensor turns on during the Execute phase. When does your logic first react to it?