Beckhoff First Scan Bit Jun 2026
Which of these two methods are you planning to use for your specific project? Beckhoff CX1010 first scan | PLCtalk - Interactive Q & A
A first scan bit is a boolean flag that remains TRUE for exactly one execution cycle of the PLC task. After the first logic solve is complete, the bit drops to FALSE and stays there until the PLC is restarted.
Best practices
METHOD FB_init : BOOL VAR_INPUT bInitRetains : BOOL; // If TRUE, retain variables are initialized bInCopyCode : BOOL; // If TRUE, instance was copied (e.g., during online change) END_VAR // Initialization code here nTargetVelocity := 1500; bEnableAxis := TRUE; Use code with caution. Why Use It? beckhoff first scan bit
Unlike some other PLC platforms that have a direct global bit (e.g., _FirstScan ), Beckhoff TwinCAT uses a more precise approach by looking at task information, allowing for multi-tasking scenarios 1.2.4 . Method 1: Using PlcTaskSystemInfo (Recommended)
PROGRAM MAIN VAR bFirstScan : BOOL; // True only during the first execution cycle bInitialized : BOOL; // Global flag showing init status fbReadConfig : FB_FileRead; // Example init function block END_VAR // Determine First Scan using the TwinCAT Task Info structure bFirstScan := (_TaskInfo[1].CycleCount = 1); IF bFirstScan THEN // Execute Startup-Only Logic Here bInitialized := FALSE; // Example: Set default hardware overrides GVL_Hardware.TargetVelocity := 100.0; END_IF; // Rest of your cyclic PLC program runs below Use code with caution. Why this works:
fbFirstScan();
: Place code at the very end of your main program that sets this bit to FALSE . Because the variable is initialized to TRUE , it remains so for the entire first scan before being permanently toggled off. Comparison and Review PlcTaskSystemInfo.FirstCycle Manual Custom Bit Reliability Native to TwinCAT; handles task-specific restarts. Highly reliable if implemented at the program's end. Complexity Requires calling GETCURTASKINDEX . Extremely simple to declare and use. Best Use Case
A common misconception is that the first scan bit is only relevant upon a full system power-up. In TwinCAT, however, using the SystemTaskInfoArr[1].firstCycle variable will be TRUE when the controller physically starts up (a "cold start"). It will not be set to TRUE when you simply restart the PLC program from STOP to RUN.
| Variable Type | Behavior on Power Cycle | Behavior on Program Download | Interaction with First Scan | |---|---|---|---| | | Re-initializes to declared start value | Re-initializes | First scan can set custom initial values | | RETAIN | Retains last value from before power loss | Retains last value (by default) | Useful for detecting first scan without losing value | | PERSISTENT | Retains value across program changes | Retains value across program downloads | Often used with first scan to determine if first run after major update | Which of these two methods are you planning
Unlike legacy PLCs that feature a global system bit in an overhead memory map, TwinCAT links the first scan status directly to its respective execution task. Because TwinCAT is a multi-tasking, deterministic real-time environment, each separate task runs its own independent cycle tracking.
boolean, which signals the initial task execution, or by creating a custom global variable initialized to TRUE. Alternative methods include utilizing
To make your machine's startup routine bulletproof, consider these best practices. Best practices METHOD FB_init : BOOL VAR_INPUT bInitRetains