Beckhoff First: Scan Bit
For PD5500, EN13445, ASME Section VIII, Div. 1 & 2
: 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
: Triggering a TP (Timer Pulse) or R_TRIG that needs to fire immediately upon startup. beckhoff first scan bit
On older hardware like the , some technical references mention a specific status bit (Bit 4) in certain control parameters that is set for the first scan after power-up. Key Comparison PlcTaskSystemInfo.FirstCycle Custom bInitialized Variable Best for System-level startup/initialization Logic-level resets/warm restarts Reset Trigger TwinCAT Runtime Restart PLC Program Start (Start/Stop) Setup Requires GETCURTASKINDEX Simple declaration : Place code at the very end of
// -- First scan detection -- fbFirstScan(CLK := bInit); IF fbFirstScan.Q THEN bFirstScanDone := FALSE; Highly reliable if implemented at the program's end
IF NOT bInitialized THEN // Initialization code here bInitialized := TRUE; END_IF Use code with caution. Copied to clipboard
Without a proper first scan routine, your machine might start with actuators in unpredictable positions or unfinished states from a previous run.
Beyond simple initialization, the First Scan bit is crucial for the handling of Retain variables. TwinCAT offers robust mechanisms for persistent data, but logic is often required to handle the scenario where no retained data exists (a first boot) versus when it does. The First Scan bit allows the code to differentiate between these scenarios, loading defaults only when necessary or validating the integrity of retained data before use.