Macro Language
Valid for S300, S700
Table of Contents
Macro language
The user can write an application program which will be running inside the S300/S700. The language is a subset of IEC 601131-3 structured text. Because this is very similar to BASIC or C an application engineer does not need much training to write a simple program. The system uses an internal compiler which allows fast program execution. The program source is stored in one segment of the amplifier's flash memory (actual 60kByte) and will be compiled automatically during the boot phase. If the amplifier is not enabled the program can be modified and recompiled.
The development tool MacroStar supports the engineer to write a program.
Program flow control
Program flow control gives a system most of its "intelligence", the ability to evaluate conditions and take different actions depending on the outcome. The macro language supports IF .. THEN ELSE END_IF, WHILE .. DO END_WHILE, REPEAT .... UNTIL, GOTO and FOR .......
IF
The basic program flow control uses the syntax:
IF <expression> THEN
.....
ELSE
...
END_IF ;
The ELSE path is optional and can be skipped. The word IF is followed by an expression, which can include comparisons between variables and/or a constant or a simple statement. For IF ... THEN, ELSE and END_IF should always used a separate source code line and it is recommended to use tabs or spaces to structure the source code.
IF Example:
IF var1=12 THEN
checks whether var1 is equal 12 (True) or not (false).
If the expression is true the program path between THEN and ELSE (if used) or END_IF is executed. If the expression is false the optional path between ELSE and END_IF will be processed.
#IF
WHILE
The
statement allows structured looping. The condition is handled in the same way its handled in the IF .. THEN statement. Looping (jumping back) is only allowed in the task PLCMAIN.
GOTO
The statement GOTO <Label> allows the servo amplifier to execute the program out of the sequential order. The word GOTO followed by a label will force the program execution to jump to the line with that label. It is possible to create loops that will never end. Therefore in all real time tasks a jump back is not allowed. Looping and jumping back is only allowed in the task PLCMAIN. If possible it is recommended not to use the GOTO statement to create more structured programs.
Variables
Variables are names that represents data values used in the macro statements. The value represented by a variable can be assigned by setting it equal to a constant, or it can be the result of calculations in the program. All variables have to be defined before they can be used.
Variable names can be defined with a max length of 10 characters. Variables names may not be the same as macro keywords, operator names and function names. The characters used to form variable names are the alphabet and the numbers 0-9. The first character of the name must be a letter. Variable names must always be written in capital letters!
The macro language offers the user different variable types which can be stored in different RAM areas. All variables are signed and global (like BASIC). Floating point and array are not implemented. Nearly all calculations are sign extended to 32 bit and are processed with 32 bit operations.
BYTE
WORD
LONG
DLONG
Predefined User Variables
There are 16 predefined general purpose variables of type LONG that can be used in the program. They can be changed e.g. via the RS232 interface like all other ASCII parameters, are saved with the standard SAVE command and stored in the parameter file.
Variable Name
|
CAN Object Number
|
Profibus PNU
|
---|---|---|
DPRVAR1
|
36A6h or 2090h Subindex 1 (see CANOpen manual)
|
2022d
|
DPRVAR2
|
36A7h or 2090h Subindex 2
|
2023d
|
...
|
|
...
|
DPRVAR8
|
36ADh or 2090h Subindex 8
|
2029d
|
DPRVAR9
|
36AEh or 2030h Subindex 1 (s. CANOpen manual)
|
2030d
|
DPRVAR10
|
36AFh or 2030h Subindex 2
|
2031d
|
...
|
...
|
...
|
DPRVAR16
|
36B9h or 2030h Subindex 8
|
2037d
|
Beginning with firmware version 3.62 there 16 additional user variables:
Variable Name
|
CAN Object Number
|
Profibus PNU
|
---|---|---|
DPV17
|
37BCh
|
1900 Index 17
|
DPV18
|
37BDh
|
1901 Index 17
|
...
|
...
|
...
|
DPV32
|
37CBh
|
1915 Index 17
|
Access to ASCII Parameters
The following functions allow access to all ASCII parameters and functions and must be used in the MAIN or in the INIT task only because they are time consuming.
//write content of user variable TEMPVAR1 to ASCII parameter MTMUX
XWRITE('MTMUX',TEMPVAR1);
//read value of PGEARO and store in user variable MYPGEARO
XREAD('PGEARO',MYPGEARO);
//create a motion task using the ORDER command
COMMAND('ORDER 192 49000 2800 8192 50 50 0 0 0 0');
Expressions and Operations
Arithmetic/shift operators
Relational operators
Logical operators
Binary operators
MULDIV Function
Subroutines
LIMITW(OUT ,IN ,MAX ) ;
This subroutine will check the value of the variable IN and will reduce it to +/- MAX if the value is greater than MAX. The result is stored in the variable OUT. All variables are passed as pointers (like FORTRAN) and the subroutine is always inline coded. This makes code execution very fast, but for example recursion (calling itself) is not allowed.
FUNCTION (CALCOPMODE) ;
This calls the subroutine CALCOPMODE. It is not possible to pass parameters.
COMMAND ('OPMODE 0')
will call the ASCII ServoStar Command interpreter to execute a switch to opmode 0. This is the easiest, but also the slowest way to execute subroutines. It should be only used in the application task PLCMAIN
LONG YEAR ;
YEAR := 2011;
PRINTF ('Hello world in the year %d\n',YEAR) ;
words like a subset of the 'C' printf function. It will show on the terminal:
Hello world in the year 2011
There are in addition to the control string up to three parameters possible. The parameter type must be of the type LONG. Constants and other types are not supported yet. PRINTF should be only used in the application task PLCMAIN
Time / Performance restrictions
PLC program
|
Load factor
|
---|---|
PLC62
|
256*number of line
|
PLC250
|
64*number of line
|
PLC1
|
16*number of line
|
PLC4
|
4*number of line
|
PLC16
|
1*number of line
|
PLCMAIN
|
-
|
PLCINIT
|
-
|
Commands and Functions
- Functions for Motion
- Functions for In- / Outputs
- Functions for runtime environment
- Functions for programming environment
- Functions for multi axis systems (CANopen)
- Functions for position latching