Add-On Instruction Scan Modes
To provide Add-On Instructions with the same flexibility as built-in instructions, optional scan mode routines can be configured that let you fully define the behavior of the instruction. The scan mode routines do not initially exist for an Add-On Instructions—they are optional. You must create them depending upon the requirements of the instruction.
Like all built-in instructions in the controller, Add-On Instructions support the following four controller scan modes:
- True – Logic is scanned as the result of a true rung condition or the EnableIn parameter is set to True.
- False – Logic is scanned as the result of a false rung condition or the EnableIn parameter is set to False. Instructions in the controller may or may not have logic that executes only when that instruction is scanned false.
- Prescan – Occurs when the controller either powers up in Run mode or transitions from Program to Run mode. Instructions in the controller may or may not have logic that executes only when that instruction is executed in Prescan mode.
- Postscan – Occurs as a result of an Action in an SFC routine becoming inactive if SFCs are configured for Automatic Reset. Instructions in the controller may or may not have logic that executes only when that instruction is executed in Postscan mode.
The default behavior for executing an Add-On Instruction with no optional scan routines created may be sufficient for the intended operation of the instruction. If you do not define an optional Scan Mode, the following default behavior of an Add-On Instruction occurs:.
- True – Executes the main Logic routine of the Add-On Instruction.
- False – Does not execute any logic for the Add-On Instruction and does not write any outputs. Input parameters are passed values from their arguments.
- Prescan – Executes the main Logic routine of the Add-On Instruction in prescan mode. Any required input and output parameters’ values are passed.
- Postscan – Executes the main Logic routine of the Add-On Instruction in postscan mode.
For each Scan Mode, you can define a routine that is programmed specifically for that scan mode and can be configured to execute in that mode.
- True – The main Logic routine for the Add-On Instruction executes (not optional).
- False – The EnableIn False routine executes normally in place of the main Logic when a scan false of the instruction occurs. Any required (or wired in FBD) input and output parameters’ values are passed.
- Prescan – The Prescan routine executes normally after a prescan execution of the main Logic routine. Any required input and output parameters’ values are passed.
- Postscan – The Postscan routine executes normally after a postscan execution of the main Logic routine.
Enabling Scan Modes
The Scan Modes tab in the Instruction Editor lets you enable program routines and create and enable execution of the routines for the following three scan modes:
- PrescanThe function of the controller whereby the logic within a program is examined prior to execution. This allows for instruction and data initialization.
- PostscanThe function of the controller whereby the logic within a program is examined before disabling it in order to reset instructions and data.
- EnableInFalseWhen defined and enabled for an Add-On Instruction, the EnableInFalse routine executes when the rung condition is false or the EnableIn parameter of the Add-On Instruction is false (0). This is useful primarily for scan false logic when used as an output instruction in a Ladder routine.
Prescan Routine
When the controller transitions from Program mode to Run mode or when the controller powers up in Run mode, all logic within the controller is executed in Prescan mode. During this scan, each instruction may initialize itself and some initialize any tags it may reference. For most instructions, Prescan mode is synonymous with scanning false. For example, an OTE instruction clears its output bit when executed during Prescan. For others, special initialization may be done such as an ONS instruction setting its storage bit during Prescan. During Prescan mode, all instructions evaluate false so conditional logic does not execute.
The optional Prescan routine for an Add-On Instruction provides a way for an Add-On Instruction to define additional behavior for Prescan mode. When a Prescan routine is defined and enabled, the Prescan routine executes normally after the primary Logic routine executes in Prescan mode. This is useful when it is desired to initialize tag values to some known or predefined state prior to execution. An example is setting a PID instruction to manual mode with a 0% output prior to its first execution or to initialize some coefficient values in your Add-On instruction.
Note that when an Add-On Instruction executes in Prescan mode, any required parameters have their data passed.
- Values are passed to Input parameters from their arguments in the instruction call.
- Values are passed out of Output parameters to their arguments defined in the instruction call.
These values are passed even when the rung condition is false in Ladder Diagram or when the instruction call is in a false conditional statement in Structured Text. When Function Block Diagram routines are executed, the data values are copied to all wired inputs and from all wired outputs, whether the parameters are required or not.
Postscan Routine
Postscan mode only occurs for logic in an SFC action when the action becomes inactive and SFC language is configured for Automatic Reset (which is not the default option for SFC). When an SFC action becomes inactive, then the logic in the action is executed one more time in Postscan mode. This mode is similar to Prescan in that most instructions simply execute as if they have a false condition. It is possible for an instruction to have different behavior during Postscan than it has during Prescan.
When an Add-On instruction is called by logic in an SFC action or a call resides in a routine called by a JSR from an SFC Action, and the Automatic Reset option is set, the Add-On Instruction executes in Postscan mode. The primary Logic routine of the Add-On Instruction executes in Postscan mode. Then, if it is defined and enabled, the Postscan routine for the Add-On Instruction executes.
This could be useful in resetting internal states, status values, or de-energizing instruction outputs automatically when the action is finished.
TIP:
Because safety Add-On Instructions cannot be called from an SFC action, the Postscan Routine option is disabled for safety Add-On Instructions.
EnableInFalse Routine
When defined and enabled for an Add-On Instruction, the EnableInFalse routine executes when the rung condition is false or the EnableIn parameter of the Add-On Instruction is false (0). This is useful primarily for scan false logic when used as an output instruction in a Ladder routine. A common use of scan false is the setting of OTEs to the de-energized state when the preceding rung conditions are false. An Add-On Instruction can use the EnableInFalse capability to let you define behavior for the False conditions.
Note that when the Add-On Instruction is executed in the false condition and has an EnableInFalse routine defined and enabled, any required parameters have their data passed.
- Values are passed to Input parameters from their arguments in the instruction call.
- Values are passed out of Output parameters to their arguments defined in the instruction call.
If the EnableInFalse routine is not enabled, the only action performed for the Add-On Instruction in the false condition is that the values are passed to any required Input parameters in Ladder.
Note that because EnableIn is always true (1) in Structured Text, the EnableInFalse routine never executes when the Add-On Instruction call is contained in a Structured Text routine.
Provide Feedback