Sysmac Studio · NJ/NX · the heartbeat

The task cycle

Your code doesn't run top to bottom just once. It runs again and again, on a fixed clock: read the inputs, run the logic, write the outputs, repeat. Once this loop makes sense, the rest of the course gets much easier to follow.

🔄 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 is out[i] := in[i]: each lamp mirrors its sensor, but only using the values captured at phase 1.

02 · What follows from it

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 is deliberate: your logic reads one consistent snapshot and never sees a value halfway through a change.

🐶 The watchdog guards the clock. If your program ever takes longer than the task period to execute, the controller logs a Task Period Exceeded error, which NJ/NX treats as a minor fault. Task execution time must always fit inside the period, and that period is the time 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. Retention is the first topic in 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?