Products: ACR9600, 9630, 9640
Available ACR User Variables
Process Image
Global Declarations
Using Write Variables: PW and BW
Using Direct Variables with HMI or Acrobasic
Restricted Flags
IEC61131-3 requires all data objects to be declared as variables. A set of different declaration sections is available to define variables on different scopes. IEC61131-3 comes with a set of predefined data-types, called elementary data types. And, there are some means to define user-defined, so called derived data types, using structures, arrays and enumerations.
With most variables, storage is assigned by the compiler, without any programmer activity. For inputs, outputs, and other ACR specific bits and parameters, the programmer may specify a memory location, using directly represented variables.
Directly represented variables are those variables that are mapped to a certain input, output or memory address specified by the programmer. The keyword AT is used to declare this, and the address is specified in a string starting with a percent sign (%).
Direct variables supported in ACR controllers:
-AT%Bnnn read-only flag, where nnn is the bit number
-AT%BWnnn read/write flag, where nnn is the bit number
-AT%Pnnn read-only parameter, where nnn is the parameter number
-AT%PWnnn read/write parameter, where nnn is the parameter number
Notes:
- Direct variables must be designated BW or PW (read/write) in order for them to be written back out to the controller at the end of a PLC scan.
- Certain ACR flags/bits cannot be assigned as BW. See Restricted Flags below.
- While only certain bits are restricted, it is recommend that only ACR bits and parameters designated as physical outputs or user variables be assigned a PW or BW.
- Direct Variables cannot take a initial value nor be marked as RETAIN
- Only the following IEC data types can be associated with Direct Variables. Any other data type will result in a compiler error.
- INT, SINT,INT,DINT,USINT,UINT,UDINT
- BOOL,BYTE,WORD,DWORD
- REAL
- ACR LONG variables can be represented as any INT (SINT,INT,DINT,USINT,UINT,UDINT) or WORD(BOOL,BYTE,WORD,DWORD) Data type
- ACR Float (32 and 64 bit) variables can be represented as REAL in the IEC PLC
- Direct Variables can be declared in Programs and Direct Global files but not in Function Blocks or Functions
Examples of direct variables
fVar0 : REAL AT%P0;
fVar1 : REAL AT%P1;
fVar2 : REAL AT%P2;
fVar3 : REAL AT%P39168;
fVar4 : REAL AT%P39423;
In128 : BOOL AT%B128;
In129 : BOOL AT%B129;
Int0 : SINT AT%P38912;
Int1 : INT AT%P38913;
Int2 : DINT AT%P38914;
Int3 : USINT AT%P38915;
Int4 : UINT AT%P38916;
Int5 : UDINT AT%P38917;
Int6 : BOOL AT%P38918;
Int7 : BYTE AT%P38919;
Int8 : WORD AT%P38920;
Int9 : DWORD AT%P38921;
Init : BOOL AT%B128;
OnBit : BOOL AT%B129;
OffBit : BOOL AT%B130;
Input31 : BOOL AT%B31;(* comment for Input31*)
Output32 : BOOL AT%BW32;(* comment for Output32*)
Available ACR User Variables
.
Parameter Range | ACR Data type | IEC Data Type | Retained | Notes |
P0-P4095 | 64-Bit float | REAL | BBRAM or Flash | Must be dimensioned prior to use. Dimensioning included in ACR-View Configuration Wizard |
P4100-P4103 | 32-Bit Long | DINT, DWORD | No | Each parameter contains 32 user flags (BIT128-255) |
P4156-P4159 | 32-Bit Long | DINT, DWORD | No | Each parameter contains 32 user flags (BIT1920-2047) |
P38912-P39167 | 32-Bit Long | DINT, DWORD | BBRAM | |
P39168-P39423 | 32-Bit float | REAL | BBRAM | |
BIT128-255 | Bit | BOOL | No | Also accessible as P4100-P4103 |
BIT1920-2047 | Bit | BOOL | No | Also accessible as P4156-P4159 |
Process Image
Direct variables are READ from controller registers prior to a program scan. The values are then placed in the Process Image. The program then uses the values from the process image during the scan. When the program is complete the values of the PW and BW variables are written backed to the controller registers.
For example, a program contains these variables:
Input31 : BOOL AT%B31;(* comment for Input31*)
Output32 : BOOL AT%BW32;(* comment for Output32*)
The value of Input31 is read at the beginning and that value is used throughout the program scan, regardless of whether the Input changes during the scan. And the value for Output32 is only written when the program is complete: it does not matter if Output 32 is changed mulitple times within the program, only the last value is actually written to the hardware output.
Global Declarations
Direct variables are allowed in Global declarations files, making the variables accessible in ALL programs. At the beginning of EACH program, the variables will be read from hardware and then written back to hardware at the end of EACH program. This means that the combination of many programs and many Direct Global variables will negatively impact overall scan time. Direct Globals should be limited to those variables that must be accessed by multiple programs.
Also keep in mind that when variables are declared as PW and BW, each program will try to write that value as part of the process image, regardless of whether it really uses the variables. Global PW and BW variables should be used sparingly and cautiously to avoid undesired behavior.
Using Write Variables: PW and BW
Direct variables designated as PW and BW are written by the PLC to controller registers. The editor and runtime engine allows most ACR bits and parameters to be written, but the user should be very selective. In general, only ACR bits and parameters designated as User Variables or as digital or analog outputs should be marked as write variables.
If a program needs to modify system bits or parameters, consider using function blocks designed for this purpose: ACR_ReadDintParameter, ACR_ReadRealParameter, ACR_ReadFlag, ACR_WriteDintParameter, ACR_WriteRealParameter, ACR_WriteFlag This will help avoid potential conflicts and save processing time for variables that only need to be written infrequently.
Using Direct Variables with HMI or Acrobasic
Direct variables can be used to exchange data with an HMI or Acrobasic program. If the value is to be written FROM the HMI to the PLC, then the variable should be designated as AT%B or AT%P rather than PW or BW. Because BW and PW vars are written every scan, it is likely that the value from the HMI will be overwritten before the PLC ever sees the change.
Example
BitToHMI : BOOL AT%BW128;
BitFromHMI : BOOL AT%B129;
ParmToHMI : BOOL AT%PW100;
ParmFromHMI : BOOL AT%P100;
In the case where both a program and the HMI need to modify a variable, again use the AT%B or AT%P designators and then in the PLC program use a FB to modify the value in the program: ACR_WriteDintParameter, ACR_WriteRealParameter, ACR_WriteFlag
Restricted Flags
The following flags CANNOT BE ASSIGNED AS AT%BW (read/write), a Moving Segment Error will result.
These bits can still get set thru the PLC, use MC_WriteBoolParameter or ACR_WriteFlag
Bit Range |
Desc |
ErrorID |
|
768 |
1023 |
Primary Axis Flags (Axes 0-7) |
3 |
7680 |
7935 |
Primary Axis Flags (Axes 8-15) |
3 |
512 |
767 |
Primary Master Flags (Masters 0-7) |
3 |
40 |
47 |
Drive Enable Outputs |
2 |
48 |
55 |
Drive Reset Outputs |
2 |
56 |
63 |
LEDs |
2 |
64 |
71 |
Drive Fault Inputs |
2 |
96 |
103 |
LEDs |
2 |
112 |
115 |
Trigger captures |
3 |