Creating a program in ST for the Lexium configuration
(Original Document)
At a glance
This section executes the different steps of the Lexium configuration. This section is only active when the step Lexium_Configuration is reached in the grafcet (see Illustration of the Move_Sequence section)
Programming structure
The programming structure is as follow:
Step number
Step description
0
Starting command of the Lexium.
10
If the Lexium is in Run State, then it switch in Homing mode using a WRITE_VAR function.
20
If the result of WRITE_VAR is conclusive then go to step 30.
30
Homing method definition using a WRITE_VAR function. For more information about the reference movement method, please refer to the Lexium user manual).
40
If the result of WRITE_VAR is conclusive then go to step 50.
50
Starting of the Homing method.
60
The Homing is done.
70
The Lexium switches in Positionning Mode using a WRITE_VAR function.
80
If the result of WRITE_VAR is conclusive then the Lexium configuration is done.
NOTE: For a correct variable declaration, click on Tools/Project Settings/Language extension then check "Directly represented array variables" and "Allow dynamic arrays".
ST Program
The example is programmed in ST structured litteral language. The dedicated section is under the same master task (MAST).
CASE Lexium_Config_Step OF
0: (* Lexium is in "Ready to switch on" position *)
IF (Lexium.statusword.0) THEN
Lexium.controlword:=Lexium_operation_enable;
Lexium_Config_Step := 10;
END_IF;
10: (* Lexium is in "Run" position *)
IF (Lexium.statusword.2) THEN (* Operating mode: Homing *)
index_subindex:=16#00006060 (*CANopen parameter address*)
%MW200:=6; (*Definition of the Lexium Function: Homing*)
%MW162:=5; (*Time out 500ms*)
%MW163:=1; (*Length 1 byte*)
WRITE_VAR(ADDM('0.0.2.55'),'SDO',index_subindex,0,%MW200:1, %MW160:4);
Lexium_Config_Step:=20;
END_IF;
20: (* Test WRITE_VAR function result *)
IF (NOT %MW160.0) THEN (* test activity bit*)
IF (%MW161=0) THEN (* correct exchange*)
Lexium_Config_Step := 30;
END_IF;
END_IF;
30: (* Homing method: set dimensions *)
index_subindex:=16#00006098
%MW150:=35; (*Definition of Homing method*)
%MW252:=5; (*Time out 500ms*)
%MW253:=1; (*Length 1 byte*)
WRITE_VAR(ADDM('0.0.2.55'),'SDO',index_subindex,0,%MW150:1, %MW250:4);
Lexium_Config_Step:=40;
40: (* Test WRITE_VAR function result *)
IF (NOT %MW250.0) THEN (* test activity bit*)
IF (%MW251=0) THEN (* correct exchange*)
New_Setpoint:=0;
Lexium_Config_Step := 50;
END_IF;
END_IF;
50: (* Trigger homing *)
New_Setpoint :=1;
Lexium_Config_Step:=60;
60: (* Homing done *)
IF (Target_Reached) AND (Homing_Done) THEN
New_Setpoint:=0;
Lexium_Config_Step:=70;
END_IF;
70: (* Operating mode: Positionnig *)
index_subindex:=16#00006060
%MW450:=1; (*Definition of Positionning method*)
%MW352:=5; (*Time out 500ms*)
%MW353:=1; (*Length 1 byte*)
WRITE_VAR(ADDM('0.0.2.55'),'SDO',index_subindex,0,%MW450:1, %MW350:4);
Lexium_Config_Step:=80;
80: (* Test WRITE_VAR function result *)
IF (NOT %MW350.0) THEN (* test activity bit*)
IF (%MW351=0) THEN (* correct exchange*)
Configuration_Done := 1;
END_IF;
END_IF;
END_CASE;