Beckhoff First Scan Bit

You can easily test it by:

In the world of industrial automation, a clean start is everything. When a Beckhoff PLC (Programmable Logic Controller) boots up—whether from a power cycle, a download of a new TwinCAT configuration, or a manual restart—the system enters a critical, fleeting state. Variables are uninitialized, previous runtime values linger in memory, and physical outputs may hold their last state. How do you reliably distinguish this “first scan” from normal cyclic operation?

The answer lies in a small, single-purpose variable: FirstScan (or bInit in older TwinCAT 2 nomenclature). Though it appears only once per startup, its impact on system reliability is profound.

The First Scan Bit is a Boolean flag that is TRUE only for a single PLC cycle immediately after the runtime system starts executing the application. On the second cycle, it becomes FALSE and remains FALSE until the next controller reboot or program download.

If you perform an "Online Change" (modify code without full download), the first scan bit does not trigger. Your initialization code will not run. To force reinitialization, use Reset or Reset Cold from the TwinCAT runtime.

Solution: Use bInit in FB_Init – it respects online changes differently. Or explicitly handle a "reinit" via a variable that you toggle manually.

If you are using Object-Oriented Programming (OOP) with Function Blocks, you should generally use the FB_Init method for hardware checks or setup, rather than a "First Scan" bit inside the body logic. This runs before the first cyclic call and is cleaner for object initialization.

However, for standard ladder logic or structured text programs, the boolean flag method above is the industry standard for Beckhoff systems.


Have you found other uses for a "First Scan" bit in your machines? Let me know in the comments!

#Beckhoff #TwinCAT #PLCProgramming #Automation #ControlsEngineering #IEC61131 beckhoff first scan bit

In Beckhoff TwinCAT (2 and 3), there is no single "magic" global bit like the S:FS in Allen-Bradley . Instead, you can access the "First Scan" status through built-in system variables or by creating a custom initialization flag. 1. Using Built-in System Info (FirstCycle)

The most reliable way to detect the first scan in TwinCAT 3 is to use the PlcTaskSystemInfo structure . Every task has an associated system structure that includes a FirstCycle boolean . Example Implementation (Structured Text):

VAR fbGetCurTaskIdx : GETCURTASKINDEX; // Function block to get current task index bFirstScan : BOOL; END_VAR fbGetCurTaskIdx(); // Call the FB to refresh current task info bFirstScan := _TaskInfo[fbGetCurTaskIdx.index].FirstCycle; IF bFirstScan THEN // Logic here only runs on the very first PLC scan // e.g., Initializing setpoints or resetting state machines END_IF Use code with caution. Copied to clipboard 2. Manual Global Variable Flag

A common "best practice" for portability across different PLC brands is to create your own flag in a Global Variable List (GVL) . Declare it with an initial value:

VAR_GLOBAL bIsFirstScan : BOOL := TRUE; // Starts TRUE when the PLC runtime begins END_VAR Use code with caution. Copied to clipboard

Reset it at the end of your main program:Place this line at the very bottom of your MAIN program or the last task to execute :

// Main logic uses bIsFirstScan... // Final line of code: bIsFirstScan := FALSE; Use code with caution. Copied to clipboard 3. SFC Initialization Flag

If you are using Sequential Function Chart (SFC) programming, TwinCAT provides implicit variables called SFC Flags .

SFCInit: When set to TRUE, the sequence is reset to the initial step . You can easily test it by: In the

SFCReset: Resets the sequence and continues processing from the initial step . Key Usage Considerations

Cold vs. Warm Restart: The FirstCycle bit typically triggers when the Runtime starts . Simple PLC "Stop" and "Start" commands in the IDE might not always reset this bit unless the entire TwinCAT system is restarted or a new configuration is activated .

Multiple Tasks: If your project has multiple tasks (e.g., a fast 1ms task and a slow 100ms task), each task has its own FirstCycle flag. Ensure you are checking the flag for the specific task where your initialization logic resides . RSLogix 5000 First Scan Bit (S:FS) Programming Guide

In Beckhoff’s TwinCAT environment, the First Scan Bit is a fundamental diagnostic tool used to initialize logic, reset variables, or trigger specific startup sequences the moment the PLC transitions from Config/Stop

Unlike a physical switch, this "bit" is a logical pulse that remains TRUE for exactly one task cycle. The Role of Initialization

When a PLC starts, variables often default to zero or their last persisted state. However, many industrial systems require a specific "safe state" or initial configuration before the main control loop takes over. The first scan bit acts as a system trigger , allowing programmers to: Set Initial Values:

Assign setpoints to PID controllers or load recipe parameters from memory. Reset Faults:

Clear old error flags that might have occurred during the previous shutdown. Establish Communication:

Trigger handshakes with external hardware or fieldbus devices. Implementation in TwinCAT 3 Have you found other uses for a "First

Unlike some legacy PLCs that have a dedicated global address (like S7’s

), Beckhoff provides this functionality primarily through the PLC System Information PLC_STARTUP In a typical TwinCAT project, developers often use the PlcTaskSystemInfo structure. By accessing the bFirstCycle

property, the code can detect if it is running for the first time. For example, in Structured Text (ST):

IF _TaskInfo[1].bFirstCycle THEN // Logic here only runs once InitialSetpoint := 50.0; SystemReady := FALSE; END_IF Use code with caution. Copied to clipboard Best Practices and Pitfalls The primary risk with first scan logic is dependency loops

. If multiple Function Blocks rely on the first scan bit to initialize, the order of execution matters. Developers must ensure that hardware I/O is actually "Ready" before the first scan logic attempts to write to it.

Furthermore, because TwinCAT is based on PC architecture, a "Warm Start" versus a "Cold Start" can behave differently regarding Persistent and Retain variables

. The first scan bit should typically be used to compliment these memory features, not fight against them. Conclusion

The First Scan Bit is the "ignition switch" of a TwinCAT program. By isolating startup logic into this single-cycle window, engineers ensure that the system begins its operation from a known, predictable state

, which is the cornerstone of both safety and reliability in automation. Should I show you how to map the System Info variables so you can use this bit in your own project?