Solutions: IEC Programming For Nodes
Solutions: IEC Programming For Nodes
Solutions: IEC Programming For Nodes
Ed. 13 - English
IEC programming for nodes
Doc. MS270928
Ed. 13 - English - 28 Oct 2020
IEC programming for nodes www.cmz.it
IMPORTANT
CMZ SISTEMI ELETTRONICI S.r.l. reserves the right to make changes to the products de-
scribed in this document at any time without notice.
This document has been prepared by CMZ SISTEMI ELETTRONICI S.r.l. sole-
ly for use by its customers, guaranteeing that at the date of issue it is the most up-to-date doc-
umentation on the products.
Users use the document under their own responsibility and certain functions de-
scribed in this document should be used with due caution to avoid danger for person-
nel and damage to the machines.
No other guarantee is therefore provided by CMZ SISTEMI ELETTRONICI S.r.l., in par-
ticular for any imperfections, incompleteness or operating difficulties.
This document contains confidential information that is propri-
etary to CMZ SISTEMI ELETTRONICI S.r.l.. Neither the document nor the informa-
tion contained therein should be disclosed or reproduced in whole or in part, without ex-
press written consent of CMZ SISTEMI ELETTRONICI S.r.l..
Table of Contents
The purpose of this document is to describe how to use the provided functions and function
blocks in an IEC application program which runs into a drive.
Important
This manual does not teach how to write an IEC program, the standards and the syntax, there-
fore, rst of all, it is important to study an IEC programmer guide.
Important
This manual refers to the programs that can be written in the drives:
• ISD ;
• SVM ;
Ed 5
• Description of all the Io_ function blocks (see Section 4.3, “Peripherals management
(IO_)”).
• Example for the capture function management (see Section 4.5.2, “Capture example”).
Ed 6
Ed 7,8
• Description of safety conditions of the program for IBD. There is also a little example.
Ed 9
Ed 10
Ed 11
Ed 12
• Table A.3 wrong error codes deleted in the IO's function blocks error codes table.
• Various minor corrections.
Ed 13
• Appendix D, Objects of the programming: contents updated with the PROFINET ad-
dresses and with a note to introduce the "n" variable in the addressing.
• Various minor corrections.
The programming of the drives follows the IEC 61131-3 language standards and in the same
way the functions and function blocks dedicated to the motion control respect the PLCopen
standards.
Important
In the Program page of the SDSetup PC program is possible to write a program, build it, de-
bug it, and download it into the drive.
3.1. Main characteristics
The main characteristics of the programming are:
• type of variables: BOOL, SINT, USINT, INT, UINT, DINT, UDINT, BYTE, WORD,
DWORD;
• the application code runs into an unique task and it can be divided into some different
programs:
• main
this is the main program and it must always be present. At the beginning of each exe-
cution of the program the %I (input status) are updated with the value of the digital
inputs, and at the end of the program the %Q (output status) are copied to the digital
outputs;
Important
The measure of the "PROGRAM main" time execution can be read in the plc peri-
od variable (CAN index 0x4616.00, MODBUS 8773). The read value is the actu-
al measure, not the maximum. The "PROGRAM main" is continuously executed.
• exception
when a fatal error happens during the execution of an instruction, the application
code cannot run, therefore the main program execution is stopped. If the exception
program is present in the application code, it is called before the stop of the program
execution; in this way the programmer can insert in this program all the instructions,
functions and functions blocks that are necessary to guarantee a safe stop of the ap-
plication code execution. The exception program is usually executed only once. The
function SYS_Continue permits to continue the calling of the program. At the end of
the execution of this program the application is stopped. The function SYS_Restart
permits to restart the application with a partial or total reset, or with a rmware restart.
An example of fatal error is a division for zero. The object 8709 shows the reason of
the alarm (see Appendix A, Error codes list). It is possible to read it with the function
SYS_ReadObject.
Figure 3.2. exception
• resett
if the resett program is present in the application code, then it is called when a total
reset startup is executed. It runs before the resetp program. The total reset is usually
executed only at the rst startup of the application code, then the application has a
normal startup. In a normal startup the application skips the resett program and starts
from the resetp program and then calls the main program.
Figure 3.3. Startup
Warning
If the Section 3.2.4, “RETAIN variables” management is not ac-
tive, then at every switch off/switch on of the drive a total reset startup is execut-
ed, therefore the resett program is always executed.
Note
While commissioning the application program, the code is usually modi-
fied and then built and downloaded into the drive. At the end of the down-
load procedure the application program is launched. If the declaration of the Sec-
tion 3.2.4, “RETAIN variables” is changed compared to the previous down-
loaded application, then it is executed a total reset startup, else it is executed a nor-
mal startup.
• resetp
if the resetp program is present in the application code, then it is executed at every
startup.
• Intn
with (the second) n = 0 to 8, these are a group of programs which are launched when
a particular event happens. An event is joined to a program Intn by the function
SYS_EnEventInt.
Important
When the Intn program is running, the drive executes it as fast as possible. The ex-
ecution of the Intn program reduces the free resources of the system, there-
fore it is important to insert into these programs only the very essential instruc-
tions, functions and functions blocks.
• an Intn program is more important than the other programs, therefore when it is
launched it stops the execution of the programs that are running. The only excep-
tion is that an Intn program cannot break the execution of another Intn program.
• when the event happens there is a delay before the called Intn program is launched.
Note
When only one event happens, then the delay before the start of the execu-
tion of the called Intn program can be 400µs.
Note
The delay can increase when more events happen very close, be-
cause more Intn programs have to be executed at the same time. The rst char-
acteristic of the programming with SDSetup is that it has only one task, there-
fore it can execute only one program. It means that, while an Intn program is ex-
ecuting, the others stand waiting until it is finished.
• When more events happen very close, then more Intn programs have to be executed
at the same time. The priority of execution is defined by the number n of the Intn
program. The Intn program with the lowest n will be the rst one launched.
While an Intn program is running, the other events may anyway happen. The Intn
programs that is called by these events waits until the running program is executed.
When the execution of the Intn program finishes, the next launched Intn program
will be the Intn program which n value is the lowest. It is important to observe that
the priority is not the time of the rst happened event, but only the number n of
the Intn program.
• when an Intn program ends, the program can wait before restart the execution of
the application code.
Note
In the worst case the delay is 400µs.
• when an Intn program ends, and there is not any Intn program still on hold, then the
application code execution returns to the program which was stopped, restarting
from the instruction where it was been blocked;
• run
if the run program is present in the application code, then it is executed when the
application execution switches from "Stopped" to "Running" status. The execution is
started at the beginning of the main program. The status of the execution ("Stopped/
Running") is commanded from a button in the SDSetup, in the Program management
page.
• stop
if the stop program is present in the application code, then it is executed when the
application execution switches from "Running" to "Stopped" status.
The execution is stopped at the end of the main program. The status of the execution
("Stopped/Running") is commanded from a button in the SDSetup, in the Program
management page.
Warning
If the "PROGRAM main" is executing a loop that can-
not be solved, then it will be impossible to stop the program because the pro-
gram is always stopped at the end of the task.
2. after that, the program execution switches to "Stop". The main program arrives at the
end of its execution and then the program stop is called, if present.
IECSafeCondition
IECSafeCondition is an internal variable. It is a "semaphore" that can block the execution of the
action that has been requested by the System Manager.
For example: if an update of the IEC is requested through the SDSetup (download IEC), then
System Manager requests to the program to go in its safety condition. Now, if the semaphore is
yellow the action is blocked until it is set to "green".
The default value of IECSafeCondition is "green". In the program it is possible to change the value
of this variable through the SYS_WrIECSafeCondition function. See Section 4.5.3, “Example of
the management of a program safety condition request”.
• when the drive is in "Stopped" state and the program is downloaded, then the state re-
turns to "Running". At the end of the download, the IEC program is in Running state.
• When the drive executes an action that needs to put the program in the safety condition,
then at the end of this action the IEC state will return to the same status it was before
the action.
5. BOOL
Important
The CPU of the drives does not manage data type small-
er than a WORD (2 bytes). Bit and byte data type are not managed.
The internal management of the CPU, used in the drive, causes a different storing of the variables
in the memory:
• DINT, UDINT and DWORD : these variables always need 4 bytes (2 WORDS) and are
memorized at addresses that are multiple of 4 bytes;
• INT, UINT and WORD : these variables always need 2 bytes (1 WORD) and are mem-
orized at even addresses (multiple of 2 bytes);
• BOOL : these variables need only 1 bit. It is impossible to use only a bit of the memory,
the minimum size of usable memory is 1 byte. Therefore 1 BOOL needs 1 byte, but if
in the declaration of the variables the BOOL are near than they are packed into the same
byte at different bits.
a : BOOL ;
b : BYTE ;
c : BOOL ;
a : BOOL ;
c : BOOL ;
b : BYTE ;
"a" and "c" are packed into the same BYTE at bit 0 and 1, therefore the used memory is:
a,c(1 byte) + b(1 byte) = 2 bytes.
• the STRUCT and the instance of FUNCTION BLOCK respect the previous rules for
their internal variables, but they are always memorized at multiple of 4 bytes addresses.
a : INT ;
b : DINT ;
c : BYTE ;
d : UDINT ;
If the same variables are declared in the next order the memory used is 11 bytes:
b : DINT ;
d : UDINT ;
a : INT ;
c : BYTE ;
BYTE DESCRIPTION
0-3 variable "b"
4-7 variable "d"
8,9 variable "a"
10 variable "c"
• Return stack: it is used for variables that are declared in the "VAR, END_VAR" section
into a PROGRAM or FUNCTION. It is also used by the rmware of the drive for the
execution of the program;
• Stack: It is used by the rmware of the drive for the execution of the program;
• VAR GLOBAL: it is used for the variables that are declared in the "VAR_GLOBAL"
section;
• VAR GLOBAL RETAIN: it is used for all the variables declared in the "VAR_GLOBAL
RETAIN" section;
• %M, %I, %Q: it is used for the "VAR_GLOBAL" declared as %M, %I, %Q.
Note
The size of the memory resources depends on the product.
When the program is built the drive also executes an internal test of the memory usage. See also
Appendix C, How can I assess the memory usage?.
When the program is built the drive also executes an internal test of the memory usage. See also
Appendix C, How can I assess the memory usage?.
3.2.2.3. IBD
Memory IBD (byte)
Return stack (VAL LOCAL and internal usage) 1868
Stack 384
VAR GLOBAL 1076
VAR GLOBAL RETAIN 46
%M 512
%I 128(10 bit used)
%Q 128(7 bit used)
When the program is built the drive also executes an internal test of the memory usage. See also
Appendix C, How can I assess the memory usage?.
3.2.3. GLOBAL variables
The GLOBAL variables can be used by all programs of the application, their target is all the
application code (that means they can be used in all programs, function blocks, and functions in
the application code). They are declared at the top of the le and they are inserted into the section:
VAR_GLOBAL
a : INT ;
b AT %MW10 : INT ;
END_VAR
These variables can be monitored in the watch dialog (Program page) of the SDSetup.
A GLOBAL variable can be simple or can be memorized into the %M memory area.
These variables allow the programmer to x where to allocate them in the memory. In other
words the programmer defines how to distribute the variables into the memory. The memory
allocation of the other (GLOBAL and LOCAL) variables is automatically done by the compiler.
In particular the variables are:
The declaration of the size of the variable is made by adding one of the following letter after %M,
%I, %Q:
• X : bit;
• B : BYTE;
• W : WORD;
• D : DWORD
%MD0
%MW2 %MW0
%MB3 %MB2 %MB1 %MB0
%MX3.7 ... %MX3.0 %MX2.7 ... %MX2.0 %MX1.7 ... %MX1.0 %MX0.7 ... %MX0.0
Table 3.1. Memory struct
16#12345678
16#1234 16#5678
16#12 16#34 16#56 16#78
2#00010010 2#00110100 2#01010110 2#01111000
Table 3.2. Data in the memory
Note
The memory allocation of %M, %I, %Q variables has to respect the Section 3.2.1, “How the vari-
ables are stored into the memory” rules.
Note
A variable can not be both mapped in the exchange memory and defined as RE-
TAIN. If the %M, %I, %Q variables are defined as RETAIN, they cannot be saved into EEP-
ROM memory.
Here follows the description of how the data are exchanged between the drive and a PLC or a PC.
The size of the variables, exchanged through CANopen protocol, must be DWORD.
The %M exchange memory can be read or written by the CANopen protocol in this way:
• ...,
The size of the variables, exchanged through MODBUS protocol, can be WORD and DWORD.
The %M exchange memory can be read or written by the MODBUS protocol in this way:
• ....
3.2.4. RETAIN variables
The RETAIN variables are GLOBAL variables with the important characteristic of to hold the
values between a switch o and switch on of the drive. They are declared in a dedicated section,
outside of every program:
VAR_GLOBAL RETAIN
r : INT ;
END_VAR
The variables are distributed in the memory according with the rules written in Section 3.2.1,
“How the variables are stored into the memory”.
Important
In the SD series and IBD the available memory for the RETAIN variables is limited to 46 byte.
When the management of the RETAIN variables is active, then their values are reset only when
the start-up of the drive needs the execution of a total reset (see Section 3.1, “Main characteristics”
- program resett).
In the SD series the management of the RETAIN variables has to be enabled. It is enabled when
the MODBUS parameter 588 (CANopen 5FF0.9) value is 1 or 3. The default value of this pa-
rameter is 0, therefore if there are RETAIN variables the program has to write the parameter in
the resett program.
Important
In the SD series, when the management of the RETAIN variables is activated, then the min-
imum value of Logic supply voltage, that is needed to keep alive the drive, is 40V in-
stead of 20V (that is the minimum needed Logic supply voltage when management of the RE-
TAIN variables is not active). When the Logic supply voltage falls under these thresh-
olds, then the application program is stopped, and the drive will shutdown.
VAR_GLOBAL
hmi_var1 AT %MD0 : DINT ;
err : BOOL ;
END_VAR
VAR_GLOBAL RETAIN
var1 : DINT ;
END_VAR
PROGRAM main
var1 := hmi_var1;
END_PROGRAM
PROGRAM resetp
hmi_var1 := var1 ; (* at every startup load the RETAIN
variable into hmi_var1 *)
END_PROGRAM
3.2.5. CONSTANT objects
A CONSTANT object is a GLOBAL variable with the characteristic to keep its value constant.
It is declared in a VAR_GLOBAL section with the information CONSTANT added.
VAR_GLOBAL CONSTANT
1
This instruction line refers only to SD series products
r : INT := 1000 ;
END_VAR
3.2.6. LOCAL variables
The LOCAL variables are declared into a PROGRAM, FUNCTION or FUNCTION
BLOCK, in a "VAR - END_VAR" section.
VAR
l : INT ;
END_VAR
3.3. Instructions
This paragraph describes the instructions that are available to the programmer.
Instruction Description
Arithmetical operations (ANY_INT)
+, -, *, / classical mathematic operations.
MULDIV(p1,p2,p3) it executes (p1*p2)/p3 and the intermediate product (p1*p2) is internally expressed with a size
bigger than the size of the data p1, p2, p3: for example if p1, p2, p3 are DINT, UDINT (32 bit),
then the product p1*p2 is on 64bit; if p1,p2,p3 are INT, UINT (16bit) the product is internally
stored on 32 bit; if p1, p2, p3 are SINT, USINT (8 bit) the product is internally stored stored
on 16 bit.
p1 MOD p2 it returns the remainder of p1/p2.
p1 ** p2 it returns the power of p1 high to p2. The exponent p2 must be INT.
SQRT(p1) it returns the square root of p1.
MAX(p1, p2) it returns the biggest value between p1 and p2.
MIN(p1, p2) it returns the smallest value between p1 and p2.
ABS(p1) it returns the absolute value of p1.
Instruction Description
Operations dedicated to the bit elaboration (BOOL, BYTE, WORD, DWORD)
p1 AND p2 [OR, logical operations AND, OR and XOR
XOR]
SHL(p1, p2) it shifts the bits of p1 in the left direction, for as many "positions/bits" as declared in p2. When
it is executing the shift and the most significant bit "goes out" it is deleted.
SHR(p1, p2) it shifts the bits of p1 in the right direction, for as many "positions/bits" as declared in p2. When
it is executing the shift and the less significant bit "goes out" it is deleted.
ROL(p1, p2) it rotates the bit of p1 in the left direction for as many "positions/bits" as declared in p2. The
"rotate" operation is a special SHL(p1,p2) because when it is executing the shift and the most
significant bit "goes out" it is not deleted, as in the shift operation, and it is inserted in the less
significant position.
ROR(p1, p2) it rotates the bit of p1 in the right direction for as many "positions/bits" as declared in p2. The
"rotate" operation is a special SHR(p1,p2) because when it is executing the shift and the less
significant bit "goes out" it is not deleted, as in the shift operation, and it is inserted in the most
significant position.
Other instructions
RETURN it is used to jump at the end of the executing program.
EXIT it is used to finish (abort) the execution of the instructions written inside a ow control section.
For example, it is used to exit from the execution of an IF or a loop (WHILE...).
Flow control instructions
IF IF Expression THEN
ThenInstructionsList;
ELSE
ElseInstructionsList;
END_IF;
CASE n OF
1 : a:=a+1;
2 : b:=b+1;
11,12,13 : c:=c+1;
16..25,14,15,88..89 : d:=d+1;
29..32: e:=e+1;
ELSE
f:=f+1;
END_CASE;
Instruction Description
FOR FOR Variable := StartValue TO EndValue BY Increment DO
InstructionsList;
END_FOR;
Variable starts from StartValue. It executes InstructionsList, then adds to Variable the Incre-
ment. If Variable is less or equal than EndValue it repeats InstructionsList, else it continues the
execution of the program with the instruction after END_FOR.
WHILE WHILE Condition DO
InstructionsList;
END_WHILE;
It executes InstructionsList cyclically until the Condition is FALSE, when Condition becomes
TRUE it continues the execution of the program from the instructions after END_REPEAT;
output exclusivity the Done, Error, CommandAborted, Active outputs are mutually exclusive: only one at a
time can be TRUE on a FB. If Execute is TRUE, one of these outputs has to be TRUE. Only
one of the Done, Error, CommandAborted and Active outputs is set at the same time.
output status the Done, InVelocity, Error, ErrorID and CommandAborted outputs are reset with
the falling edge of Execute. However the falling edge of Execute does not stop or even influ-
ence the execution of the actual FB cycle. It must be guaranteed that the corresponding outputs
are set for at least one cycle if the situation (that makes them to be set) occurs, even if Execute
is reset before the FB execution has been completed. If an instance of a FB receives a new Exe-
cute before its cycle ends (as a series of commands on the same instance), the FB execution is
interrupted and restarts, so the FB will not return any feedback, like Done or CommandAborted,
of the previous action.
input parameters the parameters are used on the rising edge of the Execute input. To modify an input it is nec-
essary to change the input parameter(s) and to restart the FB.
sign rules the Velocity, Acceleration, Deceleration and Jerk are always positive values. Po-
sition can be both positive and negative.
error handling behav- all function blocks have two outputs, which deal with errors that can occur while executing that
ior function block. These outputs are defined as follows:
Error : the rising edge of Error informs that an error has occurred during the execution of the
function block;
ErrorID : Error number code.
Error types can be for example: parameters out of range, state machine violation attempted.
Done, InVelocity mean successful completion, so these signals are logically exclusive with
Error.
behavior of Done out- The Done output is set when the commanded action has been successfully completed. When
put multiple function blocks are working in sequence on the same axis, the following may apply:
if the movement on an axis is interrupted with another movement on the same axis without
having reached the final goal of the rst one, the Done of the rst FB will not be set.
behavior of Active every FB can have an output Active, reflecting that the FB has not finished its cycle. Active
output is SET at the rising edge of Execute and RESET when one of the outputs Done, Aborted,
or Error is set. It is recommended that this FB is kept in the active loop of the application
program for at least the Active TRUE status duration, because the outputs may still change.
behavior of Command- CommandAborted is set, when a commanded motion is interrupted by another motion com-
Aborted output mand. The reset-behavior of CommandAborted is like the one of Done. When CommandAbort-
ed occurs, the other output-signals such as InVelocity are reset.
input Enable the Enable is level sensitive. It means that the function block does not start only at the rising
edge detection of this input, but its cycle will be repeated as long as Enable is kept on high level.
Table 3.3. General rules
The behavior between the Execute and the outputs in a MC_MoveAbsolute function block
is as follows:
example 1 : the movement is aborted, therefore the output CommandAborted becomes TRUE;
example 2 : the function block has had an error;
example 3 : the movement has been completed successfully. The Done is TRUE only for one
time (cycle) because the input Execute is already FALSE;
example 4 : the movement has been completed successfully. The Done remains TRUE until the
input Execute is TRUE.
This chapter includes all the functions and function blocks that are necessary to write an IEC
program.
SYS_EnEventInt
It activates the management of an event in an INT PROGRAM.
Synopsis
Return value
Value of type BOOL
If 0 then there are no errors.
Parameter
EventType
Value of type INT
Event type:
• SYS_EVENT_TIMER (11) : int called every programmed time. This elapsing time
reference is written into 0x461A.02 (8722). This time is written into 461A.01
(8720)1.
Note
For a better programming it is suggested to use the CONSTANT names in-
stead of the related numbers.
IntNumber
Value of type INT
Number of the interrupt program INT, that is called if and when the EventType hap-
pens.
Description
it activates the management of a programmed event on an INT PROGRAM. When the event
happens, the INT PROGRAM is called.
The timer is set on 100 ms, but the drive approximates it to 500 ms. The result is that the INT
PROGRAM intervenes according to this rule:
0..400 ms = 0 ms
500..900 ms = 500 ms
...
2
This event is valid only for BD drives.
SYS_DisEventInt
It deactivates the management of an event on an INT PROGRAM.
Synopsis
Return value
Value of type BOOL
If 0 then there are no errors.
Parameter
EventType
Value of type INT
Event type to be deactivated. See SYS_EnEventInt.
Description
it deactivates the management of a programmed event on an INT PROGRAM.
SYS_ReadTime
It returns the system time in milliseconds.
Synopsis
Return value
Value of type UDINT
Actual time of the system.
Description
It returns the system time in milliseconds.
SYS_WriteObject
It writes a parameter of the drive.
Synopsis
Return value
Value of type BOOL
If 0 then there are no errors
Parameter
ParameterNumber
Value of type UDINT
It is the MODBUS address of the parameter (see Appendix B, Parameters table).
Value
Value of type DINT
Value to write in the selected parameter.
Description
It writes Value in the parameter with address ParameterNumber.
Important
Both SYS_ReadObject and SYS_WriteObject functions can access to the addresses that are re-
lated to the exchange area, but only by WORD and not by DWORD data type.
SYS_ReadObject
It reads a parameter of the drive.
Synopsis
Return value
Value of type DINT
it reads the value of a specific parameter.
Parameter
ParameterNumber
Value of type UDINT
It is the MODBUS address of the parameter (see Appendix B, Parameters table).
Description
It reads the parameter which address is ParameterNumber.
Important
Both SYS_ReadObject and SYS_WriteObject functions can access to the addresses that are re-
lated to the exchange area, but only by WORD and not by DWORD data type.
SYS_Restart
It permits to restart the application.
Synopsis
Return value
Value of type BOOL
If 0 then there are no errors
Parameter
Type
Value of type DINT
Type of restart:
• 2 : it simulates a switch o-switch on of the drive. The restart will be applied 10 sec-
onds after the execution of the command. In these 10 seconds the PLC remains on
STOP state.
Note
With IBD, before to execute SYS_Restart(2) it is necessary to put the dri-
ve in the safety conditions. See the manual of the IBD for further details.
Description
It permits to restart the application. It is usually used into PROGRAM EXCEPTION, to avoid
the machine blocking due to the program lock when an exception happens.
SYS_Continue
It requests to continue the execution of program EXCEPTION.
Synopsis
Return value
Value of type BOOL
If 0 then there are no errors.
Description
The PROGRAM exception is usually executed only one time, but sometimes when an excep-
tion happens, it is necessary to run a safety procedure. For example, to move the axis in a safety
position and then switch o the digital outputs: in this case, the PROGRAM exception has to be
executed several times. If this function is called, then the PROGRAM exception does not stop
its execution but repeat it once again.
SYS_MemoryToEeprom
It manages the saving and restoring of some %M into the EEPROM.
Synopsis
FUNCTION_BLOCK SYS_MemoryToEeprom
VAR_INPUT
Execute : BOOL ;
LoadStore : BOOL ;
Index : UINT;
Lenght : UINT;
END_VAR
VAR_OUTPUT
Done : BOOL ;
Active : BOOL ;
Error : BOOL ;
ErrorID : DINT ;
END_VAR
Parameter
Execute
Value of type BOOL
At the rising edge it starts to copy the memory.
LoadStore
Value of type BOOL
Direction of the copy:
Index
Value of type UDINT
It is the starting address of the %M to manage.
Lenght
Value of type UINT
It is the length of the area to move.
Done
Value of type BOOL
Flag that is set to TRUE when the copy operation is finished.
Active
Value of type BOOL
Flag that is set to TRUE when the procedure is in progress.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred in the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Description
The RETAIN area of the drive has few bytes, but sometimes it is important to save into EEP-
ROM some variables. This function block permits to save a part of the %M memory area into the
EEPROM, and also to restore a part of the %M area with values saved into EEPROM. The part
of the managed %M memory area is declared with its start address (Index) and with its Lenght.
SYS_RdIECSafeCondition
It reads the value of the semaphore IECSafeCondition.
Synopsis
Return value
Value of type INT
It is the state of the IECSafeCondition semaphore (0 = green, 1 = yellow, 2 = red).
Parameter
Event
Value of type DINT
It has to be 0. It means 'all events'.
Description
It reads the state of the semaphore IECSafeCondition. See the example Section 4.5.3, “Example
of the management of a program safety condition request”.
SYS_RqsIECSafeCondition
It returns TRUE when the event is requesting to the program to go in safe condition.
Synopsis
Return value
Value of type BOOL
TRUE means that the system manager is requesting to the program to go in its safety condition
before to continue the action referred to the event.
Parameter
Event
Value of type DINT
It is the reference number of the event that is making the request.
Description
It informs when the system manager is requesting to the program to go in its safety condition
before to continue the action referred to the event. It is useful when the IECSafeCondition is
"yellow" (see SYS_WrIECSafeCondition).
In this situation when the function SYS_RqsIECSafeCondition returns TRUE, the program
can execute all the operations to put the application in a well defined condition and then it
switches the semaphore to "green". After that, the safety condition for the IEC program is reached
and the system manager can continue the execution of the action referred to the event.
See the example Section 4.5.3, “Example of the management of a program safety condition request”
SYS_WrIECSafeCondition
It writes the internal semaphore IECSafeCondition.
Synopsis
Return value
Value of type DINT
If 0 then there are no errors
Parameter
Event
Value of type DINT
It has to be 0. It means all events.
State
Value of type INT
It is the value to write in IECSafeCondition semaphore:
• [0] this value switches the semaphore to "green" state, therefore the execution of the
event is allowed;
• [1] this value switches the semaphore to "yellow" state. When the system manager re-
quests to put the program in safety condition, this condition suspends the execution
of the event until the program sets the semaphore to "green" (State = 0).
• [2] this value switches the semaphore to "red" state, therefore the execution of the
event is aborted.
Description
It writes the state of the internal semaphore IECSafeCondition. When the State is [1], the IEC
program wants to suspend the execution of the event that has requested the safety condition.
See the example Section 4.5.3, “Example of the management of a program safety condition request”
4.2.1. Axis status
The axis can be in one of the following status:
• INITIALIZATION : when the axis is in this status, the program is initializing its vari-
ables;
When the axes program starts the axis is always in INITIALIZATION status.
When the drive is "ReadyToSwitchOn" (see Section 4.2.2.1, “How digital inputs and outputs
manage the drive”) the axis status automatically becomes STANDSTILL.
When the axis has an error, its status becomes ERRORSTOP and the behavior of the motor
depends on the drive management.
Note
• when the motor arrives to an hardware or software limit switch, the move-
ment is stopped;
• for all the other alarms, the drive switches o the torque of the motor.
When a motion function block is launched, then the axis changes its status according to the
following relations:
4.2.2. Drive status
The drive status is described by the ReadyToSwitchOn, Run, Fault digital outputs (see Sec-
tion 4.2.2.1, “How digital inputs and outputs manage the drive”). It can be read by MC_Read-
DriveStatus.
Digital Inputs:
• Run : it is TRUE when the drive is switched on (the power stage of the drive is switched
on).
• Fault : it is TRUE when the drive has an alarm. When it is TRUE the digital inputs
ReadyToSwitchOn and Run are FALSE.
Digital Outputs:
• SwitchOn : when it becomes TRUE, the controller commands the drive to switch on
the power stage;
• Reset : on the rising edge, the axes program tries to recover the drive from a Fault situa-
tion;
• Brake : when it is TRUE, the motor can freely run, when it is FALSE the brake is on,
therefore the motor is blocked. The brake control can be automatically managed from
the axes program or be driven in manual mode.
In the following diagram there is the description of the SwitchOn timing procedure with auto-
matic Brake control:
The next diagram describes the drive behavior when there is an alarm. The Fault signal becomes
TRUE and immediately the Brake, Run and ReadyToSwitchOn I/Os are set to FALSE.
Figure 4.4. Fault management
Important
For SD series there is not the brake management.
4.2.3. Axis functionalities
This section describes some axis functionalities.
• when the axis exceeds the positive limit with a positive velocity, then the axis switches to
the ERRORSTOP state with Axis is arrived at a SW limit switch error code;
• when the axis exceeds the negative limit with a negative velocity, then the axis switches
to ERRORSTOP state with Axis is arrived at a SW limit switch error code.
1. to configure the position limit (in the SYS_WriteObject the needed parameters num-
bers are: 4327, 4329);
2. to activate the position limit management (for the SYS_WriteObject the needed para-
meter number is 4326).
• when the axis exceeds the positive limit with a positive velocity then the axis switches to
ERRORSTOP state with Axis is arrived at a limit switch error code;
• when the axis exceeds the negative limit with a negative velocity then the axis switches to
ERRORSTOP state with Axis is arrived at a limit switch error code.
To use a HW limit is necessary to configure which inputs are the positive and negative limits.
4.2.3.3. Emergency ramp
This ramp is executed when the motor arrives to an hardware or limit switch. It is configured
with the parameter number 4343.
AXIS_REF
It is the axis reference.
Synopsis
TYPE
AXIS_REF : STRUCT
num : <type>INT</type>;
END_STRUCT;
END_TYPE
Elements
num
Value of type INT
It is an internal number. In a project each axis has an identification number, different
from the other axes.
Description
This Data Type is the axis reference. It is used to declare an axis in the project. It is important to
initialize the struct with Num = MC_REF_AXIS_MAIN.
MC_EmergencyStop
It commands an emergency ramp stop. It is a non-controlled stop.
Synopsis
FUNCTION_BLOCK MC_EmergencyStop
VAR_IN_OUT
Axis : <type>AXIS_REF</type> ;
END_VAR
VAR_INPUT
Execute : <type>BOOL</type> ;
Deceleration : <type>DINT</type> ;
Jerk : <type>DINT</type> ;
END_VAR
VAR_OUTPUT
Done : <type>BOOL</type> ;
CommandAborted : <type>BOOL</type> ;
Error : <type>BOOL</type> ;
ErrorID : <type>DINT</type> ;
END_VAR
Parameter
Axis
Value of type AXIS_REF
Axis reference
Execute
Value of type BOOL
At the rising edge the axis starts to move
Deceleration
Value of type DINT
Value of deceleration [axis unit per second]
Jerk
Value of type DINT
It must be 100.
Done
Value of type BOOL
Zero velocity is reached.
CommandAborted
Value of type BOOL
Flag that is set to TRUE if the command is aborted by another motion command.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred in the function block
ErrorID
Value of type DINT
Error identification code (see Table A.1)
Description
This function block commands an uncontrolled motion stop and transfers the axis to the
EMERGENCYSTOPPING status. The program stops the axis in open loop mode. It aborts
any motion function block execution in progress. With the Done output set, the state is trans-
ferred to STANDSTILL. While the axis is in state EMERGENCYSTOPPING status, no other
FB can perform any motion on the same axis. If the MC_Stop is launched and the axis is already
in STANDSTILL, then the Done output is immediately set to TRUE.
MC_Gear
It manages a gear movement between an encoder and the axis.
Synopsis
FUNCTION_BLOCK MC_Gear
VAR_IN_OUT
Master : Enc_Ref;
Slave : AXIS_REF;
END_VAR
VAR_INPUT
StartGear : BOOL ;
Execute : BOOL ;
Mode : WORD ;
RatioInNumerator : DINT ;
RatioInDenominator : DINT := 1000;
RatioEndNumerator : DINT ;
RatioEndDenominator : DINT := 1000;
MasterSpace : DINT ;
InpStart : BOOL ;
MasterStart : DINT ;
END_VAR
VAR_OUTPUT
InGear : BOOL ;
Active : BOOL ;
CommandAborted : BOOL ;
Error : BOOL ;
ErrorID : DINT ;
State : INT ;
SlaveStart : DINT ;
END_VAR
Parameter
Master
Value of type Enc_Ref
Encoder master reference of the gear movement. The Master has to be IO_RE-
F_ENC_AUXILIARY (see ENC_REF). In this way the Master is the auxiliary encoder.
In order to use the internal simulated master, the auxiliary master configuration must
be changed.
Slave
Value of type AXIS_REF
Axis slave reference of the gear movement.
StartGear
Value of type BOOL
At the rising edge it starts the gear movement between the encoder and the axis. When
it is TRUE the status of the outputs of the function block are managed. At the rising
edge it executes the action of the Execute input, too.
Execute
Value of type BOOL
When the StartGear input is TRUE, at the rising edge it makes active the change of
the ratio of the gear movement. The characteristics of the change are defined by the
other inputs.
Mode
Value of type WORD
It defines the mode of change of the ratio of the gear movement. One of the bits 1, 2,
3, 4 must be set.
• bit 1 : if it is 1 than the change of the ratio from initial to end ratio is started at the
rising edge of the Execute input;
• bit 2 : if it is 1 than the change of the ratio from initial to end ratio is started at the
rising edge of the InpStart input;
• bit 3 : if it is 1 than the change of the ratio from initial to end ratio is started when the
master position is greater than the MasterStart input. It is used when the master
has a positive velocity;
• bit 4 : if it is 1 than the change of the ratio from initial to end ratio is started when
the master position is less than the MasterStart input. It is used when the master
has a negative velocity.
RatioInNumerator
Value of type DINT
It is the numerator of the initial ratio. The range of the admitted values is 1 ÷ 32768.
RatioInDenominator
Value of type DINT
It is the denominator of the initial ratio. The range of the admitted values is 1 ÷ 32768.
RatioEndNumerator
Value of type DINT
It is the numerator of the gear movement ratio at the end of the change. The range of
the admitted values is 1 ÷ 32768.
RatioEndDenominator
Value of type DINT
It is the denominator of the gear movement ratio at the end of the change. The range
of the admitted values is 1 ÷ 32768.
MasterSpace
Value of type DINT
It is the master space within the change of the ratio will be done. The minimum value
is 1.
InpStart
Value of type BOOL
When Mode has bit 2 = 1 , then the change of the ratio starts at the rising edge of In-
pStart.
MasterStart
Value of type DINT
When Mode has bit 3 or 4 = 1 , this input defines the master position threshold for the
change of the ratio.
InGear
Value of type BOOL
This ag is set to TRUE when the axis is moving in gear movement with ratio equals to
RatioEndNumerator/RatioEndDenominator.
Active
Value of type BOOL
CommandAborted
Value of type BOOL
Flag that is set to TRUE if the command is aborted by another motion command.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred in the function block
ErrorID
Value of type DINT
Error identification code (see Table A.1)
State
Value of type INT
State of the procedure for the change of the ratio:
• 0 : not active;
• 1 : it is waiting for the event which triggers the start of the ratio change;
• 2 : the State passes to this number when Mode has bit 3 or 4 = TRUE. In this state
it is waiting that the master position becomes higher (or lower) than MasterStart;
SlaveStart
Value of type DINT
The slave position at the beginning of the changing of the gear movement ratio.
Description
This function block manages the gear movement between a master encoder and the axis. It has
two functions:
• while the axis is moving in gear mode, with this function block it is possible to change
the gear ratio between the master and the slave movement. There are several modes to
manage the change. The changing can start from the actual ratio or from a defined ra-
tio, and can also start immediately at the rising edge of the Execute input or when a
particular condition happens. All these characteristics are defined by the Mode, InpS-
tart and MasterStart inputs. The initial ratio, when it is necessary, is declared with
RatioInNumerator/RatioInDenominator. The gear ratio at the end of the change is
RatioEndNumerator/RatioInDenominator. The change of the ratio, from the initial
to the end one, is always executed in MasterSpace master units.
MC_Home
It executes a selected homing procedure.
Synopsis
FUNCTION_BLOCK MC_Home
VAR_IN_OUT
Axis : AXIS_REF;
END_VAR
VAR_INPUT
Execute : BOOL ;
Position : DINT;
HomingMode: INT;
VelocitySearchSwitch : DINT;
VelocitySearchZero : DINT;
END_VAR
VAR_OUTPUT
Done : BOOL ;
CommandAborted : BOOL ;
Error : BOOL ;
ErrorID : DINT ;
END_VAR
Parameter
Axis
Value of type AXIS_REF
Axis reference
Execute
Value of type BOOL
At the rising edge it starts the action.
Position
Value of type DINT
It is the absolute position when the reference signal is detected.
HomingMode
Value of type INT
It selects the homing type:
• 1: homing against the switch connected to home input (the limit switch detection
interrupts the procedure);
• 2: homing against the switch connected to home input and then searching of the
"zero mark" encoder reference pulse (the limit switch detection interrupts the proce-
dure); for the SD drives it is allowed only to the ones which feedback is an incremen-
tal encoder;
• 3: homing against the switch connected to home input, with the limit switch man-
agement;
• 4: homing against the switch connected to home input and then searching of the
"zero mark" encoder reference pulse, with the limit switch management; for the SD
drives it is allowed only for the ones which feedback is an incremental encoder;
• 5: set the position of the axis equals to the Input Position without any movement;
• 6: the axis searches the encoder reference pulse "zero mark" (the limit switch detec-
tion interrupts the procedure); for the SD drives it is allowed only for the ones which
feedback is an incremental encoder;
• 7: homing against the switch connected to the hw limit input without "zero mark"
reference pulse;
• 8: homing against the switch connected to hw limit input and then searching of
the "zero mark" encoder reference pulse; for the SD drives it is allowed only for the
ones which feedback is an incremental encoder;
• 101: it is equal to 1, but at the end of the procedure the offsets are saved in the
permanent memory so that the position will be correctly restored after a reboot of
the drive. It is allowed only for SD drives which feedback is an absolute encoder;
• 103: it is equal to 3, but at the end of the procedure the offsets are saved in the
permanent memory so that the position will be correctly restored after a reboot of
the drive. It is allowed only for SD drives which feedback is an absolute encoder;
• 105: it is equal to 5, but at the end of the procedure the offsets are saved in the
permanent memory so that the position will be correctly restored after a reboot of
the drive. It is allowed only for SD drives which feedback is an absolute encoder;
• 107: it is equal to 7, but at the end of the procedure the offsets are saved in the
permanent memory so that the position will be correctly restored after a reboot of
the drive. It is allowed only for SD drives which feedback is an absolute encoder;
VelocitySearchSwitch
Value of type DINT
It is the velocity used to move the axis toward the limit switch. It has to be a value dif-
ferent from zero.
VelocitySearchZero
Value of type DINT
In the HomingType = (1),(3) it is the velocity used to move the axis out of the micro,
while in the modes (2),(4) it is the velocity used to move the axis toward the reference
pulse of the encoder. It has to be a value different from zero.
Done
Value of type BOOL
Flag that is set to TRUE when the homing procedure is correctly finished.
CommandAborted
Value of type BOOL
Flag that is set to TRUE if the command is aborted by another motion command.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Description
This function block starts an homing procedure. An homing procedure is used to get a reference
position in a defined real condition. The possible procedures are:
• 1, 3, 101, 103:
1. the axis moves toward the home switch with VelocitySearchSwitch velocity;
2. when the axis reaches the home switch, the axis starts to move with Veloci-
tySearchZero velocity;
3. when the axis leaves the home switch, the axis position is set to the Position value
and then the axis is stopped.
the difference between mode 1 and 3 is the axis behavior if the movement reaches a limit
(hw limit switch or software limit) while the homing procedure is in progress. Further-
more in modes 1 the axis goes in ERRORSTOP, instead in mode 3 the axis maintains
the HOMING state and it reverts the movement in the opposite direction until the axis
nds the home switch.
• 2, 4, 102, 104:
2. when the axis reaches the home switch, the axis starts to move with Veloci-
tySearchZero velocity;
3. when the axis reaches the reference pulse of the encoder, the axis position is set to
the Position value and then it is stopped.
the difference between mode 2 and 4 is the axis behavior if the movement reaches a limit
(hw limit switch or software limit) while the homing procedure is in progress. Further-
more in modes 2 the axis goes in ERRORSTOP, instead in mode 4 the axis maintains
the HOMING state and it reverts the movement in the opposite direction until the axis
nds the home switch.
• 5:
the axis position is set to the Position input value without any movement.
• 6:
2. when the axis reaches the reference pulse of the encoder, the axis position is set to
the Position input value and then it is stopped.
• 7: The procedure is equal to the number 1, but at the beginning the axis moves toward
the hw limit;
• 8: The procedure is equal to the number 2, but at the beginning the axis moves toward
the hw limit.
When the homing procedure is in progress the axis state is HOMING. When the procedure ends,
the Done output is set to TRUE and the axis state becomes STANDSTILL.
Important
The homing procedure is allowed when the axis state is STANDSTILL.
MC_MoveAbsolute
It moves the axis to an absolute position.
Synopsis
FUNCTION_BLOCK MC_MoveAbsolute
VAR_IN_OUT
Axis : <type>AXIS_REF </type>;
END_VAR
VAR_INPUT
Execute : <type>BOOL</type> ;
Position : <type>DINT</type> ;
Velocity : <type>DINT</type> ;
Acceleration : <type>DINT</type> ;
Deceleration : <type>DINT</type> ;
Jerk : <type>DINT</type> ;
Direction : <type>INT</type> ;
END_VAR
VAR_OUTPUT
Done : <type>BOOL</type> ;
CommandAborted : <type>BOOL</type> ;
Error : <type>BOOL</type> ;
ErrorID : <type>DINT</type> ;
END_VAR
Parameter
Axis
Value of type AXIS_REF
Axis reference
Execute
Value of type BOOL
At the rising edge it starts to move the axis.
Position
Value of type DINT
It is the target absolute position.
Velocity
Value of type DINT
It is the target velocity.
Acceleration
Value of type DINT
It is the acceleration which the drive uses to start the axis movement in order to reach
the target Velocity.
Deceleration
Value of type DINT
It is the deceleration which the drive uses to stop the axis.
Jerk
Value of type DINT
It must be 100.
Direction
Value of type DINT
It is not used.
Done
Value of type BOOL
Flag that is set to TRUE when the movement is finished.
CommandAborted
Value of type BOOL
Flag that is set to TRUE if the command is aborted by another motion command.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Description
This function block moves the axis from the current position to the target Position.
When the movement is executing the axis state is DISCRETEMOTION. When the procedure
finishes the output Done is set to TRUE and the axis state becomes STANDSTILL. If the
MC_MoveAbsolute is launched and the axis is in STANDSTILL and it is already in the target
position then the output Done is set to TRUE immediately.
Figure 4.5. position movement
• end velocity: it is the velocity in the final part of the movement. It is useful when the
end of the movement has to be execute in a "softly mode", that means that the speed near
the target position is defined by the programmer and not automatically calculated by the
drive;
• anticipation of end position: it is the space within the movement has to run with end
velocity;
• when the axis has a velocity not equal to zero, and the target position is too close to the
actual position, the position movement is solved with a profile which guarantees the de-
celeration and describes an overshoot.
MC_MoveVelocity
It moves the axis with a target velocity.
Synopsis
FUNCTION_BLOCK MC_MoveVelocity
VAR_IN_OUT
Axis : <type>AXIS_REF</type> ;
END_VAR
VAR_INPUT
Execute : <type>BOOL</type> ;
Velocity : <type>DINT</type> ;
Acceleration : <type>DINT</type> ;
Deceleration : <type>DINT</type> ;
Jerk : <type>DINT</type> ;
Direction : <type>INT</type> ;
END_VAR
VAR_OUTPUT
InVelocity : <type>BOOL</type> ;
CommandAborted : <type>BOOL</type> ;
Error : <type>BOOL</type> ;
ErrorID : <type>DINT</type> ;
END_VAR
Parameter
Axis
Value of type AXIS_REF
Axis reference
Execute
Value of type BOOL
At the rising edge it starts to move the axis.
Velocity
Value of type DINT
Acceleration
Value of type DINT
It is the acceleration which the drive uses to start the axis movement in order to reach
the target Velocity.
Deceleration
Value of type DINT
It is the deceleration which the drive uses to stop the axis
Jerk
Value of type DINT
It must be 100.
Direction
Value of type DINT
It is not used.
In Velocity
Value of type BOOL
Flag that is set to TRUE when the theoretical profile arrives to target Velocity.
CommandAborted
Value of type BOOL
Flag that is set to TRUE if the command is aborted by another motion command.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Description
This function block moves the axis to target Velocity.
When the movement is executing the axis state is CONTINUOUSMOTION. If the target veloc-
ity is set to 0, when the movement reaches the target velocity (in other words, it stops) the axis
changes its state in STANDSTILL.
MC_Stop
It commands a motion stop.
Synopsis
FUNCTION_BLOCK MC_Stop
VAR_IN_OUT
Axis : <type>AXIS_REF</type> ;
END_VAR
VAR_INPUT
Execute : <type>BOOL</type> ;
Deceleration : <type>DINT</type> ;
Jerk : <type>DINT</type> ;
END_VAR
VAR_OUTPUT
Done : <type>BOOL</type> ;
CommandAborted : <type>BOOL</type> ;
Error : <type>BOOL</type> ;
ErrorID : <type>DINT</type> ;
END_VAR
Parameter
Axis
Value of type AXIS_REF
Axis reference
Execute
Value of type BOOL
At the rising edge it starts to move the axis.
Deceleration
Value of type DINT
Value of deceleration [axis's unit per second]
Jerk
Value of type DINT
It must be 100.
Done
Value of type BOOL
Flag that is set to TRUE when the Zero velocity is reached.
CommandAborted
Value of type BOOL
Flag that is set to TRUE if the command is aborted by another motion command.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1)
Description
This function block commands a motion stop and transfers the axis to the STOPPING state.
It aborts any ongoing motion function block execution. When the Done output is set, the state
is transferred to STANDSTILL. If the MC_Stop is launched and the axis is in STANDSTILL,
then the output Done is set to TRUE immediately.
MC_Power
It controls the power stage.
Synopsis
FUNCTION_BLOCK MC_Power
VAR_IN_OUT
Axis : <type>AXIS_REF</type>;
END_VAR
VAR_INPUT
Enable : <type>BOOL</type> ;
END_VAR
VAR_OUTPUT
Status : <type>BOOL</type> ;
Error : <type>BOOL</type> ;
ErrorID : <type>DINT</type> ;
END_VAR
Parameter
Axis
Value of type AXIS_REF
Axis reference.
Enable
Value of type BOOL
At the rising edge it sets the power on. It does not work like an usual 'Enable' input:
• To enable the axis it is necessary to execute a rising edge of this input, from 0 to 1;
• To disable the axis it is necessary to execute a falling edge of this input, from 1 to 0;
Status
Value of type BOOL
Effective state of power stage. TRUE = axis torque active; FALSE = axis free;
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Description
This function block controls the power stage (ON or OFF). See an example in MC_ReadDriveS-
tatus.
MC_ReadActualPosition
It returns the actual position of the axis.
Synopsis
FUNCTION_BLOCK MC_ReadActualPosition
VAR_IN_OUT
Axis : <type>AXIS_REF</type> ;
END_VAR
VAR_INPUT
Enable : <type>BOOL</type> ;
END_VAR
VAR_OUTPUT
Done : <type>BOOL</type> ;
Error : <type>BOOL</type> ;
ErrorID : <type>DINT</type> ;
Position : <type>DINT</type> ;
Velocity : <type>DINT</type> ;
Acceleration : <type>DINT</type> ;
END_VAR
Parameter
Axis
Value of type AXIS_REF
Axis reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously gets the value of the parameter.
Done
Value of type BOOL
Flag that is set to TRUE when the read actual position value is available.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Position
Value of type DINT
Absolute actual position in axis's unit.
Velocity
Value of type DINT
Actual velocity in axis's unit per second.
Acceleration
Value of type DINT
Actual acceleration in axis's unit per second2.
Description
This function block, while enabled, continuously returns the value of the parameters. The para-
meters are the actual position, velocity and acceleration of the axis.
Note
Axis's unit is step.
MC_ReadCommandPosition
It returns the commanded position of the axis.
Synopsis
FUNCTION_BLOCK MC_ReadCommandPosition
VAR_IN_OUT
Axis : <type>AXIS_REF</type> ;
END_VAR
VAR_INPUT
Enable : <type>BOOL</type> ;
END_VAR
VAR_OUTPUT
Done : <type>BOOL</type> ;
Error : <type>BOOL</type> ;
ErrorID : <type>DINT</type> ;
Position : <type>DINT</type> ;
Velocity : <type>DINT</type> ;
Acceleration : <type>DINT</type> ;
END_VAR
Parameter
Axis
Value of type AXIS_REF
Axis reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously gets the value of the parameter.
Done
Value of type BOOL
Flag that is set to TRUE when the read commanded position value is available.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1)
Position
Value of type DINT
Absolute commanded position in axis's unit.
Velocity
Value of type DINT
Commanded velocity in axis's unit per second.
Acceleration
Value of type DINT
Commanded acceleration in axis's unit per second2.
Description
This function block, while enabled, continuously returns the value of the parameters. The para-
meters are the commanded position, velocity and acceleration of the axis.
Note
Axis's unit is step.
MC_ReadDriveStatus
It returns drive status.
Synopsis
FUNCTION_BLOCK MC_ReadDriveStatus
VAR_IN_OUT
Axis : <type>AXIS_REF</type> ;
END_VAR
VAR_INPUT
Enable : <type>BOOL</type> ;
END_VAR
VAR_OUTPUT
Done : <type>BOOL</type> ;
Error : <type>BOOL</type> ;
ErrorID : <type>DINT</type> ;
ReadyToSwitchOn : <type>BOOL</type> ;
SwitchedOn : <type>BOOL</type> ;
Run : <type>BOOL</type> ;
Fault : <type>BOOL</type> ;
END_VAR
Parameter
Axis
Value of type AXIS_REF
Axis reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously gets the value of the parameter.
Done
Value of type BOOL
Flag that is set to TRUE when the value is available.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1)
ReadyToSwitchOn
Value of type BOOL
Flag that is set to TRUE when the drive is ready to switch on.
SwitchedOn
Value of type BOOL
Flag that is set to TRUE as long as the drive is switched on. The power stage is on.
Run
Value of type BOOL
Flag that is set to TRUE when the power stage is on and the drive can move the motor.
This output is equal to the output 'Status' of MC_Power.
Fault
Value of type BOOL
Flag that is set to TRUE when the drive has an alarm.
Description
This function block describes the drive state. See Section 4.2.2.1, “How digital inputs and outputs
manage the drive”
When the output ReadyToSwitchOn is TRUE then the drive is ready to be switched on, there-
fore the power stage can be enabled by using MC_Power. When the power stage is on and the
drive is ready to move the motor, both the SwitchedOn and Run outputs are TRUE.
If the drive is on alarm state, then the output Fault is TRUE and the other outputs are all
FALSE. In this situation the axis state is ERRORSTOP (see MC_ReadStatus).
This example is used to show how to give the power to the drive:
The input 'SwitchOn = TRUE' ;
1. rst of all it is necessary to start the management of the movement in the IEC program;
2. when the axis management is started, the program reads the drive status;
3. when the drive status output 'ReadyToSwitchOn' is TRUE, the program can enable the stage;
4. when the power is on, then the output 'Status' of 'MC_Power = TRUE' and output 'Run' of 'MC_ReadDriveStatus = TRUE'.
Note
At the rst switched on procedure some drives execute an alignment procedure.
Example 4.1. start-up procedure
MC_ReadStatus
It returns, in detail, the status of the axis.
Synopsis
FUNCTION_BLOCK MC_ReadStatus
VAR_IN_OUT
Axis : <type>AXIS_REF</type> ;
END_VAR
VAR_INPUT
Enable : <type>BOOL</type> ;
END_VAR
VAR_OUTPUT
Done : <type>BOOL</type> ;
Error : <type>BOOL</type> ;
ErrorID : <type>DINT</type> ;
ErrorStop : <type>BOOL</type> ;
Stopping : <type>BOOL</type> ;
StandStill : <type>BOOL</type> ;
DiscreteMotion : <type>BOOL</type> ;
ContinuousMotion : <type>BOOL</type> ;
SynchronizedMotion : <type>BOOL</type> ;
Homing : <type>BOOL</type> ;
Initialization : <type>BOOL</type> ;
CostantVelocity : <type>BOOL</type> ;
Accelerating : <type>BOOL</type> ;
Decelerating : <type>BOOL</type> ;
END_VAR
Parameter
Axis
Value of type AXIS_REF
Axis reference.
Enable
Value of type BOOL
Done
Value of type BOOL
Flag that is set to TRUE when the read actual position value is available.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Errorstop
Value of type BOOL
Is TRUE when the axis is in ERRORSTOP state.
Stopping
Value of type BOOL
Flag that is set to TRUE when the axis is in STOPPING or EMERGENCYSTOPPING
state.
StandStill
Value of type BOOL
Flag that is set to TRUE when the axis is in STANDSTILL state.
DiscreteMotion
Value of type BOOL
Flag that is set to TRUE when the axis is executing a DISCRETEMOTION movement.
(For example a MC_MoveAbsolute)
ContinuosMotion
Value of type BOOL
Flag that is set to TRUE when the axis is executing a CONTINUOUSMOTION move-
ment (for example a MC_MoveCustom or MC_MoveVelocity)
SynchronizedMotion
Value of type BOOL
Flag that is set to TRUE when the axis is executing a SYNCHRONIZED movement.
Actually this output is always FALSE.
Homing
Value of type BOOL
Flag that is set to TRUE when the axis is executing an HOMING procedure.
Initialization
Value of type BOOL
Flag that is set to TRUE while the axis program is executing the INITIALIZATION
procedure of the axis.
CostantVelocity
Value of type BOOL
Flag that is set to TRUE when the axis is moving with a constant theoretical velocity.
Accelerating
Value of type BOOL
It is not managed.
Decelerating
Value of type BOOL
It is not managed.
Description
This function block returns, in detail, the status of the axis according to the motion that is cur-
rently in progress. See Section 4.2.1, “Axis status” paragraph.
MC_Reset
It recovers the axis from the ERRORSTOP state.
Synopsis
FUNCTION_BLOCK MC_Reset
VAR_IN_OUT
Axis : <type>AXIS_REF</type>;
END_VAR
VAR_INPUT
Execute : <type>BOOL</type> ;
END_VAR
VAR_OUTPUT
Done : <type>BOOL</type> ;
Error : <type>BOOL</type> ;
ErrorID : <type>DINT</type> ;
END_VAR
Parameter
Axis
Value of type AXIS_REF
Axis reference.
Execute
Value of type BOOL
At the rising edge it resets the axis.
Done
Value of type BOOL
STANDSTILL state is reached.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Description
This function block makes the transition from the state ERRORSTOP to STANDSTILL by
resetting all internal axis-related errors. If it is tried to execute this function block when the axis
state is not ERRORSTOP, nothing happens.
When the axis has an error, the ERRORSTOP output of MC_ReadStatus is TRUE. When AX_ResetCommand is TRUE the FB
MC_Reset recovers the error. If AX_ResetCommand is always TRUE this program automatically recovers the axis from an ERRORS-
TOP state.
Example 4.2. Reset error procedure
MC_Start
It starts the axes program management.
Synopsis
FUNCTION_BLOCK <function>MC_Start</function>
VAR_INPUT
Execute : <type>BOOL</type> ;
END_VAR
VAR_OUTPUT
Done : <type>BOOL</type> ;
CommandAborted : <type>BOOL</type> ;
Error : <type>BOOL</type> ;
ErrorID : <type>DINT</type> ;
END_VAR
Parameter
Execute
Value of type BOOL
At the rising edge it starts the management of the axis.
Done
Value of type BOOL
Flag that is set to TRUE when the read actual position value is available.
CommandAborted
Value of type BOOL
Flag that is set to TRUE if the command is aborted by another motion command.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Description
This function block starts the management of the axis. Before the program launches a movement
it is necessary the output Done of MC_Start is TRUE.
4.3.1. Encoder management
In this paragraph there are the descriptions of:
• data type ENC_REF, used in a program that defines the encoder to be managed;
ENC_REF
It is the encoder reference.
Synopsis
TYPE Enc_Ref :
STRUCT
Num : INT;
END_STRUCT;
END_TYPE
Elements
num
Value of type INT
It is an internal number that represents the encoder to be used.
Description
This Data Type is the encoder reference. It is used to declare an encoder in the project. Before to
call this function block it is important to initialize the num with the correct value related to the
encoder that has to be managed. For this purpose, it is strongly recommended to use the already
defined constants:
Note
This encoder is equal to IO_REF_ENC_AX_FEEDBACK when the feed-
back loop is closed, else it is a simulated value (=command position).
1
This reference is available only on BD drives.
Note
It can be selected equal to IO_REF_ENC_AUX_REAL or IO_RE-
F_ENC_AUX_VIRTUAL;
2
This reference is available only on BD drives.
CMP_REF
It is the position comparator reference.
Synopsis
TYPE Cmp_Ref :
STRUCT
Num : INT;
EncRef : Enc_Ref;
END_STRUCT;
END_TYPE
Elements
num
Value of type INT
It is an internal number that represents the comparator number.
EncRef
Value of type Enc_Ref
It defines which encoder reference has to be latched. The possible usable encoders are:
• IO_REF_ENC_AXIS (1);
• IO_REF_ENC_AX_COMMAND (3);
• IO_REF_ENC_AUXILIARY (11);
Description
This Data Type is the comparator number. It is used to define the encoder to be related to the
comparator. Before to call the function block it is important to initialize the num with the correct
value related to the comparator it has to manage. For this purpose, it is strongly recommended
to use the already defined constants:
Note
The position comparator cannot use all the encoder references (see ENC_REF), but on-
ly the numbers (1), (3) and (11).
IO_EncGetStatus
It shows the encoder status.
Synopsis
FUNCTION_BLOCK Io_EncGetStatus
VAR_IN_OUT
Reference : Enc_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
Init : BOOL;
Ready : BOOL;
Alarm : BOOL;
AlarmCode : DINT;
AlarmBitCode: DINT;
END_VAR
Parameter
Reference
Value of type ENC_REF
Encoder reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously gets the value of the Encoder status.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Init
Value of type BOOL
As long as it is TRUE, the peripheral is in initialization state.
Ready
Value of type BOOL
As long as it is TRUE, the peripheral is ready.
Alarm
Value of type BOOL
Flag that is set to TRUE when the peripheral is in alarm.
AlarmCode
Value of type DINT
When the encoder has an alarm, it shows the alarm code.
AlarmBitCode
Value of type DINT
When the encoder has an alarm, it shows the alarm code.
Description
It shows the status of the encoder. Its possible statuses are:
When the program starts, the encoder is in Init state and then automatically passes to Ready. If
the encoder does not work, it goes in alarm state.
Io_EncManager
It manages the encoder.
Synopsis
FUNCTION_BLOCK Io_EncManager
VAR_IN_OUT
Reference : Enc_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
AlarmResume : BOOL;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
Init : BOOL;
PreReady : BOOL;
Ready : BOOL;
Alarm : BOOL;
AlarmCode : DINT;
AlarmBitCode: DINT;
END_VAR
Parameter
Reference
Value of type ENC_REF
Encoder reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously gets the value of the encoder status.
AlarmResume
Value of type BOOL
When the encoder is in alarm state, it executes a resume of the alarm. It is necessary to
recover the encoder.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Init
Value of type BOOL
As long as it is TRUE, the encoder is in initialization state.
PreReady
Value of type BOOL
As long as it is TRUE, the encoder is in PreReady state. PreReady is an internal state of
the initialization procedure of the encoder.
Ready
Value of type BOOL
Flag that is set to TRUE when the encoder is ready.
Alarm
Value of type BOOL
Flag that is set to TRUE when the encoder is in alarm state.
AlarmCode
Value of type DINT
When the encoder has an alarm, it shows the alarm code.
AlarmBitCode
Value of type DINT
When the encoder has an alarm, it shows the alarm bit code.
Description
It manages the encoder. It allows to recover the encoder from an alarm state.
Io_EncReadPosition
It reads the encoder position.
Synopsis
FUNCTION_BLOCK Io_EncReadPosition
VAR_IN_OUT
Reference : Enc_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
RefValidation : BOOL;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
Position : DINT;
Velocity : DINT;
Valid : BOOL;
Forced : BOOL;
RefValid : BOOL;
END_VAR
Parameter
Reference
Value of type ENC_REF
Encoder reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously reads the encoder position.
RefValidation
Value of type BOOL
It validates the encoder position.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Position
Value of type DINT
Encoder position.
Velocity
Value of type DINT
Encoder velocity.
Valid
Value of type BOOL
As long as 'Enable' is true, the position and the velocity values are valid.
Forced
Value of type BOOL
It is not used.
RefValid
Value of type BOOL
Flag that is set to TRUE when the position has been validate. After that RefValid has
been set to TRUE, this output shows if the position of the encoder is still coherent, or
some problem is happened and so the position is not coherent.
Description
It reads the encoder position.
Io_EncReadPositionOnPort
It reads the encoder position.
Synopsis
FUNCTION_BLOCK Io_EncReadPositionOnPort
VAR_IN_OUT
Reference : Enc_Ref; (*[IO reference]*)
END_VAR
VAR_INPUT
Enable : BOOL;
RefValidation : BOOL;
END_VAR
VAR_OUTPUT
Done : BOOL;
Active : BOOL;
Error : BOOL;
ErrorID : DINT;
Position : DINT;
Velocity : DINT;
Valid : BOOL;
Forced : BOOL;
RefValid : BOOL;
END_VAR
Parameter
Reference
Value of type ENC_REF
Encoder reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously reads the encoder position.
RefValidation
Value of type BOOL
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Position
Value of type DINT
Encoder position.
Velocity
Value of type DINT
Encoder velocity.
Valid
Value of type BOOL
As long as 'Enable' is true, the position and the velocity values are valid.
Forced
Value of type BOOL
It is not used.
RefValid
Value of type BOOL
Flag that is set to TRUE when the position has been validate. After that RefValid has
been set to TRUE, this output shows if the position of the encoder is still coherent, or
some problem is happened and so the position is not coherent.
Description
It reads the encoder position. This function block works at the same way of Io_EncReadPosition.
Io_EncTriggerEvent
It configures the trigger event zero mark for the capture function.
Synopsis
FUNCTION_BLOCK Io_EncTriggerEvent
VAR_IN_OUT
Reference : Enc_Ref;
END_VAR
VAR_INPUT
Execute : BOOL;
Abort : BOOL;
TrgStart : BOOL;
EdgeType : BOOL;
OneShot : BOOL;
NEventDriven : BYTE;
END_VAR
VAR_OUTPUT
Done : BOOL;
Active : BOOL;
CommandAborted : BOOL;
Error : BOOL;
ErrorID : DINT;
EnablingCapture : BOOL;
TrgEventHandle : DINT;
END_VAR
Parameter
Reference
Value of type ENC_REF
Encoder reference.
• IO_REF_ENC_AX_FEEDBACK (2);
• IO_REF_ENC_AUX_REAL (12)1.
1
This reference is valid only for BD drives.
Execute
Value of type BOOL
At the rising edge it starts to configure the capture on the zero mark of the encoder.
Abort
Value of type BOOL
At the rising edge it executes an abort of the capture procedure.
TrgStart
Value of type BOOL
At the rising edge it launches the capture function. This command is executed when
the configuration is complete.
EdgeType
Value of type BOOL
Edge of the Zero Mark detection that triggers the capture
0 : falling edge;
1 : rising edge.
OneShot
Value of type BOOL
if it is TRUE, then the capture function is executed only once. If it is FALSE, then it
is automatically restarted.
NEventDriven
Value of type INT
Selector of the Capture Peripheral:
• 0 : the drive automatically selects the rst Capture Peripheral that is not in use (free);
Done
Value of type BOOL
The position capture on the Zero Mark detection has been executed.
Active
Value of type BOOL
It is waiting the Zero Mark detection.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the Function Block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
EnablingCapture
Value of type BOOL
When this Function Block completes the configuration of the event, this output is set
to TRUE. This output is an input for the Function Block Io_EncEventCaptureValue.
TrgEventHandle
Value of type DINT
It is an internal identification of the event. The Function Block itself calculates it.
NEventActived
Value of type INT
It indicates which Capture Peripheral has been activated by the Function Block:
Description
This Function Block must be used with Io_EncEventCaptureValue. They configure and manage
the capture function of the encoder position when the encoder position passes through the zero
mark. The Function Block inputs must be used by following this sequence:
2. when the Function Block sees a positive edge on the input Execute, it starts to configure
the capture function into the drive and also it calculates the TrgEventHandle. When
it finishes its internal operations, the output EnablingCapture is set to TRUE. This
output is used by the Function Block Io_EncEventCaptureValue to complete the con-
figuration of the capture function;
3. when this second Function Block finishes its operations, the input TrgStart is set to
TRUE. At this moment the capture function starts. The output Active is set to TRUE;
4. when the capture event happens then the output Active returns to FALSE and the
output Done is set to TRUE.
Io_EncEventCaptureValue
It completes the configurations of the capture function. It defines which is the value to be cap-
tured.
Synopsis
FUNCTION_BLOCK Io_EncEventCaptureValue
VAR_IN_OUT
Reference : Enc_Ref;
END_VAR
VAR_INPUT
Execute : BOOL;
Abort : BOOL;
TrgEventHandle: DINT;
ValueType : INT;
END_VAR
VAR_OUTPUT
Done : BOOL;
Active : BOOL;
CommandAborted: BOOL;
Error : BOOL;
ErrorID : DINT;
CaptureEnabled: BOOL;
CapturedValue : DINT;
END_VAR
Parameter
Reference
Value of type ENC_REF
It defines which encoder reference has to be consider as capture reference. The possible
usable encoders are:
• IO_REF_ENC_AXIS (1);
• IO_REF_ENC_AX_FEEDBACK (2);
• IO_REF_ENC_AX_FOLLOW_ERR (5);
• IO_REF_ENC_AUXILIARY (11);
• IO_REF_ENC_AUX_REAL (12)1;
• IO_REF_ENC_AUX_VIRTUAL (13)2;
Execute
Value of type BOOL
At the rising edge it configures the value for the capture function. The value is the Val-
ueType of the encoder reference (Reference).
Abort
Value of type BOOL
At the rising edge it executes the abort of the capture procedure.
TrgEventHandle
Value of type DINT
It is the internal identification of the event that defines when the capture function has to
capture the reference encoder position. This value is calculated by the Function Block
which configures the event. See Io_EncTriggerEvent, Io_DInpTriggerEvent.
ValueType
Value of type INT
It defines which type of value the capture function has to capture. The default value is
the position of the reference encoder selected. It is not allowed to change it.
Done
Value of type BOOL
The position has been captured.
Active
Value of type BOOL
As long as 'Active' is true, the Function Block keeps waiting the happening of the event.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
1
Available only for BD series.
2
Available only for BD series, except for IBD ange 60.
CaptureEnabled
Value of type BOOL
When this function block completes the configuration of the position that the capture
function has to capture, this output is set to TRUE. This output is usually connected
to the input TrgStart of the function block that configures the event (see Io_EncTrig-
gerEvent or Io_DInpTriggerEvent).
CapturedValue
Value of type DINT
When the position has been captured, the output Done is set to TRUE and in this out-
put there is the value of the captured position.
Description
This function block must be used with another one that configures the event for the capture
function. (See Io_EncTriggerEvent or Io_DInpTriggerEvent).
The capture function is used to capture a position when a particular event happens. To configure
the capture function is necessary to define two characteristics:
• the event that causes the capture. The available events are: zero mark (Io_EncTrig-
gerEvent) and the home digital input (Io_DInpTriggerEvent);
• the position that the function captures when the event happens: this function block is
necessary to configure it.
1. when the function block that configures the event sets its EnablingCapture output,
then the input Execute of this function block has to detect a rising edge trigger. The
input Execute is usually connected to the output EnablingCapture of the Io_Enc-
TriggerEvent or Io_DInpTriggerEvent. After this rising edge, the function block con-
figures the position to be captured according to the ValueType. When it finishes, the
outputs CaptureEnabled and Active are both set to TRUE;
Io_EncComparator
It compares the encoder position.
Synopsis
FUNCTION Io_EncComparator
VAR_IN_OUT
Reference : Cmp_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
Direction : BOOL;
Position : DINT;
END_VAR
Parameter
Reference
Value of type CMP_REF
Comparator reference
• IO_REF_CMP_0 (0);
• IO_REF_CMP_1 (1).
Note
The encoder references (ENC_REF) that can be linked to the comparator refer-
ence (CMP_REF) can be only:
• IO_REF_ENC_AXIS (1);
• IO_REF_ENC_AX_COMMAND (3);
• IO_REF_ENC_AUXILIARY (11).
Enable
Value of type BOOL
Direction
Value of type BOOL
Defines the positive direction counting of the position comparison. If its value is FALSE
the comparator verifies if the reference position is exceeded from lower to higher values.
If its value is TRUE the comparator verifies if the reference position is exceeded from
higher to lower values.
Position
Value of type DINT
Value of the position to be exceeded.
Description
It sets the position comparator functioning: the encoder reference, the counting direction and
the position reference in order to plan the INT PROGRAM through the SYS_EnEventInt func-
tion.
• data type DINP_REF, used in a program to define the digital input to be managed;
DINP_REF
It is the digital inputs bench reference.
Synopsis
TYPE DInp_Ref :
STRUCT
Num : INT;
END_STRUCT;
END_TYPE
Elements
num
Value of type INT
It is an internal number that represents the digital inputs bench to be used.
Description
This Data Type is the digital inputs bench reference. It is used to declare the digital inputs in the
project. Before to call this function block it is important to initialize the num with the correct
value related to the digital inputs that has to be managed. For this purpose, it is strongly recom-
mended to use the already defined constants:
1
This bank is present on SVM and BD series only.
Io_DInpGetStatus
It shows the digital inputs status.
Synopsis
FUNCTION_BLOCK Io_DInpGetStatus
VAR_IN_OUT
Reference : DInp_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
Init : BOOL;
Ready : BOOL;
Alarm : BOOL;
AlarmCode : DINT;
AlarmBitCode: DINT;
END_VAR
Parameter
Reference
Value of type DINP_REF
Digital inputs reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously gets the value of the digital inputs status.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1)
Init
Value of type BOOL
Flag that is set to TRUE when the peripheral is in initialization state.
Ready
Value of type BOOL
Flag that is set to TRUE when the peripheral is ready.
Alarm
Value of type BOOL
Flag that is set to TRUE when the peripheral is in alarm.
AlarmCode
Value of type DINT
When the peripheral has an alarm, it shows the alarm code.
AlarmBitCode
Value of type DINT
When the peripheral has an alarm, it shows the alarm code.
Description
It shows the status of the peripheral. The statuses are:
When the program starts, the peripheral is in Init state and then automatically passes to Ready.
If the digital inputs do not work, then the peripheral goes in alarm state.
Io_DInpManager
It manages the peripheral digital inputs.
Synopsis
FUNCTION_BLOCK Io_DInpManager
VAR_IN_OUT
Reference : DInp_Ref; (*[IO reference]*)
END_VAR
VAR_INPUT
Enable : BOOL;
AlarmResume : BOOL;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
Init : BOOL;
PreReady : BOOL;
Ready : BOOL;
Alarm : BOOL;
AlarmCode : DINT;
AlarmBitCode: DINT;
END_VAR
Parameter
Reference
Value of type DINP_REF
Digital inputs reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously manages the digital inputs.
AlarmResume
Value of type BOOL
When the peripheral is in alarm state, it executes a resume of the alarm. It is necessary
to recover the peripheral.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1)
Init
Value of type BOOL
As long as it is TRUE, the peripheral is in initialization state.
PreReady
Value of type BOOL
As long as it is TRUE, the peripheral is in PreReady state. PreReady is an internal state
of the initialization procedure of the peripheral.
Ready
Value of type BOOL
As long as it is TRUE, the peripheral is ready.
Alarm
Value of type BOOL
Flag that is set to TRUE when the peripheral is in alarm.
AlarmCode
Value of type DINT
When the peripheral has an alarm, it shows the alarm code.
AlarmBitCode
Value of type DINT
When the peripheral has an alarm, it shows the alarm code.
Description
It manages the peripheral. It permits to recover an alarm in the peripheral.
Io_DInpReadStatus
It reads the status of the digital inputs.
Synopsis
FUNCTION_BLOCK Io_DInpReadStatus
VAR_IN_OUT
Reference : DInp_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
InpStatus : BYTE;
Valid : BOOL;
Forced : BOOL;
END_VAR
Parameter
Reference
Value of type DINP_REF
Digital inputs reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously gets the value of the status of the digital in-
puts.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
InpStatus
Value of type BYTE
Digital inputs status when the output Valid is TRUE. Each bit is related to a digital
input, according to the bank selected by the DINP_REF.
Valid
Value of type BOOL
Is TRUE when the output InpStatus has a valid value.
Forced
Value of type BOOL
It is not used.
Description
It reads the status of the digital inputs selected in the DINP_REF reference input.
Io_DInpReadStatusOnPort
It reads the status of the digital inputs.
Synopsis
FUNCTION_BLOCK Io_DInpReadStatusOnPort
VAR_IN_OUT
Reference : DInp_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
InpStatus : BYTE;
Valid : BOOL;
Forced : BOOL;
END_VAR
Parameter
Reference
Value of type DINP_REF
Digital inputs reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously gets the value of the status of the digital in-
puts.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
InpStatus
Value of type BYTE
Digital inputs status when the output Valid is TRUE. Each bit is related to a digital
input, according to the bank selected by the DINP_REF.
Valid
Value of type BOOL
Is TRUE when the output InpStatus has a valid value.
Forced
Value of type BOOL
It is not used.
Description
It reads the status of the digital inputs selected in the DINP_REF reference input. This function
block works at the same way of Io_DInpReadStatus.
Io_DInpTriggerEvent
It configures the capture function trigger event on an edge of a particular digital input.
Synopsis
FUNCTION_BLOCK Io_DInpTriggerEvent
VAR_IN_OUT
Reference : DInp_Ref;
END_VAR
VAR_INPUT
Execute : BOOL;
Abort : BOOL;
TrgStart : BOOL;
NBit : BYTE;
EdgeType : BOOL;
OneShot : BOOL;
NEventDriven : BYTE;
END_VAR
VAR_OUTPUT
Done : BOOL;
Active : BOOL;
CommandAborted : BOOL;
Error : BOOL;
ErrorID : DINT;
EnablingCapture : BOOL;
TrgEventHandle : DINT;
END_VAR
Parameter
Reference
Value of type DINP_REF
Digital inputs reference.
Execute
Value of type BOOL
At the rising edge it starts to configure the trigger event. Its characteristics are in the
inputs NBit and EdgeEvent.
Abort
Value of type BOOL
At the rising edge it executes an abort of the capture procedure.
TrgStart
Value of type BOOL
At the rising edge it launches the capture function. This command is executed when
the configuration is complete.
NBit
Value of type BYTE
It defines the number of the digital input selected to be the trigger for the capture func-
tion. The bit number NBit is related to the bank defined through the DINP_REF ref-
erence:
• For Digital input 0..7 the reference bank is IO_REF_DI_PHYSICAL_0, NBit 0..7;
• For Digital input 8..15 the reference bank is IO_REF_DI_PHYSICAL_1, NBit 0..7
(NBit 0 = Dig. input 8, etc..);
EdgeType
Value of type BOOL
0 : falling edge;
1 : rising edge.
OneShot
Value of type BOOL
if it is TRUE, then the capture function is executed only once. If it is FALSE, then it
is automatically restarted.
NEventDriven
Value of type BYTE
It is not used.
Done
Value of type BOOL
The capture has been executed.
Active
Value of type BOOL
It is waiting for the event happening.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
EnablingCapture
Value of type BOOL
When this function block completes the configuration of the event, this output is set
to TRUE. This output is an input for the function block Io_EncEventCaptureValue.
TrgEventHandle
Value of type DINT
It is an internal identification of the event. The function block itself calculates it.
Description
This function block must be used with Io_EncEventCaptureValue. They configure and manage
the capture of the encoder position function when the event in the digital input happens. The
function block inputs has to follow this sequence:
2. when the function block detects a positive edge in the input Execute, it starts to con-
figure the capture function into the drive and also to calculate the TrgEventHandle.
When it finishes its internal operations, it sets to TRUE the output EnablingCapture.
This output is used by the function block Io_EncEventCaptureValue to complete the
configuration of the capture function;
3. when this second function block finishes its operations, then it sets to TRUE the in-
put TrgStart. In this moment the capture function starts. The output Active is set to
TRUE;
4. when the capture has been made, the output Active returns to FALSE and the output
Done is set to TRUE.
• data type DOUT_REF, used in a program to define the digital outputs to be managed;
DOUT_REF
It is the digital outputs bench reference.
Synopsis
TYPE DOut_Ref :
STRUCT
Num : INT;
END_STRUCT;
END_TYPE
Elements
num
Value of type INT
It is an internal number that represents the digital outputs bench to be used.
Description
This Data Type is the digital outputs bench reference. It is used to declare the digital outputs
in the project. Before to call this function block it is important to initialize the num with the
correct value related to the digital outputs that has to be managed. For this purpose, it is strongly
recommended to use the already defined constant:
Io_DOutGetStatus
It shows the digital outputs status.
Synopsis
FUNCTION_BLOCK Io_DOutGetStatus
VAR_IN_OUT
Reference : DOut_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
Init : BOOL;
Ready : BOOL;
Alarm : BOOL;
AlarmCode : DINT;
AlarmBitCode: DINT;
END_VAR
Parameter
Reference
Value of type DOUT_REF
Digital outputs reference
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously gets the value of the digital outputs status.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Init
Value of type BOOL
As long as it is TRUE, the peripheral is in initialization state.
Ready
Value of type BOOL
As long as it is TRUE, the peripheral is ready.
Alarm
Value of type BOOL
As long as it is TRUE, the peripheral is in alarm.
AlarmCode
Value of type DINT
When the peripheral has an alarm, it shows the alarm code.
AlarmBitCode
Value of type DINT
When the peripheral has an alarm, it shows the alarm code.
Description
It shows the status of the peripheral. The statuses are:
When the program starts, the peripheral is in Init state and then automatically passes to Ready.
If the digital outputs do not work, then the peripheral goes in alarm state.
Io_DOutManager
It manages the peripheral digital outputs.
Synopsis
FUNCTION_BLOCK Io_DOutManager
VAR_IN_OUT
Reference : DOut_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
AlarmResume : BOOL;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
Init : BOOL;
PreReady : BOOL;
Ready : BOOL;
Alarm : BOOL;
AlarmCode : DINT;
AlarmBitCode: DINT;
END_VAR
Parameter
Reference
Value of type DOUT_REF
Digital outputs reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously manages the digital outputs.
AlarmResume
Value of type BOOL
When the peripheral is in alarm state, it executes a resume of the alarm. It is necessary
to recover the peripheral.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Init
Value of type BOOL
Flag that is set to TRUE when the peripheral is in initialization state.
PreReady
Value of type BOOL
Flag that is set to TRUE when the peripheral is PreReady. PreReady is an internal state
of the initialization procedure of the peripheral.
Ready
Value of type BOOL
As long as it is TRUE, the peripheral is ready.
Alarm
Value of type BOOL
Flag that is set to TRUE when the peripheral is in alarm.
AlarmCode
Value of type DINT
When the peripheral has an alarm, it shows the alarm code.
AlarmBitCode
Value of type DINT
When the peripheral has an alarm, it shows the alarm code.
Description
It manages the peripheral. It permits to recover an alarm in the peripheral.
Io_DOutWriteStatus
It writes the status of the digital outputs.
Synopsis
FUNCTION_BLOCK Io_DOutWriteStatus
VAR_IN_OUT
Reference : DOut_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
OutStatus : BYTE;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
Valid : BOOL;
Forced : BOOL;
END_VAR
Parameter
Reference
Value of type DOUT_REF
Digital outputs reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously writes the value of the outputs status.
OutStatus
Value of type BYTE
It is the value that has to be written on the digital outputs status.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Valid
Value of type BOOL
Is TRUE when the digital outputs are valid.
Forced
Value of type BOOL
It is not used.
Description
It writes the value of the input OutStatus on the digital outputs that are selected by the Reference.
Io_DOutWriteStatusOnPort
It writes the status of the digital outputs.
Synopsis
FUNCTION_BLOCK Io_DOutWriteStatusOnPort
VAR_IN_OUT
Reference : DOut_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
OutStatus : BYTE;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
Valid : BOOL;
Forced : BOOL;
END_VAR
Parameter
Reference
Value of type DOUT_REF
Digital outputs reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously writes the value of the outputs status.
OutStatus
Value of type BYTE
It is the value that has to be written on the digital outputs status.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1).
Valid
Value of type BOOL
Is TRUE when the digital outputs are valid.
Forced
Value of type BOOL
It is not used.
Description
It writes the value of the input OutStatus on the digital outputs that are selected by the Reference.
• data type AINP_REF used in a program to define the analog inputs to be managed;
AINP_REF
It is the analog input reference.
Synopsis
TYPE
AXIS_REF : STRUCT
num : <type>INT</type>;
END_STRUCT;
END_TYPE
Elements
num
Value of type INT
It is an internal number that represents the analog input bench to be used.
Description
This Data Type is the analog input bench reference. It is used to declare the analog input in the
project. Before to call this function block it is important to initialize the num with the correct
value according to the analog input it has to manage. For this purpose, it is strongly recommended
to use the already defined constants:
Io_AInpGetStatus
It shows the analog input status.
Synopsis
FUNCTION_BLOCK Io_AInpGetStatus
VAR_IN_OUT
Reference : AInp_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
Init : BOOL;
Ready : BOOL;
Alarm : BOOL;
AlarmCode : DINT;
AlarmBitCode: DINT;
END_VAR
Parameter
Reference
Value of type AINP_REF
Analog inputs reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously gets the value of the status of the analog input.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1)
Init
Value of type BOOL
As long as it is TRUE, the peripheral is in initialization state.
Ready
Value of type BOOL
As long as it is TRUE, the peripheral is ready.
Alarm
Value of type BOOL
Flag that is set to TRUE when the peripheral is in alarm.
AlarmCode
Value of type DINT
When the peripheral has an alarm, it shows the alarm code.
AlarmBitCode
Value of type DINT
When the peripheral has an alarm, it shows the alarm code.
Description
It shows the status of the peripheral. The statuses are:
When the program starts, the peripheral is in Init state and then automatically passes to Ready.
If the analog input does not work, then the peripheral goes in alarm state.
Io_AInpManager
It manages the peripheral analog input.
Synopsis
FUNCTION_BLOCK Io_AInpManager
VAR_IN_OUT
Reference : AInp_Ref; (*[IO reference]*)
END_VAR
VAR_INPUT
Enable : BOOL;
AlarmResume : BOOL;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
Init : BOOL;
PreReady : BOOL;
Ready : BOOL;
Alarm : BOOL;
AlarmCode : DINT;
AlarmBitCode: DINT;
END_VAR
Parameter
Reference
Value of type AINP_REF
Analog input reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously gets the value of the analog input peripheral
status.
AlarmResume
Value of type BOOL
When the peripheral is in alarm state, it executes a resume of the alarm. It is necessary
to recover the peripheral.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Error identification code (see Table A.1)
Init
Value of type BOOL
As long as it is TRUE, the peripheral is in initialization state.
PreReady
Value of type BOOL
As long as it is TRUE, the peripheral is in PreReady state. PreReady is an internal state
of the initialization procedure of the peripheral.
Ready
Value of type BOOL
As long as it is TRUE, the peripheral is ready.
Alarm
Value of type BOOL
As long as it is TRUE, the peripheral is in alarm.
AlarmCode
Value of type DINT
When the peripheral has an alarm it shows the alarm code
AlarmBitCode
Value of type DINT
When the peripheral has an alarm it shows the alarm code.
Description
It manages the peripheral. It permits to recover an alarm occurred in the peripheral.
Io_AInpReadValue
It reads the value of the analog input.
Synopsis
FUNCTION_BLOCK Io_AInpReadValue
VAR_IN_OUT
Reference : AInp_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
Value : DINT;
Valid : BOOL;
Forced : BOOL;
END_VAR
Parameter
Reference
Value of type AINP_REF
Analog input reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously reads the value of the analog input.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Value
Value of type DINT
Analog input value when the output Valid is TRUE.
Valid
Value of type BOOL
If it is TRUE it means that the parameter Value has a valid value.
Forced
Value of type BOOL
It is not used
Description
It reads the value of the analog input selected in the reference.
Io_AInpReadValueOnPort
It reads the value of the analog input.
Synopsis
FUNCTION_BLOCK Io_AInpReadValueOnPort
VAR_IN_OUT
Reference : AInp_Ref;
END_VAR
VAR_INPUT
Enable : BOOL;
END_VAR
VAR_OUTPUT
Error : BOOL;
ErrorID : DINT;
Value : DINT;
Valid : BOOL;
Forced : BOOL;
END_VAR
Parameter
Reference
Value of type AINP_REF
Analog input reference.
Enable
Value of type BOOL
As long as 'Enable' is true, it continuously gets the value of the analog input.
Error
Value of type BOOL
Flag that is set to TRUE when an error has occurred within the function block.
ErrorID
Value of type DINT
Value
Value of type DINT
Analog input value when the output Valid is TRUE.
Valid
Value of type BOOL
If it is TRUE it means that the parameter Value has a valid value.
Forced
Value of type BOOL
It is not used
Description
It reads the value of the analog input selected in the reference.
Note
These functionalities are not supported in the IBD.
Ut_ArcCos
It calculates the angle in degrees with resolution E-6.
Synopsis
Return value
Value of type DINT
The angle in degrees with resolution E-6 (1000000 = 1).
Parameter
Cosine
Value of type DINT
It is the cosine of the angle with resolution E-8 (100000000 = 1). Its range starts from
-100000000 to +100000000. The value is saturated when it exceeds the range.
Description
This function calculates the angle in degrees with resolution E-6.
Ut_Cos
It calculates the cosine of the angle with resolution E-8.
Synopsis
Return value
Value of type DINT
The cosine of the angle with resolution E-8.
Parameter
Angle
Value of type DINT
It is the angle in degree with resolution E-6. Any value is valid.
Description
This function calculates the cosine of the angle with resolution E-8.
Ut_ArcSin
It calculates the angle in degrees with resolution E-6.
Synopsis
Return value
Value of type DINT
The angle in degrees with resolution E-6 (1000000 = 1).
Parameter
Sine
Value of type DINT
It is the sine of the angle with resolution E-8 (100000000 = 1). Its range starts from
-100000000 to +100000000. The value is saturated when it exceeds the range.
Description
This function calculates the angle in degrees with resolution E-6.
Ut_Sin
It calculates the sine of the angle with resolution E-8.
Synopsis
Return value
Value of type DINT
The sine of the angle with resolution E-8.
Parameter
Angle
Value of type DINT
It is the angle in degree with resolution E-6. Any value is valid.
Description
This function calculates the sine of the angle with resolution E-8.
Ut_MTracky
It calculates the angle of the single axis tracker (M-Tracky type).
Synopsis
Return value
Value of type BOOL
If 0 then there are no errors.
Parameter
Altitude
Value of type INT
It is the altitude in hundredths of a degree. Its range starts from -18000 to +18000.
AxisAngle
Value of type INT
It is the angle of rotation axis in hundredths of a degree. Its range starts from -18000
to +18000.
Azimuth
Value of type INT
It is the azimuth in hundredths of a degree. Its range starts from -18000 to +18000.
Result
Value of type INT
The angle of the single axis tracker (M-Tracky type) in hundredths of a degree.
Description
This function calculates the angle of the single axis tracker (M-Tracky type).
Ut_SolarPosition
It calculates the position of the sun.
Synopsis
Return value
Value of type BOOL
If 0 then there are no errors.
Parameter
DayOfYear
Value of type INT
It is the days of the year. Its range starts from 1 to 366.
MinOfDay
Value of type INT
It is the minute of the day. Its range starts from 0 to 1439.
Latitude
Value of type INT
It is the latitude in hundredths of a degree. Its range starts from -9000 to +9000.
Altitude
Value of type INT
Altitude in hundredths of a degree.
Azimuth
Value of type INT
Azimuth in hundredths of a degree.
Description
This function calculates the position of the sun.
Ut_TrueSolarTime
It calculates the local solar time in minutes.
Synopsis
Return value
Value of type BOOL
If 0 then there are no errors.
Parameter
DayOfYear
Value of type INT
It is the day of the year. Its range starts from 1 to 366.
MinOfDay
Value of type INT
It is the minute of the day. Its range starts from 0 to 1439.
Longitude
Value of type INT
It is the longitude in hundredths of a degree. Its range starts from -18000 to +18000.
TrueSolarTime
Value of type INT
Description
This function calculates the local solar time in minutes.
4.5. Examples
There are three examples.
4.5.1. Axis management
A simple example of an axis management:
2. RESET : when the axis has an error and Reset = TRUE, the MC_Reset recovers the
error;
3. HOMING : it writes the velocities for the homing procedure and then it executes the
homing movement;
(* DINT *)
ActPos : DINT ;
ActVel : DINT ;
CmdPos : DINT ;
CmdVel : DINT ;
VelFindMicro : DINT := -4096 ;
VelOutMicro : DINT := 2048 ;
HomePosition : DINT := 0;
VelJog : DINT := 8192 ;
Move1Pos : DINT := 81920 ;
(* INT *)
HomeMode : INT := 5 ;
iStep : INT := 0 ;
(* BOOL *)
Reset : BOOL := FALSE ;
Stop : BOOL := FALSE ;
StartMove : BOOL := TRUE ;
Move1Done : BOOL := 0 ;
Move2Done : BOOL := FALSE;
err : BOOL ;
MC_Move1_inst : MC_MoveAbsolute ;
MC_Move2_inst : MC_MoveAbsolute ;
END_VAR
PROGRAM main
VAR
MC_Start_inst : MC_Start ;
MC_Reset_inst : MC_Reset ;
MC_ReadActPos_inst : MC_ReadActualPosition ;
MC_ReadPos_inst : MC_ReadCommandPosition ;
MC_Home_inst : MC_Home;
MC_Stop_inst : MC_Stop ;
END_VAR
Axis.Num := MC_REF_AXIS_MAIN ;
Enable:= MC_DriveStatus_inst.ReadyToSwitchOn) ;
(* it recovers an error *)
IF (MC_Status_inst.ErrorStop = 1) AND Reset THEN
MC_Reset_inst(Axis:=Axis, Execute:=0) ;
MC_Reset_inst.Execute := 1 ;
iStep := 0 ;
END_IF;
MC_Reset_inst(Axis:=Axis) ;
CASE iStep OF
0 :
(* Homing Procedure *)
MC_Home_inst.Execute := 0 ;
MC_Move1_inst.Execute := 0;
MC_Move2_inst.Execute := 0;
IF StartMove AND MC_Power_inst.Status THEN
MC_Home_inst.Execute := 1 ;
StartMove := 0 ;
iStep := 1 ;
END_IF;
1 :
2 :
IF MC_Move1_inst.Done THEN
MC_Move1_inst.Execute := 0 ;
MC_Move2_inst.Execute := 1 ;
ELSE
IF MC_Move2_inst.Done THEN
MC_Move1_inst.Execute := 1 ;
MC_Move2_inst.Execute := 0 ;
END_IF;
END_IF;
END_CASE ;
(* it executes a continuously
Move1Pos -> Move2Pos -> Move1Pos
movement*)
MC_Move1_inst(Axis:=Axis,
Position:=Move1Pos,
Velocity:=Move1Vel,
Acceleration:= Move1Acc,
Deceleration:=Move1Acc);
MC_Move2_inst(Axis:=Axis,
Position:=Move2Pos,
Velocity:=Move2Vel,
Acceleration:= Move2Acc,
Deceleration:=Move2Acc);
END_PROGRAM
(* exception management *)
PROGRAM exception
VAR
MC_EmergencyStop_inst : MC_EmergencyStop ;
END_VAR
(* it stops the movement because the program has had an error,
therefore it is stopped *)
MC_EmergencyStop_inst(Axis:= Axis,
Execute:=0) ;
MC_EmergencyStop_inst(Axis:= Axis,
Execute:=1,
Deceleration:= EmgDeceleration ) ;
err:=1 ;
END_PROGRAM
4.5.2. Capture example
In this section a simple management for the capture of the axis position on the zero mark is
shown. To configure the capture function it is necessary to define two characteristics:
• the event that causes the capture. The available events are: zero mark (Io_EncTrig-
gerEvent); the home digital input(Io_DInpTriggerEvent);
• the position that the function has to capture when the event happens: the function block
Io_EncEventCaptureValue is necessary to configure it.
In the following example the capture of the axis position on the zero mark is configured and
managed. The sequence to manage the capture function is:
2. when the function block Io_EncTriggerEvent detects a positive edge on the input Ex-
ecute, it starts to configure the capture function into the drive and it also calculates
the TrgEventHandle. When it finishes its internal operations, it sets to TRUE the
output EnablingCapture. This output is used from the function block Io_EncEvent-
CaptureValue to complete the configuration of the capture function.
3. When this second function block finishes its operations, then it has to set to TRUE
the input TrgStart of the rst one. In this moment the capture function starts. The
output Active is set to TRUE;
4. When TrgStart of Io_EncTriggerEvent has a rising edge, the capture function starts.
When the event happens and the position is latched, then the output Done of
Io_EncEventCaptureValue is set to TRUE and the captured value is reported in its out-
put CapturedValue.
VAR_GLOBAL(* STRUCT *)
EventRef : ENC_REF ;
CptRef : ENC_REF ;
END_VAR
PROGRAM main
Axis.Num := MC_REF_AXIS_MAIN ;
EventRef.Num := IO_REF_ENC_AX_FEEDBACK ; (* event on feedback
encoder *)
CptRef.Num := IO_REF_ENC_AXIS ; (* latch the axis position
*)
CASE iStep OF
0 :
EncTriggerEvent.Execute := 0 ;
EncEventCaptureValue.Execute := 0;
IF StartCpt THEN
EncTriggerEvent.EdgeType := 0 ;
EncTriggerEvent.OneShot := 1 ;
EncTriggerEvent.TrgStart := 0;
EncTriggerEvent.Execute := 1 ;
iStep := iStep + 1 ;
END_IF;
1 :
EncTriggerEvent.TrgStart := EncEventCaptureValue.CaptureEnabled ;
IF EncEventCaptureValue.Done THEN
CptPos := EncEventCaptureValue.CapturedValue ;
iStep := 0 ;
StartCpt := 0 ;
END_IF;
END_CASE ;
EncTriggerEvent(Reference:=EventRef);
EncEventCaptureValue(Reference:=CptRef,
Execute := EncTriggerEvent.EnablingCapture,
TrgEventHandle :=
EncTriggerEvent.TrgEventHandle);
END_PROGRAM
1. First of all, in the IEC program the semaphore IECSafeCondition has to switch to
"yellow" (see SYS_WrIECSafeCondition(0,1)). In this way, when the system manager
has to execute an action that needs that the program is in safety condition, it has to
wait that the program executes the programmed procedure to arrive in the well defined
situation;
2. Then it has to check if a request of a safety condition is arrived from the system manager
(SYS_RqsIECSafeCondition);
3. when it happens: it manages the request, so it executes a sequence of actions to put the
program in a well defined situation, that is the safety condition of the application. The
procedure reported in the example is to wait until a counter decreases its value from
50000 to 0;
Note
SYS_WrIECSafeCondition (0,1) can be thought as a traf-
fic light. When it is 0 then it means it is green, when it is 1 is equal to yellow and 2 equals to red.
In an application the status of the SYS_WrIECSafeCondition can change al-
so if there is not a request to switch to the safety condition. In this way if an application is work-
ing and it is already in its safety condition, then it can set SYS_WrIECSafeCondition to 0.
Or it can set SYS_WrIECSafeCondition to 2, in this way the application in-
forms that it can not modify its execution to put the application in the safety condition.
When SYS_WrIECSafeCondition is 1 means that the application is not in safety condi-
tion in this moment, but if a request arrives (e.g. in case a IEC program download, para-
meter le or rmware update, ...) then the application (IEC program) will execute a pro-
cedure (that must be written by the program developer) in order to put even the ma-
chine in its safety condition before to let the IEC safety procedure to start.
VAR_GLOBAL
a : DINT := 10;
d : DINT := 0;
SemIEC : INT;
err : DINT;
event : DINT;
newrqst : BOOL;
safeGo : BOOL;
delay : DINT;
Exception : INT := 0;
END_VAR
PROGRAM resetp
a := 0;
delay := 50000;
(*
* it writes the semaphore IECSafeCondition to "yellow" = 1 for all
events
* 0: all events
* 1: semaphore = yellow
*)
err := SYS_WrIECSafeCondition(0, 1);
END_PROGRAM
PROGRAM run
delay := 50000;
safeGo := FALSE;
(*
PROGRAM exception
(* after that only a forced download is allowed *)
exception := exception + 1;
END_PROGRAM
PROGRAM main
a := a + 1;
(*
* it checks if an event is requesting to program to go in safety
condition
*)
newrqst := SYS_RqsIECSafeCondition(event);
IF newrqst THEN
safeGo := TRUE;
END_IF;
(*
* it manages the safety condition procedure in the program
*)
IF safeGo THEN
delay := delay - 1;
IF delay <= 0 THEN
(* when the time is elapsed the semaphore is set to green
because
* the program is arrived in the safety condition.
* Then the execution of the program will go in Stopped mode
*)
err := SYS_WrIECSafeCondition(0, 0);
END_IF;
END_IF;
(*
* it reads the semaphore IECSafeCondition
*)
SemIEC := SYS_RdIECSafeCondition(0);
END_PROGRAM
When the program has an exception, the object 8709 returns one of these codes:
When a function block of the I/O peripheral has an exception, the object 8709 returns one of
these codes:
The parameters table is the same of the MODBUS protocol, therefore the address of the desired
parameter has to be searched in the table reported in the manual of the drive.
Figure C.1. compiling result
In the section Statistics there is the report of the memory usage. The numbers written into the
parenthesis (nnnn) are the limit values of each type of memory resource (see Section 3.2.2, “Mem-
ory resources of the drive”).
Note
In some cells of the tables there is a simplifying formula, used to summarize the ad-
dressing rule for the %MD and %MW memory area. The "n" letter in the formu-
la means the number of the byte of the %MD or %MW area (e.g. the %MD12 refers to the Dou-
ble Word that starts on the byte 12 of the %MD memory area).
e-mail: sales@cmz.it
web site: www.cmz.it