Somachine: Modbus Rtu Communications - Read/Write Variables Modbus - RW - Var - Project Example Guide
Somachine: Modbus Rtu Communications - Read/Write Variables Modbus - RW - Var - Project Example Guide
www.schneider-electric.com
The information provided in this documentation contains general descriptions and/or
technical characteristics of the performance of the products contained herein. This
documentation is not intended as a substitute for and is not to be used for
determining suitability or reliability of these products for specific user applications. It
is the duty of any such user or integrator to perform the appropriate and complete
risk analysis, evaluation and testing of the products with respect to the relevant
specific application or use thereof. Neither Schneider Electric nor any of its affiliates
or subsidiaries shall be responsible or liable for misuse of the information contained
herein. If you have any suggestions for improvements or amendments or have
found errors in this publication, please notify us.
All pertinent state, regional, and local safety regulations must be observed when
installing and using this product. For reasons of safety and to help ensure
compliance with documented system data, only the manufacturer should perform
repairs to components.
When devices are used for applications with technical safety requirements, the
relevant instructions must be followed.
Failure to use Schneider Electric software or approved software with our hardware
products may result in injury, harm, or improper operating results.
2 EIO0000000913.01 04/2012
Table of Contents
1. DESCRIPTION·············································································································13
1.1. Presentation ······························································································································· 13
6.2. LD Program································································································································· 41
EIO0000000913.01 04/2012 3
4 EIO0000000913.01 04/2012
Safety Information
Safety Information
Important Information
NOTICE
Read these instructions carefully, and look at the equipment to become familiar with the
device before trying to install, operate, or maintain it. The following special messages
may appear throughout this documentation or on the equipment to warn of potential
hazards or to call attention to information that clarifies or simplifies a procedure.
The addition of this symbol to a Danger or Warning safety label
indicates that an electrical hazard exists, which will result in personal
injury if the instructions are not followed.
DANGER
DANGER indicates an imminently hazardous situation which, if not avoided,
will result in death or serious injury.
WARNING
WARNING indicates a potentially hazardous situation which, if not avoided, can
result in death or serious injury.
CAUTION
CAUTION indicates a potentially hazardous situation which, if not avoided, can
result in minor or moderate injury.
NOTICE
NOTICE is used to address practices not related to physical injury.
PLEASE NOTE
Electrical equipment should be installed, operated, serviced, and maintained only by
qualified personnel. No responsibility is assumed by Schneider Electric for any
consequences arising out of the use of this material.
A qualified person is one who has skills and knowledge related to the construction
and operation of electrical equipment and the installation, and has received safety
training to recognize and avoid the hazards involved.
EIO0000000913.01 04/2012 5
6 EIO0000000913.01 04/2012
About the Book
At a Glance
Document Scope
This document describes one of the SoMachine examples.
Since the example described in this document is intended for learning purposes
only, it must not be run, nor tested, on products that are part of a machine or
process.
Validity Note
This document has been updated with the release of SoMachine V3.1.
The technical characteristics of the device(s) described in this manual also appear
online. To access this information online:
Step Action
1 Go to www.schneider-electric.com
2 In the Search box on the home page, type a model number. Do not type any blank
spaces in the model number. To get information on a grouping of similar modules, you
can use the characters **; do not use dots or xx's.
3 Under All, click Products → Product Datasheets and select the model number that
interests you.
4 To save or print a data sheet as a .pdf file, click Export to PDF.
The characteristics presented in this manual should be the same as those that
appear online. In line with our policy of constant improvement we may revise
content over time to improve clarity and accuracy. In the event that you see a
difference between the manual and online information, use the online information as
your reference.
Related Documents
Title of Documentation Reference Number
Modicon M238 Logic Controller Hardware Guide EIO0000000016 (ENG);
EIO0000000017 (FRE);
EIO0000000018 (GER);
EIO0000000019 (SPA);
EIO0000000020 (ITA);
EIO0000000021 (CHS)
EIO0000000913.01 04/2012 7
About the Book
8 EIO0000000913.01 04/2012
About the Book
WARNING
UNINTENDED EQUIPMENT OPERATION
Only use software approved by Schneider Electric for use with this equipment.
Update your application program every time you change the physical hardware
configuration.
Failure to follow these instructions can result in death, serious injury, or
equipment damage.
WARNING
LOSS OF CONTROL
The designer of any control scheme must consider the potential failure modes
of control paths and, for certain critical control functions, provide a means to
achieve a safe state during and after a path failure. Examples of critical control
functions are emergency stop and overtravel stop, power outage and restart.
Separate or redundant control paths must be provided for critical control
functions.
System control paths may include communication links. Consideration must be
given to the implications of unanticipated transmission delays or failures of the
link.
Observe all accident prevention regulations and local safety guidelines.1
Each implementation of this equipment must be individually and thoroughly
tested for proper operation before being placed into service.
Failure to follow these instructions can result in death, serious injury, or
equipment damage.
1
For additional information, refer to NEMA ICS 1.1 (latest edition), "Safety
Guidelines for the Application, Installation, and Maintenance of Solid State Control"
and to NEMA ICS 7.1 (latest edition), "Safety Standards for Construction and Guide
for Selection, Installation and Operation of Adjustable-Speed Drive Systems" or
their equivalent governing your particular location.
EIO0000000913.01 04/2012 9
About the Book
WARNING
REGULATORY INCOMPATIBILITY
Be sure that all equipment applied and systems designed comply with all
applicable local, regional and national regulations and standards.
Failure to follow these instructions can result in death, serious injury, or
equipment damage.
The use and application of the information contained herein require expertise in the
design and programming of automated control systems. Only the user or integrator
can be aware of all the conditions and factors present during installation and setup,
operation, and maintenance of the machine or process, and can therefore
determine the automation and associated equipment and the related safeties and
interlocks which can be effectively and properly used. When selecting automation
and control equipment, and any other related equipment or software, for a particular
application, the user or integrator must also consider any applicable local, regional
or national standards and/or regulations.
Some of the major software functions and/or hardware components used in the
proposed architectures and examples described in this document cannot be
substituted without significantly compromising the performance of your application.
Further, any such substitutions or alterations may completely invalidate any
proposed architectures, descriptions, examples, instructions, wiring diagrams and/or
compatibilities between the various hardware components and software functions
specified herein and in related documentation. You must be aware of the
consequences of any modifications, additions or substitutions. A residual risk, as
defined by EN/ISO 12100-1, Article 5, will remain if:
it is necessary to modify the recommended logic and if the added or modified
components are not properly integrated in the control circuit.
you do not follow the required standards applicable to the operation of the
machine, or if the adjustments to and the maintenance of the machine are
not properly made (it is essential to strictly follow the prescribed machine
maintenance schedule).
the devices connected to any safety outputs do not have mechanically-linked
contacts.
10 EIO0000000913.01 04/2012
About the Book
CAUTION
EQUIPMENT INCOMPATIBILITY
Read and thoroughly understand all device and software documentation before
attempting any component substitutions or other changes related to the
application examples provided in this document.
Failure to follow these instructions can result in injury or equipment
damage.
CAUTION
EQUIPMENT OPERATION HAZARD
Verify that all installation and set up procedures have been completed.
Before operational tests are performed, remove all blocks or other temporary
holding means used for shipment from all component devices.
Remove tools, meters and debris from equipment.
Failure to follow these instructions can result in injury or equipment
damage.
Verify that the completed system, including the functional safety system, is free from
all short-circuits and grounds, except those grounds installed according to local
regulations. If high-potential voltage testing is necessary, follow the
recommendations in equipment documentation to help prevent injury or equipment
damage.
EIO0000000913.01 04/2012 11
About the Book
WARNING
UNGUARDED MACHINERY CAN CAUSE SERIOUS INJURY
Do not use this software and related automation equipment on equipment
which does not have point-of-operation protection.
Do not reach into machinery during operation.
User Comments
We welcome your comments about this document. You can reach us by e-mail at
[email protected].
12 EIO0000000913.01 04/2012
1. Description
1. Description
1.1. Presentation
This example presents communications between a Modbus master and a Modbus
slave using the Modbus RTU (Remote Terminal Unit) protocol. In this example,
these exchanges are performed between an LMC058 motion controller (the Modbus
master), and an ATV12 (Altivar 12) variable speed drive (the Modbus slave).
The controller’s program is created using SoMachine software and the ATV12
variable speed drive is configured using the HMI of its front panel.
In this example, the purpose of these communications consists in performing a
periodic read request of the ETA parameter (status word) of the ATV12, and three
aperiodic read & write requests of several other parameters of the ATV12.
PC with
SoMachine
Download
& Monitoring
Serial
Transmissions
Modbus RTU
protocol
EIO0000000913.01 04/2012 13
1. Description
NOTE: This example guide is also applicable to any M238 Logic Controller or
M258 Logic Controller. This guide assumes that you are using a LMC038 Motion
Controller, but it also describes the modifications required for using a M238 Logic
Controller or M258 Logic Controller instead of this LMC038 Motion Controller.
14 EIO0000000913.01 04/2012
1. Description
EIO0000000913.01 04/2012 15
1. Description
Start
1-second delay
Result No
= OK?
End
Yes
Resets
Sets LFR Sets ACC & DEC
SP2 to SP8
read command read command
R/W command
Resets Resets
LFR ACC & DEC
R/W commands R/W commands
Converts Converts
LFR ACC & DEC
(WORD to INT) (WORD to INT)
16 EIO0000000913.01 04/2012
1. Description
(1) In this example, the Modbus function #23 (Read/Write Multiple Registers) is
used both to write SP2 to SP8 parameters and to read back the values of the
very same parameters. Here, this is intended to check that these parameters
have been updated on the ATV12 variable speed drive.
Depending on the Modbus slaves and/or the registers, it is possible that
reading/writing the same registers using Modbus function #23 in this manner
does not result in identical values. It depends on how the Modbus slave handles
this command.
In this diagram, the green boxes indicate where the functions of the
PLCCommunication library are used.
EIO0000000913.01 04/2012 17
1. Description
18 EIO0000000913.01 04/2012
1. Description
To install these libraries in your own project, please refer to Library Manager (see
page 30).
EIO0000000913.01 04/2012 19
1. Description
1
USB 3 5
2a Controller ATV12
or Pgr
2b Port MBS MODBUS / VP8S
(RJ45 connector)
(1) This software is only required if you are using a Motion Controller for
Solutions (ref. LMC058•••••S0) or a Logic Controller for Solutions (ref.
TM238••••••••S0 or TM258••••••••S0).
(2) This example guide describes how to create a SoMachine project for a
Modicon LMC058 Motion controller, but it also describes how to adapt this
project for a Modicon M238 Logic controller or a Modicon M258 Logic
controller.
20 EIO0000000913.01 04/2012
1. Description
NOTE: No line terminator (ref. VW3 A8 306 RC) is required because of the short
length of the Modbus RS485 cordset.
For the hardware setup of your controller, please refer to its Hardware Guide:
Modicon LMC058 Motion Controller Hardware Guide
Modicon M238 Logic Controller Hardware Guide
Modicon M258 Logic Controller Hardware Guide
Please refer to the Altivar 12 Variable speed drives for asynchronous motors User
manual for the hardware setup of the Altivar 12 drive.
EIO0000000913.01 04/2012 21
2. Description of the Example Content
Example of the content visible in the Devices panel of the Program tab:
22 EIO0000000913.01 04/2012
3. Creation of the Project
EIO0000000913.01 04/2012 23
3. Creation of the Project
Step Action
Or, add an M238 or M258 Logic Controller if you plan to use this type of controller
instead of an LMC058 Motion Controller.
In the following screen capture, a TM258LD42DT4L Logic Controller is selected
and added to the SoMachine project:
NOTE: Details on the selected controller are displayed in the Information section of
SoMachine.
SoMachine controller version: Defines the version of the selected controller; it is
displayed in the Information section of SoMachine.
Target controller firmware version: Defines the firmware version of your controller. This
version is shown when you select your controller’s node, as shown as in Downloading the
Example to the Controller (see page 65).
For compatibility purposes between a SoMachine controller version and a target
controller firmware version, only the first three numbers of a version must be identical. In
the preceding dialog displays, the 2.0.2.30 SoMachine controller version is compatible
with any 2.0.2.•• target controller firmware version.
For each controller model, SoMachine only presents the latest available version. If you
check the Display all versions (for expert only) option, SoMachine will list the
supported controller firmware versions. However, a good practice consists in using the
latest available version and updating the firmware of your controller, if required. Please
refer to the document that corresponds to your controller:
Modicon LMC058 Motion Controller Programming Guide
M238 ExecLoader User Guide
Modicon M258 Controller Programming Guide
24 EIO0000000913.01 04/2012
3. Creation of the Project
Step Action
3 Rename this controller.
In the following screen capture, the LMC058 Motion Controller is renamed to
LMC058_Controller:
EIO0000000913.01 04/2012 25
4. Serial Line Modbus Manager
This will remove this Manager and suggest replacing it by another Serial Line Manager.
M238 controller: This step is not necessary since a default Modbus_Manager device is
configured for its Serial Line 1. In the case of this controller, you must go to Hardware
Configuration (see page 27).
26 EIO0000000913.01 04/2012
4. Serial Line Modbus Manager
Step Action
3 LMC058 or M258 controller: The Add device window is automatically displayed to
allow you to replace the Manager just removed:
Select the Schneider Electric vendor.
Select the Modbus_Manager device.
EIO0000000913.01 04/2012 27
4. Serial Line Modbus Manager
Step Action
6 In the Configuration tab of the central panel, set the configuration shown below:
Baud rate....................... 19200
Parity ............................. None
Data bits ........................ 8
Stop bits ........................ 1
Physical Medium ........... RS 485
Polarisation Resistor ..... No
28 EIO0000000913.01 04/2012
4. Serial Line Modbus Manager
Step Action
8 In the Configuration tab of the central panel, change the Addressing from Slave to
Master:
EIO0000000913.01 04/2012 29
5. Library Manager
5. Library Manager
The steps listed in the following table describe how to add and/or check the list of
the libraries linked to this example.
Step Action
1 Select the Program tab.
In the Devices tree view, double-click on the Library Manager to open the list of the
libraries linked to the Application software of this example.
2 Check that the PLCCommunication, Standard, and Util libraries are already linked, as
shown below:
NOTE: These libraries are grayed to inform that they have been automatically linked to
the program upon addition of the controller to the project and that they cannot be
removed.
30 EIO0000000913.01 04/2012
6. ST, LD, or CFC Program
In addition, each of these three chapters begins with detailed explanations of any
optional steps.
EIO0000000913.01 04/2012 31
6. ST, LD, or CFC Program
6.1. ST Program
Step Action
1 Creation of the POU: Create a new POU in ST language, called PLC_PRG_ST.
PROGRAM PLC_PRG_ST
VAR
(*********************)
(*** TON Variables ***)
(*********************)
(**********************)
(*** ADDM Variables ***)
(**********************)
// ADDM Function Block for formatting the address of the ATV12 Modbus Slave
ADDM_MODBUS_ATV12 : ADDM;
// ADDRESS structure for the address of the ATV12 Modbus Slave
v_addressModbusAtv12 : ADDRESS;
// "Done" result of the Address conversion
v_xAddressDone : BOOL := FALSE;
// "Error" result of the Address conversion
v_xAddressError : BOOL := FALSE;
(******************************)
(*** ETA Register Variables ***)
(******************************)
32 EIO0000000913.01 04/2012
6. ST, LD, or CFC Program
Step Action
// BLINK Function Block for periodic reading of the ETA register
BLINK_ETA : BLINK;
// "OUT" output of the BLINK Function Block: Clock
v_xClockReadETARegister : BOOL := FALSE;
// READ_VAR Function Block for reading the ETA register of the ATV12 Modbus
// device
READ_VAR_ETA : READ_VAR;
// Buffer for the value of the ETA register
v_wRegisterETA : WORD := 0;
// "Done" result of the ETA register read operation
v_xReadETADone : BOOL := FALSE;
// "Busy" output of the ETA register read operation
v_xReadETABusy : BOOL := FALSE;
// "Error" result of the ETA register read operation
v_xReadETAError : BOOL := FALSE;
// "CommError" result of the ETA register read operation
v_bReadETACommError : BYTE := CommunicationErrorCodes.CommunicationOK;
(******************************)
(*** LFR Register Variables ***)
(******************************)
// Value of the LFR register to write on the device (-400.0 Hz to +400.0 Hz;
// unit: 0.1 Hz)
v_iWriteLFRValue : INT := 0;
// SINGLE_WRITE Function Block for writing the LFR register of the ATV12 Modbus
// device
SINGLE_WRITE_LFR : SINGLE_WRITE;
// Value of the LFR register to write on the device (after conversion to WORD)
v_wWriteLFRValue : WORD := 0;
// "Busy" output of the LFR register write operation
v_xWriteLFRBusy : BOOL := FALSE;
// READ_VAR Function Block for reading the new value of the LFR register of the
// ATV12 Modbus device
READ_VAR_LFR : READ_VAR;
// Buffer for the value of the LFR register
v_wRegisterLFR : WORD := 0;
// "Busy" output of the LFR register read operation
v_xReadLFRBusy : BOOL := FALSE;
// Value of the LFR register read on the device (-400.0 Hz to +400.0 Hz; unit:
// 0.1 Hz)
v_iReadLFRValue : INT := 0;
(*************************************)
(*** ACC & DEC Registers Variables ***)
(*************************************)
// MANUAL command for starting one ACC & DEC registers write operation
v_xCmdManualWriteACC_DEC : BOOL := FALSE;
// Automatic command for reading the new values of the ACC & DEC registers
v_xCmdAutoReadACC_DEC : BOOL := FALSE;
EIO0000000913.01 04/2012 33
6. ST, LD, or CFC Program
Step Action
// Command to write the ACC & DEC registers
v_xWriteACC_DECRegisters : BOOL := FALSE;
// Value of the ACC & DEC registers to write on the device (0.0 s to 999.9 s;
// unit: 0.1 s)
v_iWriteACCValue : INT := 0;
v_iWriteDECValue : INT := 0;
// WRITE_VAR Function Block for writing the ACC & DEC registers of the ATV12
// Modbus device
WRITE_VAR_ACC_DEC : WRITE_VAR;
// Buffer for the values of the ACC & DEC registers to write on the device (after
// conversion to WORD)
v_wWriteACC_DECValues : ARRAY [0..1] OF WORD := [0,0];
// "Busy" output of the ACC & DEC registers write operation
v_xWriteACC_DECBusy : BOOL := FALSE;
// READ_VAR Function Block for reading the new value of the ACC & DEC registers
// of the ATV12 Modbus device
READ_VAR_ACC_DEC : READ_VAR;
// Buffer for the values of the ACC & DEC registers
v_wRegisterACC_DEC : ARRAY[0..1] OF WORD := [0,0];
// "Busy" output of the ACC & DEC registers read operation
v_xReadACC_DECBusy : BOOL := FALSE;
// Value of the ACC & DEC registers read from the device (0.0 s to 999.9 s; unit:
// 0.1 s)
v_iReadACCValue : INT := 0;
v_iReadDECValue : INT := 0;
(**************************************)
(*** SP2 to SP8 Registers Variables ***)
(**************************************)
// MANUAL command for starting one SP2 to SP8 registers write & read operation
v_xCmdManualWrRdSP2_SP8 : BOOL := FALSE;
// Values of the SP2 to SP8 registers to write on the device (0.0 Hz to 400.0 Hz;
// unit: 0.1 Hz)
v_uiWriteSP2Value : UINT := 0;
v_uiWriteSP3Value : UINT := 0;
v_uiWriteSP4Value : UINT := 0;
v_uiWriteSP5Value : UINT := 0;
v_uiWriteSP6Value : UINT := 0;
v_uiWriteSP7Value : UINT := 0;
v_uiWriteSP8Value : UINT := 0;
// WRITE_READ_VAR Function Block for writing & reading the SP2 to SP8 registers
// of the ATV12 Modbus device
WRITE_READ_VAR_SP2_SP8 : WRITE_READ_VAR;
// Buffer for the values of the SP2 to SP8 registers to write on the device
// (after conversion to WORD)
v_wWriteSP2_SP8Values : ARRAY [0..6] OF WORD := [7(0)];
// Buffer for the values of the SP2 to SP8 registers read from the device
v_wReadSP2_SP8Values : ARRAY [0..6] OF WORD := [7(0)];
// "Busy" output of the SP2 to SP8 registers write & read operation
v_xWriteSP2_SP8Busy : BOOL := FALSE;
// Values of the SP2 to SP8 registers read from the device (0.0 Hz to 400.0 Hz;
// unit: 0.1 Hz)
v_uiReadSP2Value : UINT := 0;
v_uiReadSP3Value : UINT := 0;
v_uiReadSP4Value : UINT := 0;
v_uiReadSP5Value : UINT := 0;
v_uiReadSP6Value : UINT := 0;
v_uiReadSP7Value : UINT := 0;
v_uiReadSP8Value : UINT := 0;
END_VAR
34 EIO0000000913.01 04/2012
6. ST, LD, or CFC Program
Step Action
3 ST program: In the lower part of the ST editor, implement the following program:
(*************************************************************)
(* TON Function Block for delaying the start of this program *)
(*************************************************************)
(********************************************************)
(*** Formatting the Address of the ATV12 Modbus Slave ***)
(*** Function Block(s): ADDM ***)
(********************************************************)
(* ADDM Function Block for formatting the address of the ATV12 Modbus Slave *)
(* Note: In ST language, this call syntax is required for Function Blocks that
include *)
(* at least one "VAR_IN_OUT" variable ("AddrTable" in the case of ADDM)
*)
ADDM_MODBUS_ATV12(
AddrTable := v_addressModbusAtv12, // IN/OUT - Resulting ADDRESS structure
Execute := v_xStartProgram , // IN - Rising Edge signal that triggers
// this Function Block
Addr := '1.2' , // IN - Modbus Serial Address Format =
// '<communication port number>.<slave address>'
Done => v_xAddressDone , // OUT - Resulting address is OK
Error => v_xAddressError , // OUT - Resulting address is not OK
(*CommError*) ); // OUT - This error code is not used in
// this program
(******************************************************************)
(*** Periodic Communications: ETA Register read once per second ***)
(*** Function Block(s): READ_VAR ***)
(******************************************************************)
(* BLINK Function Block for periodic reading of the ETA register: 1-second clock *)
BLINK_ETA.ENABLE := TRUE; // IN - Enabled (TRUE)
BLINK_ETA.TIMELOW := T#500MS; // IN - Duration of the LOW state (500ms)
BLINK_ETA.TIMEHIGH := T#500MS; // IN - Duration of the HIGH state (500ms)
BLINK_ETA(); // Function Block call
v_xClockReadETARegister := BLINK_ETA.OUT; // OUT - Resulting clock
(* READ_VAR Function Block for reading the ETA register of the ATV12 Modbus device *)
(* Note: In ST language, this call syntax is required for Function Blocks of the
*)
(* 'PLCCommunication' library that use an 'Addr' INPUT variable (data type =
ADDRESS) *)
READ_VAR_ETA(
Execute := v_xReadETARegister, // IN - Rising Edge signal that triggers
// this Function Block
Abort := FALSE, // IN - Function Block not aborted (FALSE)
Addr := v_addressModbusAtv12, // IN - Formatted address of the ATV12
// Modbus device
Timeout := 5, // IN - Timeout of 500 ms
ObjType := ObjectType.MW, // IN - Type of object to be read: MW
// --> The Modbus function #3 (read
// holding registers) is used
FirstObj := 3201, // IN - First object to be read: ETA
// register (address = 3201)
Quantity := 1, // IN - Number of objects to read:
// 1 register
Buffer := ADR(v_wRegisterETA), // IN - Address of the variable for
// RECEIVING the value of the
// ETA register
Done => v_xReadETADone, // OUT - "Done" result of the ETA register
EIO0000000913.01 04/2012 35
6. ST, LD, or CFC Program
Step Action
// read operation
Busy => v_xReadETABusy, // OUT - "Busy" output of the ETA register
// read operation
(*Aborted*) // OUT - This output is not used in this
// program
Error => v_xReadETAError, // OUT - "Error" result of the ETA register
// read operation
CommError => v_bReadETACommError); // OUT - "CommError" result of the ETA
// register read operation
(*OperError*) // OUT - This error code is not used in
// this program
(* The ATV12 Modbus device is present (TRUE) if it has correctly answered (once the
BUSY is FALSE) *)
IF NOT v_xReadETABusy AND NOT v_xReadETAError AND v_xReadETADone THEN
v_xPresenceAtv12 := TRUE; // The ATV12 is present
v_xCommErrorAtv12 := FALSE; // No communication error
(* Otherwise, a communication error is reported: Timeout or other error? (once the
BUSY is FALSE) *)
ELSIF NOT v_xReadETABusy AND READ_VAR_ETA.Error THEN
IF (v_bReadETACommError = CommunicationErrorCodes.TimedOut) THEN
v_xPresenceAtv12 := FALSE; // The ATV12 is absent
ELSE
v_xCommErrorAtv12 := TRUE; // Communication error (Timeout excluded)
END_IF
END_IF
(******************************************************************)
(*** On-demand command : LFR Register Write + LFR Register Read ***)
(*** Function Block(s): SINGLE_WRITE + READ_VAR ***)
(******************************************************************)
(* Conversion from INT to WORD of the LFR register value to write on the device
*)
(* NOTE: The conversion must preserve the +/- sign in the case of the LFR register.
*)
v_wWriteLFRValue := INT_TO_WORD(v_iWriteLFRValue);
(* Command to write the LFR register: IF Address is OK AND Manual Command to Write
LFR *)
v_xWriteLFRRegister := v_xAddressIsOK AND v_xCmdManualWriteLFR;
(* SINGLE_WRITE Function Block for writing the LFR register of the ATV12 Modbus
device *)
(* Note: In ST language, this call syntax is required for Function Blocks of the
*)
(* 'PLCCommunication' library that use an 'Addr' INPUT variable (data type =
ADDRESS) *)
SINGLE_WRITE_LFR(
Execute := v_xWriteLFRRegister, // IN - Rising Edge signal that triggers
// this Function Block
Abort := FALSE, // IN - Function Block not aborted (FALSE)
Addr := v_addressModbusAtv12, // IN - Formatted address of the ATV12
// Modbus device
Timeout := 5, // IN - Timeout of 500 ms
ObjType := ObjectType.MW, // IN - Type of object to be written: MW
// --> The Modbus function #6 (write
// single register) is used
FirstObj := 8502, // IN - Object to be written: LFR register
// (address = 8502)
theWord := v_wWriteLFRValue, // IN - Value to write in the LFR register
// of the ATV12 Modbus device
(*Done*) // OUT - This output is not used in this
// program
Busy => v_xWriteLFRBusy); // OUT - "Busy" output of the ETA register
// read operation
(*Aborted*) // OUT - This output is not used in this
// program
(*Error*) // OUT - This output is not used in this
// program
(*CommError*) // OUT - This output is not used in this
// program
(*OperError*) // OUT - This output is not used in this
// program
(* Upon completion of the LFR WRITE operation, an automatic LFR READ operation *)
(* is performed to check if the value of the LFR register has been updated *)
36 EIO0000000913.01 04/2012
6. ST, LD, or CFC Program
Step Action
IF v_xWriteLFRRegister AND NOT v_xWriteLFRBusy THEN
v_xCmdAutoReadLFR := TRUE;
END_IF
(* Command to read the LFR register: IF Address is OK AND Automatic Command to Read
LFR *)
v_xReadLFRRegister := v_xAddressIsOK AND v_xCmdAutoReadLFR;
(* READ_VAR Function Block for reading the new value of the LFR register of the ATV12
Modbus device *)
(* Note: In ST language, this call syntax is required for Function Blocks of the
*)
(* 'PLCCommunication' library that use an 'Addr' INPUT variable (data type =
ADDRESS) *)
READ_VAR_LFR(
Execute := v_xReadLFRRegister, // IN - Rising Edge signal that triggers
// this Function Block
Abort := FALSE, // IN - Function Block not aborted (FALSE)
Addr := v_addressModbusAtv12, // IN - Formatted address of the ATV12
// Modbus device
Timeout := 5, // IN - Timeout of 500 ms
ObjType := ObjectType.MW, // IN - Type of object to be read: MW
// --> The Modbus function #3 (read
// holding registers) is used
FirstObj := 8502, // IN - First object to be read: LFR
// register (address = 8502)
Quantity := 1, // IN - Number of objects to read:
// 1 register
Buffer := ADR(v_wRegisterLFR), // IN - Address of the variable for
// RECEIVING the value of the
// LFR register
(*Done*) // OUT - This output is not used in this
// program
Busy => v_xReadLFRBusy); // OUT - "Busy" output of the LFR register
// read operation
(*Aborted*) // OUT - This output is not used in this
// program
(*Error*) // OUT - This output is not used in this
// program
(*CommError*) // OUT - This output is not used in this
// program
(*OperError*) // OUT - This output is not used in this
// program
(* Upon completion of the LFR READ operation, both LFR WRITE and LFR READ operations
*)
(* are ended AND the read value is converted from WORD to INT.
*)
IF v_xReadLFRRegister AND NOT v_xReadLFRBusy THEN
v_xCmdManualWriteLFR := FALSE;
v_xCmdAutoReadLFR := FALSE;
(* Conversion from WORD to INT of the LFR register value read on the device
*)
(* NOTE: The conversion must preserve the +/- sign in the case of the LFR
register. *)
v_iReadLFRValue := WORD_TO_INT(v_wRegisterLFR);
END_IF
(********************************************************************************)
(*** On-demand command : ACC & DEC Registers Write + ACC & DEC Registers Read ***)
(*** Function Block(s): WRITE_VAR + READ_VAR ***)
(********************************************************************************)
(* Conversion from INT to WORD of the ACC & DEC registers values to write on the
device *)
v_wWriteACC_DECValues[0] := INT_TO_WORD(v_iWriteACCValue); // 1st WORD = ACC Register
v_wWriteACC_DECValues[1] := INT_TO_WORD(v_iWriteDECValue); // 2nd WORD = DEC Register
(* Command to write the ACC & DEC registers: IF Address is OK AND Manual Command to
Write ACC & DEC *)
v_xWriteACC_DECRegisters := v_xAddressIsOK AND v_xCmdManualWriteACC_DEC;
(* WRITE_VAR Function Block for writing the ACC & DEC registers of the ATV12 Modbus
device *)
(* Note: In ST language, this call syntax is required for Function Blocks of the
*)
(* 'PLCCommunication' library that use an 'Addr' INPUT variable (data type =
EIO0000000913.01 04/2012 37
6. ST, LD, or CFC Program
Step Action
ADDRESS) *)
WRITE_VAR_ACC_DEC(
Execute := v_xWriteACC_DECRegisters, // IN - Rising Edge signal that
// triggers this Function Block
Abort := FALSE, // IN - Function Block not aborted
// (FALSE)
Addr := v_addressModbusAtv12, // IN - Formatted address of the ATV12
// Modbus device
Timeout := 5, // IN - Timeout of 500 ms
ObjType := ObjectType.MW, // IN - Type of object to be written:
// MW --> The Modbus function #16
// (write multiple
// registers) is used
FirstObj := 9001, // IN - Object to be written: ACC &
// DEC registers (addresses =
// 9001 & 9002)
Quantity := 2, // IN - Number of objects to write:
// 2 registers
Buffer := ADR(v_wWriteACC_DECValues), // IN - Address of the variables which
// values will be SENT to the ACC
// & DEC Registers
(*Done*) // OUT - This output is not used in
// this program
Busy => v_xWriteACC_DECBusy); // OUT - "Busy" output of the ACC & DEC
// registers read operation
(*Aborted*) // OUT - This output is not used in
// this program
(*Error*) // OUT - This output is not used in
// this program
(*CommError*) // OUT - This output is not used in
// this program
(*OperError*) // OUT - This output is not used in
// this program
(* Upon completion of the ACC & DEC WRITE operation, an automatic ACC & DEC READ
operation *)
(* is performed to check if the values of the ACC & DEC registers have been updated
*)
IF v_xWriteACC_DECRegisters AND NOT v_xWriteACC_DECBusy THEN
v_xCmdAutoReadACC_DEC := TRUE;
END_IF
(* Command to read the ACC & DEC registers: IF Address is OK AND Automatic Command to
Read ACC & DEC *)
v_xReadACC_DECRegisters := v_xAddressIsOK AND v_xCmdAutoReadACC_DEC;
(* READ_VAR Function Block for reading the new values of the ACC & DEC registers of
the ATV12 Modbus device *)
(* Note: In ST language, this call syntax is required for Function Blocks of the
*)
(* 'PLCCommunication' library that use an 'Addr' INPUT variable (data type =
ADDRESS) *)
READ_VAR_ACC_DEC(
Execute := v_xReadACC_DECRegisters, // IN - Rising Edge signal that triggers
// this Function Block
Abort := FALSE, // IN - Function Block not aborted
// (FALSE)
Addr := v_addressModbusAtv12, // IN - Formatted address of the ATV12
// Modbus device
Timeout := 5, // IN - Timeout of 500 ms
ObjType := ObjectType.MW, // IN - Type of object to be read: MW
// --> The Modbus function #3 (read
// holding registers) is used
FirstObj := 9001, // IN - Objects to be read: ACC & DEC
// registers (addresses = 9001 &
// 9002)
Quantity := 2, // IN - Number of objects to read:
// 2 registers
Buffer := ADR(v_wRegisterACC_DEC), // IN - Address of the variables for
// RECEIVING the values of the ACC &
// DEC registers
(*Done*) // OUT - This output is not used in this
// program
Busy => v_xReadACC_DECBusy); // OUT - "Busy" output of the ACC & DEC
// registers read operation
(*Aborted*) // OUT - This output is not used in this
// program
(*Error*) // OUT - This output is not used in this
38 EIO0000000913.01 04/2012
6. ST, LD, or CFC Program
Step Action
// program
(*CommError*) // OUT - This output is not used in this
// program
(*OperError*) // OUT - This output is not used in this
// program
(* Upon completion of the ACC & DEC READ operations, both ACC & DEC WRITE and ACC &
DEC READ *)
(* operations are ended AND the read values are converted from WORD to INT.
*)
IF v_xReadACC_DECRegisters AND NOT v_xReadACC_DECBusy THEN
v_xCmdManualWriteACC_DEC := FALSE;
v_xCmdAutoReadACC_DEC := FALSE;
(* Conversion from WORD to INT of the ACC & DEC registers values read on the
device *)
v_iReadACCValue := WORD_TO_INT(v_wRegisterACC_DEC[0]);
v_iReadDECValue := WORD_TO_INT(v_wRegisterACC_DEC[1]);
END_IF
(*************************************************************)
(*** On-demand command : SP2 to SP8 Registers Write & Read ***)
(*** Function Block(s): WRITE_READ_VAR ***)
(*************************************************************)
(* Conversion from UINT to WORD of the SP2 to SP8 registers values to write on the
device *)
v_wWriteSP2_SP8Values[0] := UINT_TO_WORD(v_uiWriteSP2Value); // 1st WORD=SP2 Register
v_wWriteSP2_SP8Values[1] := UINT_TO_WORD(v_uiWriteSP3Value); // 2nd WORD=SP3 Register
v_wWriteSP2_SP8Values[2] := UINT_TO_WORD(v_uiWriteSP4Value); // 3rd WORD=SP4 Register
v_wWriteSP2_SP8Values[3] := UINT_TO_WORD(v_uiWriteSP5Value); // 4th WORD=SP5 Register
v_wWriteSP2_SP8Values[4] := UINT_TO_WORD(v_uiWriteSP6Value); // 5th WORD=SP6 Register
v_wWriteSP2_SP8Values[5] := UINT_TO_WORD(v_uiWriteSP7Value); // 6th WORD=SP7 Register
v_wWriteSP2_SP8Values[6] := UINT_TO_WORD(v_uiWriteSP8Value); // 7th WORD=SP8 Register
(* Command to write the SP2 to SP8 registers: IF Address is OK AND Manual Command to
Write & Read SP2 to SP8 *)
v_xWrRdSP2_SP8Registers := v_xAddressIsOK AND v_xCmdManualWrRdSP2_SP8;
(* WRITE_READ_VAR Function Block for writing & reading the SP2 to SP8 registers of
the ATV12 Modbus device *)
(* Note: In ST language, this call syntax is required for Function Blocks of the
*)
(* 'PLCCommunication' library that use an 'Addr' INPUT variable (data type =
ADDRESS) *)
WRITE_READ_VAR_SP2_SP8(
Execute := v_xWrRdSP2_SP8Registers, // IN - Rising Edge signal that
// triggers this Function
// Block
Abort := FALSE, // IN - Function Block not aborted
// (FALSE)
Addr := v_addressModbusAtv12, // IN - Formatted address of the
// ATV12 Modbus device
Timeout := 5, // IN - Timeout of 500 ms
ObjType := ObjectType.MW, // IN - Type of object to be
// written: MW --> The Modbus
// function #23 (read/write
// multiple registers) is used
FirstWriteObj := 11410, // IN - Object to be written: SP2
// to SP8 registers (addresses
// = 11410 to 11416)
WriteQuantity := 7, // IN - Number of objects to write:
// 7 registers
WriteBuffer := ADR(v_wWriteSP2_SP8Values), // IN - Address of the variables
// which values will be SENT
// to the SP2 to SP8 Registers
FirstReadObj := 11410, // IN - Object to be read: SP2 to
// SP8 registers (addresses =
// 11410 to 11416)
ReadQuantity := 7, // IN - Number of objects to read:
// 7 registers
ReadBuffer := ADR(v_wReadSP2_SP8Values), // IN - Address of the variables
// for RECEIVING the values of
// the SP2 to SP8 register
(*Done*) // OUT - This output is not used in
// this program
Busy => v_xWriteSP2_SP8Busy); // OUT - "Busy" output of the ACC &
// DEC registers read
EIO0000000913.01 04/2012 39
6. ST, LD, or CFC Program
Step Action
// operation
(*Aborted*) // OUT - This output is not used in
// this program
(*Error*) // OUT - This output is not used in
// this program
(*CommError*) // OUT - This output is not used in
// this program
(*OperError*) // OUT - This output is not used in
// this program
(* Upon completion of the SP2 to SP8 WRITE & READ operation, it is ended *)
(* AND the read values are converted from WORD to UINT. *)
IF v_xWrRdSP2_SP8Registers AND NOT v_xWriteSP2_SP8Busy THEN
v_xCmdManualWrRdSP2_SP8 := FALSE;
(* Conversion from WORD to UINT of the SP2 to SP8 registers values read on the
device *)
v_uiReadSP2Value := WORD_TO_UINT(v_wReadSP2_SP8Values[0]);
v_uiReadSP3Value := WORD_TO_UINT(v_wReadSP2_SP8Values[1]);
v_uiReadSP4Value := WORD_TO_UINT(v_wReadSP2_SP8Values[2]);
v_uiReadSP5Value := WORD_TO_UINT(v_wReadSP2_SP8Values[3]);
v_uiReadSP6Value := WORD_TO_UINT(v_wReadSP2_SP8Values[4]);
v_uiReadSP7Value := WORD_TO_UINT(v_wReadSP2_SP8Values[5]);
v_uiReadSP8Value := WORD_TO_UINT(v_wReadSP2_SP8Values[6]);
END_IF
40 EIO0000000913.01 04/2012
6. ST, LD, or CFC Program
6.2. LD Program
The following table presents one optional step that gives you information on how to
program in LD language.
Step Action
1 Optional step
How to display titles and comments in LD language
Select the Options… command of the Tools menu.
Select, in the Options window, the FBD, LD and IL editor section.
If you wish to add a title and/or a comment for each LD network, check the Show
network title and/or the Show network comment options, as shown below:
EIO0000000913.01 04/2012 41
6. ST, LD, or CFC Program
Step Action
2 Creation of the POU: Create a new POU in LD language, called PLC_PRG_LD.
PROGRAM PLC_PRG_LD
VAR
(*********************)
(*** TON Variables ***)
(*********************)
(**********************)
(*** ADDM Variables ***)
(**********************)
// ADDM Function Block for formatting the address of the ATV12 Modbus Slave
ADDM_MODBUS_ATV12 : ADDM;
// ADDRESS structure for the address of the ATV12 Modbus Slave
v_addressModbusAtv12 : ADDRESS;
// "Done" result of the Address conversion
v_xAddressDone : BOOL := FALSE;
// "Error" result of the Address conversion
v_xAddressError : BOOL := FALSE;
(******************************)
(*** ETA Register Variables ***)
(******************************)
42 EIO0000000913.01 04/2012
6. ST, LD, or CFC Program
Step Action
// READ_VAR Function Block for reading the ETA register of the ATV12 Modbus device
READ_VAR_ETA : READ_VAR;
// Buffer for the value of the ETA register
v_wRegisterETA : WORD := 0;
// "Done" result of the ETA register read operation
v_xReadETADone : BOOL := FALSE;
// "Busy" output of the ETA register read operation
v_xReadETABusy : BOOL := FALSE;
// "Error" result of the ETA register read operation
v_xReadETAError : BOOL := FALSE;
// "CommError" result of the ETA register read operation
v_bReadETACommError : BYTE := CommunicationErrorCodes.CommunicationOK;
(******************************)
(*** LFR Register Variables ***)
(******************************)
// Value of the LFR register to write on the device (-400.0 Hz to +400.0 Hz; unit:
// 0.1 Hz)
v_iWriteLFRValue : INT := 0;
// SINGLE_WRITE Function Block for writing the LFR register of the ATV12 Modbus
// device
SINGLE_WRITE_LFR : SINGLE_WRITE;
// Value of the LFR register to write on the device (after conversion to WORD)
v_wWriteLFRValue : WORD := 0;
// "Busy" output of the LFR register write operation
v_xWriteLFRBusy : BOOL := FALSE;
// READ_VAR Function Block for reading the new value of the LFR register of the ATV12
// Modbus device
READ_VAR_LFR : READ_VAR;
// Buffer for the value of the LFR register
v_wRegisterLFR : WORD := 0;
// "Busy" output of the LFR register read operation
v_xReadLFRBusy : BOOL := FALSE;
// Value of the LFR register read on the device (-400.0 Hz to +400.0 Hz; unit: 0.1Hz)
v_iReadLFRValue : INT := 0;
(*************************************)
(*** ACC & DEC Registers Variables ***)
(*************************************)
// MANUAL command for starting one ACC & DEC registers write operation
v_xCmdManualWriteACC_DEC : BOOL := FALSE;
// Automatic command for reading the new values of the ACC & DEC registers
v_xCmdAutoReadACC_DEC : BOOL := FALSE;
// Value of the ACC & DEC registers to write on the device (0.0 s to 999.9 s; unit:
// 0.1 s)
v_iWriteACCValue : INT := 0;
v_iWriteDECValue : INT := 0;
EIO0000000913.01 04/2012 43
6. ST, LD, or CFC Program
Step Action
// WRITE_VAR Function Block for writing the ACC & DEC registers of the ATV12 Modbus
// device
WRITE_VAR_ACC_DEC : WRITE_VAR;
// Buffer for the values of the ACC & DEC registers to write on the device (after
// conversion to WORD)
v_wWriteACC_DECValues : ARRAY [0..1] OF WORD := [0,0];
// "Busy" output of the ACC & DEC registers write operation
v_xWriteACC_DECBusy : BOOL := FALSE;
// READ_VAR Function Block for reading the new value of the ACC & DEC registers of
// the ATV12 Modbus device
READ_VAR_ACC_DEC : READ_VAR;
// Buffer for the values of the ACC & DEC registers
v_wRegisterACC_DEC : ARRAY[0..1] OF WORD := [0,0];
// "Busy" output of the ACC & DEC registers read operation
v_xReadACC_DECBusy : BOOL := FALSE;
// Value of the ACC & DEC registers read from the device (0.0 s to 999.9 s; unit:
// 0.1 s)
v_iReadACCValue : INT := 0;
v_iReadDECValue : INT := 0;
(**************************************)
(*** SP2 to SP8 Registers Variables ***)
(**************************************)
// MANUAL command for starting one SP2 to SP8 registers write & read operation
v_xCmdManualWrRdSP2_SP8 : BOOL := FALSE;
// Values of the SP2 to SP8 registers to write on the device (0.0 Hz to 400.0 Hz;
// unit: 0.1 Hz)
v_uiWriteSP2Value : UINT := 0;
v_uiWriteSP3Value : UINT := 0;
v_uiWriteSP4Value : UINT := 0;
v_uiWriteSP5Value : UINT := 0;
v_uiWriteSP6Value : UINT := 0;
v_uiWriteSP7Value : UINT := 0;
v_uiWriteSP8Value : UINT := 0;
// WRITE_READ_VAR Function Block for writing & reading the SP2 to SP8 registers of
// the ATV12 Modbus device
WRITE_READ_VAR_SP2_SP8 : WRITE_READ_VAR;
// Buffer for the values of the SP2 to SP8 registers to write on the device (after
// conversion to WORD)
v_wWriteSP2_SP8Values : ARRAY [0..6] OF WORD := [7(0)];
// Buffer for the values of the SP2 to SP8 registers read from the device
v_wReadSP2_SP8Values : ARRAY [0..6] OF WORD := [7(0)];
// "Busy" output of the SP2 to SP8 registers write & read operation
v_xWriteSP2_SP8Busy : BOOL := FALSE;
// Values of the SP2 to SP8 registers read from the device (0.0 Hz to 400.0 Hz; unit:
// 0.1 Hz)
v_uiReadSP2Value : UINT := 0;
v_uiReadSP3Value : UINT := 0;
v_uiReadSP4Value : UINT := 0;
v_uiReadSP5Value : UINT := 0;
v_uiReadSP6Value : UINT := 0;
v_uiReadSP7Value : UINT := 0;
v_uiReadSP8Value : UINT := 0;
END_VAR
44 EIO0000000913.01 04/2012
6. ST, LD, or CFC Program
Step Action
4 LD program: In the lower part of the LD editor, implement the following program:
EIO0000000913.01 04/2012 45
6. ST, LD, or CFC Program
Step Action
46 EIO0000000913.01 04/2012
6. ST, LD, or CFC Program
Step Action
EIO0000000913.01 04/2012 47
6. ST, LD, or CFC Program
Step Action
48 EIO0000000913.01 04/2012
6. ST, LD, or CFC Program
Step Action
EIO0000000913.01 04/2012 49
6. ST, LD, or CFC Program
Step Action
1 Creation of the POU: Create a new POU in CFC language, called PLC_PRG_CFC.
PROGRAM PLC_PRG_CFC
VAR
(*********************)
(*** TON Variables ***)
(*********************)
(**********************)
(*** ADDM Variables ***)
(**********************)
// ADDM Function Block for formatting the address of the ATV12 Modbus Slave
ADDM_MODBUS_ATV12 : ADDM;
// ADDRESS structure for the address of the ATV12 Modbus Slave
v_addressModbusAtv12 : ADDRESS;
// "Done" result of the Address conversion
v_xAddressDone : BOOL := FALSE;
// "Error" result of the Address conversion
v_xAddressError : BOOL := FALSE;
(******************************)
(*** ETA Register Variables ***)
(******************************)
50 EIO0000000913.01 04/2012
6. ST, LD, or CFC Program
Step Action
// "OUT" output of the BLINK Function Block: Clock
v_xClockReadETARegister : BOOL := FALSE;
// READ_VAR Function Block for reading the ETA register of the ATV12 Modbus device
READ_VAR_ETA : READ_VAR;
// Buffer for the value of the ETA register
v_wRegisterETA : WORD := 0;
// "Done" result of the ETA register read operation
v_xReadETADone : BOOL := FALSE;
// "Busy" output of the ETA register read operation
v_xReadETABusy : BOOL := FALSE;
// "Error" result of the ETA register read operation
v_xReadETAError : BOOL := FALSE;
// "CommError" result of the ETA register read operation
v_bReadETACommError : BYTE := CommunicationErrorCodes.CommunicationOK;
(******************************)
(*** LFR Register Variables ***)
(******************************)
// Value of the LFR register to write on the device (-400.0 Hz to +400.0 Hz; unit:
// 0.1 Hz)
v_iWriteLFRValue : INT := 0;
// SINGLE_WRITE Function Block for writing the LFR register of the ATV12 Modbus
// device
SINGLE_WRITE_LFR : SINGLE_WRITE;
// Value of the LFR register to write on the device (after conversion to WORD)
v_wWriteLFRValue : WORD := 0;
// "Busy" output of the LFR register write operation
v_xWriteLFRBusy : BOOL := FALSE;
// READ_VAR Function Block for reading the new value of the LFR register of the ATV12
// Modbus device
READ_VAR_LFR : READ_VAR;
// Buffer for the value of the LFR register
v_wRegisterLFR : WORD := 0;
// "Busy" output of the LFR register read operation
v_xReadLFRBusy : BOOL := FALSE;
// Value of the LFR register read on the device (-400.0 Hz to +400.0 Hz; unit: 0.1
// Hz)
v_iReadLFRValue : INT := 0;
(*************************************)
(*** ACC & DEC Registers Variables ***)
(*************************************)
// MANUAL command for starting one ACC & DEC registers write operation
v_xCmdManualWriteACC_DEC : BOOL := FALSE;
// Automatic command for reading the new values of the ACC & DEC registers
v_xCmdAutoReadACC_DEC : BOOL := FALSE;
EIO0000000913.01 04/2012 51
6. ST, LD, or CFC Program
Step Action
// Command to write the ACC & DEC registers
v_xWriteACC_DECRegisters : BOOL := FALSE;
// Value of the ACC & DEC registers to write on the device (0.0 s to 999.9 s; unit:
// 0.1 s)
v_iWriteACCValue : INT := 0;
v_iWriteDECValue : INT := 0;
// WRITE_VAR Function Block for writing the ACC & DEC registers of the ATV12 Modbus
// device
WRITE_VAR_ACC_DEC : WRITE_VAR;
// Buffer for the values of the ACC & DEC registers to write on the device (after
// conversion to WORD)
v_wWriteACC_DECValues : ARRAY [0..1] OF WORD := [0,0];
// "Busy" output of the ACC & DEC registers write operation
v_xWriteACC_DECBusy : BOOL := FALSE;
// READ_VAR Function Block for reading the new value of the ACC & DEC registers of
// the ATV12 Modbus device
READ_VAR_ACC_DEC : READ_VAR;
// Buffer for the values of the ACC & DEC registers
v_wRegisterACC_DEC : ARRAY[0..1] OF WORD := [0,0];
// "Busy" output of the ACC & DEC registers read operation
v_xReadACC_DECBusy : BOOL := FALSE;
// Value of the ACC & DEC registers read from the device (0.0 s to 999.9 s; unit:
// 0.1 s)
v_iReadACCValue : INT := 0;
v_iReadDECValue : INT := 0;
(**************************************)
(*** SP2 to SP8 Registers Variables ***)
(**************************************)
// MANUAL command for starting one SP2 to SP8 registers write & read operation
v_xCmdManualWrRdSP2_SP8 : BOOL := FALSE;
// Values of the SP2 to SP8 registers to write on the device (0.0 Hz to 400.0 Hz;
// unit: 0.1 Hz)
v_uiWriteSP2Value : UINT := 0;
v_uiWriteSP3Value : UINT := 0;
v_uiWriteSP4Value : UINT := 0;
v_uiWriteSP5Value : UINT := 0;
v_uiWriteSP6Value : UINT := 0;
v_uiWriteSP7Value : UINT := 0;
v_uiWriteSP8Value : UINT := 0;
// WRITE_READ_VAR Function Block for writing & reading the SP2 to SP8 registers of
// the ATV12 Modbus device
WRITE_READ_VAR_SP2_SP8 : WRITE_READ_VAR;
// Buffer for the values of the SP2 to SP8 registers to write on the device (after
// conversion to WORD)
v_wWriteSP2_SP8Values : ARRAY [0..6] OF WORD := [7(0)];
// Buffer for the values of the SP2 to SP8 registers read from the device
v_wReadSP2_SP8Values : ARRAY [0..6] OF WORD := [7(0)];
// "Busy" output of the SP2 to SP8 registers write & read operation
v_xWriteSP2_SP8Busy : BOOL := FALSE;
// Values of the SP2 to SP8 registers read from the device (0.0 Hz to 400.0 Hz; unit:
// 0.1 Hz)
v_uiReadSP2Value : UINT := 0;
v_uiReadSP3Value : UINT := 0;
v_uiReadSP4Value : UINT := 0;
v_uiReadSP5Value : UINT := 0;
v_uiReadSP6Value : UINT := 0;
v_uiReadSP7Value : UINT := 0;
v_uiReadSP8Value : UINT := 0;
END_VAR
52 EIO0000000913.01 04/2012
6. ST, LD, or CFC Program
Step Action
3 CFC program: In the lower part of the CFC editor, implement the following program:
EIO0000000913.01 04/2012 53
6. ST, LD, or CFC Program
Step Action
54 EIO0000000913.01 04/2012
6. ST, LD, or CFC Program
Step Action
EIO0000000913.01 04/2012 55
6. ST, LD, or CFC Program
Step Action
56 EIO0000000913.01 04/2012
7. Configuration of the ATV12 Modbus Slave
The instructions given herein include the steps for resetting your Altivar variable
speed drive to its factory settings.
DANGER
UNINTENDED EQUIPMENT OPERATION
Before resetting your Altivar variable speed drive to its factory settings, check that
the modification of its current configuration is compatible with the wiring diagram
used.
Failure to follow these instructions will result in death or serious injury.
NOTE: Since this example is for learning purposes only, it is strongly recommended
to install and operate the Altivar drive without wiring it to any motor. This is
particularly true if you inhibit its motor output phase loss detection via the Output
Phase Loss (OPL) parameter.
DANGER
UNINTENDED EQUIPMENT OPERATION
Before installing or operating an Altivar 12 variable speed drive and/or a motor,
read and understand the Altivar 12 Variable speed drives for asynchronous
motors User manual.
Failure to follow these instructions will result in death or serious injury.
Step Action
1 Switch on the Altivar 12 variable speed drive.
2 Reset the Altivar 12 to its factory setting:
Press the ENT key.
Enter the Configuration Mode ConF menu (HMI display: COnF)
Edit the Factory/ recall customer parameter set (FCS) parameter
(HMI display: FCS)
Select the InI value for resetting the Altivar 12 drive to its factory setting
(HMI display: InI)
Press the ENT key during 2 seconds to activate the factory setting.
Press the ESC key to exit the Configuration Mode ConF menu.
Press the ESC key.
EIO0000000913.01 04/2012 57
7. Configuration of the ATV12 Modbus Slave
Step Action
3 Optional step
This step shows you how to configure the control mode of the Altivar 12 so the variable
speed drive can be controlled by a Modbus Master. This step is not necessary in the
case of this example but could prove useful if you want your controller to control this
drive:
Press the ENT key.
Enter the Configuration Mode ConF menu (HMI display: COnF)
58 EIO0000000913.01 04/2012
7. Configuration of the ATV12 Modbus Slave
Step Action
Edit the Modbus format (tFO) parameter (HMI display: tFO)
Select the 8N1 value to configure the Altivar drive to communicate on the Modbus
network with the following settings: 8 data bits, no parity, and 1 stop bit
(HMI display: 8n1)
NOTE: This value corresponds to the Parity, Data bits, and Stop bits parameters
of the controller’s Modbus_Manager device in the SoMachine project (see
page 28).
Press the ENT key.
Edit the Modbus time out (ttO) parameter (HMI display: ttO)
Select the 30.0 value to set a Modbus timeout of 30 seconds on the Altivar drive
(HMI display: 30.0)
NOTE: With this configuration, the Altivar 12 drive detects a Modbus communication
fault (SLF1) if it does not receive any Modbus request at its address within a
30 second limit.
This Modbus timeout is only started when the Altivar 12 drive receives a Modbus
write request (e.g. Write Single Register). Modbus read requests (e.g. Read Holding
Registers) do not start this timeout, but once it has been started, the configured
30 second timeout is restarted each time the Altivar 12 drive receives a read and/or
write Modbus request at its address.
Press the ENT key.
Press the ESC key to exit the Communication menu (COM-).
Press the ESC key to exit the Complete menu (FULL).
Press the ESC key to exit the Configuration Mode ConF menu.
Press the ESC key.
EIO0000000913.01 04/2012 59
7. Configuration of the ATV12 Modbus Slave
Step Action
5 Check the settings of the Modbus fault management on the Altivar 12:
Press the ENT key.
Enter the Configuration Mode ConF menu (HMI display: COnF)
Enter the Fault detection management menu (FLt-) (HMI display: FLt-)
Edit the Modbus fault management (SLL) parameter (HMI display: SLL)
If the HMI display shows YES:
Press the ESC key.
If the HMI display does not show YES:
Select the Freewheel stop (YES) value to configure the Altivar 12 drive to report
a fault with the freewheel stop if it detects a Modbus communication fault (SLF1)
(HMI display: YES)
Press the ENT key.
Press the ESC key to exit the Fault detection management menu (FLt-).
Press the ESC key to exit the Complete menu (FULL).
Press the ESC key to exit the Configuration Mode ConF menu.
Press the ESC key.
6 Inhibit the motor output phase loss detection of the Altivar 12:
Press the ENT key.
Enter the Configuration Mode ConF menu (HMI display: COnF)
Enter the Fault detection management menu (FLt-) (HMI display: FLt-)
Edit the Output Phase loss (OPL) parameter (HMI display: OPL)
Select the NO value to deactivate the motor output phase loss fault detection
(HMI display: nO)
Press the ENT key.
Press the ESC key to exit the Fault detection management menu (FLt-).
Press the ESC key to exit the Complete menu (FULL).
Press the ESC key to exit the Configuration Mode ConF menu.
Press the ESC key.
60 EIO0000000913.01 04/2012
7. Configuration of the ATV12 Modbus Slave
Step Action
7 Optional step
If you intend to use a motor with your Altivar 12 variable speed drive, you should update
the values of the various parameters of its Motor control menu (drC-) with the values
given on the motor rating plate.
The path of this menu, on the HMI display, is: Configuration Mode (ConF) ► Complete
menu (FULL) ► Motor control menu (drC-)
Please refer to the Altivar 12 Variable speed drives for asynchronous motors User
manual for a description of these parameters and their possible values.
EIO0000000913.01 04/2012 61
8. Running the Example
Step Action
1 In the Devices tree view:
Expand the contents of your controller.
Double-click on the MAST task of the Task Configuration item.
Click on the Add POU command.
62 EIO0000000913.01 04/2012
8. Running the Example
Step Action
3 Click OK.
This adds the selected POU to the list of programs run by the MAST task of the
controller.
EIO0000000913.01 04/2012 63
8. Running the Example
64 EIO0000000913.01 04/2012
8. Running the Example
Step Action
4 Select this controller’s node and click on the Set active path button.
EIO0000000913.01 04/2012 65
8. Running the Example
Step Action
6 Click on the Login button of the toolbar to establish a connection from SoMachine to
the controller.
7a If you download the current project to the controller for the first time and if there is no
project on the controller, the following window is displayed:
66 EIO0000000913.01 04/2012
8. Running the Example
EIO0000000913.01 04/2012 67
8. Running the Example
Step Action
3 Periodic read request of one parameter (ETA) of the ATV12 drive using the
READ_VAR function block:
Name of the READ_VAR Function Block instance: READ_VAR_ETA
A BLINK_ETA instance of the BLINK Function Block is used to periodically trigger this
read request (once per second).
This BLINK_ETA instance triggers the execution of the READ_VAR_ETA instance. The
outputs of this READ_VAR_ETA instance are then used to report the Modbus connection
state between the controller and the Altivar 12 drive:
The v_xPresenceAtv12 variable is set to TRUE and the
v_xCommErrorAtv12 variable is reset to FALSE if the Modbus cable is
connected between the controller and the Altivar 12 drive.
The v_xPresenceAtv12 variable is reset to FALSE if the Modbus cable is
disconnected.
The v_xCommErrorAtv12 variable is set to TRUE if a communication error
occurs (timeout excluded).
68 EIO0000000913.01 04/2012
8. Running the Example
Step Action
Check the value of the v_iReadLFRValue variable: if this value is equal to the
v_iWriteLFRValue variable (positive or negative value), then the write
operation is successful.
To test the Modbus timeout of the Altivar 12 drive, proceed as follows:
Disconnect the Altivar 12 drive from the Modbus network by unplugging its
Modbus RS485 cordset (ref. VW3 A8 306 R••).
Wait at least 30 seconds.
Check that the Altivar 12 drive reports a SLF1 fault (HMI display: SLF1)
because the duration of the disconnection is greater than the duration configured
for its Modbus time out (ttO) parameter (see page 59) and because a Modbus
write request has been received by the Altivar 12 drive.
Plug back the Modbus RS485 cordset to the Altivar 12 drive.
Optional step: switch off, then switch on, the Altivar 12 drive to reset this fault.
5 Aperiodic write request of two parameters (ACC and DEC) of the ATV12 drive using
the WRITE_VAR function block:
Name of the WRITE_VAR Function Block instance: WRITE_VAR_ACC_DEC
To test this WRITE_VAR_ACC_DEC instance, proceed as follows:
Change the value of the v_iWriteACCValue and v_iWriteDECValue
variables: their unit is 0.1 s and they range from 0.1 s to 999.9 s (value = 1 to
9,999).
Set the v_xCmdManualWriteACC_DEC variable to TRUE.
This triggers the execution of the WRITE_VAR_ACC_DEC instance, followed by
the execution of a READ_VAR_ACC_DEC instance of the READ_VAR Function
Block. These Function Block instances update the values of the ACC and DEC
parameters on the Altivar 12 drive and read their updated values.
The v_xCmdManualWriteACC_DEC variable is automatically reset to FALSE by
the program after being used by the WRITE_VAR_ACC_DEC and
READ_VAR_ACC_DEC Function Block instances.
Check the values of the v_iReadACCValue and v_iReadDECCValue
variables: if their values are equal to the v_iWriteACCValue and
v_iWriteDECValue variables, then the write operation is successful.
EIO0000000913.01 04/2012 69
8. Running the Example
Step Action
6 Aperiodic read/write request of seven parameters (SP2 to SP8) of the ATV12 drive
using the WRITE_READ_VAR function block:
Name of the WRITE_READ_VAR Function Block: WRITE_READ_VAR_SP2_SP8
To test this WRITE_READ_VAR_SP2_SP8 instance, proceed as follows:
Change the values of the seven v_uiWriteSP2Value to
v_uiWriteSP8Value variables: their unit is 0.1 Hz and they range from 0.0 Hz
to 400.0 Hz (value = 0 to 4,000).
Set the v_xCmdManualWrRdSP2_SP8 variable to TRUE.
This triggers the execution of the WRITE_READ_VAR_SP2_SP8 instance. This
Function Block instance updates the values of the SP2 to SP8 parameters on the
Altivar 12 drive and reads their updated values.
NOTE: Both write and read operations are performed in a single Modbus
exchange.
The v_xCmdManualWrRdSP2_SP8 variable is automatically reset to FALSE by
the program after being used by the WRITE_READ_VAR_SP2_SP8 Function
Block instance.
Check the values of the v_uiReadSP2Value to v_uiWriteSP8Value
variables: if their values are equal to the v_uiWriteSP2Value to
v_uiWriteSP8Value variables, then the read/write operation is successful.
70 EIO0000000913.01 04/2012