0% found this document useful (0 votes)
500 views70 pages

Somachine: Modbus Rtu Communications - Read/Write Variables Modbus - RW - Var - Project Example Guide

Uploaded by

Malik May
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
500 views70 pages

Somachine: Modbus Rtu Communications - Read/Write Variables Modbus - RW - Var - Project Example Guide

Uploaded by

Malik May
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

SoMachine

Modbus RTU Communications - Read/Write


Variables
Modbus_RW_Var.project
Example Guide Basic
04/2012 Intermediate
Expert
EIO0000000913.01

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.

No part of this document may be reproduced in any form or by any means,


electronic or mechanical, including photocopying, without express written
permission of Schneider Electric.

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.

Failure to observe this information can result in injury or equipment damage.


© 2012 Schneider Electric. All rights reserved.

2 EIO0000000913.01 04/2012
Table of Contents

SAFETY INFORMATION ····································································································5

ABOUT THE BOOK ············································································································7

1. DESCRIPTION·············································································································13
1.1. Presentation ······························································································································· 13

1.2. Main Features ····························································································································· 15

1.3. Functional Analysis of the Example ························································································ 16

1.4. Functions Used in this Example······························································································· 18

1.5. Hardware Installation················································································································· 20

2. DESCRIPTION OF THE EXAMPLE CONTENT ··························································22

3. CREATION OF THE PROJECT···················································································23

4. SERIAL LINE MODBUS MANAGER···········································································26

5. LIBRARY MANAGER ··································································································30

6. ST, LD, OR CFC PROGRAM·······················································································31


6.1. ST Program································································································································· 32

6.2. LD Program································································································································· 41

6.3. CFC Program ······························································································································ 50

7. CONFIGURATION OF THE ATV12 MODBUS SLAVE ···············································57

8. RUNNING THE EXAMPLE ··························································································62


8.1. MAST Task Configuration ········································································································· 62

8.2. Downloading the Example to the Controller ··········································································· 64

8.3. Running the Example on the Controller ·················································································· 67

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.

This is the safety alert symbol. It is used to alert you to potential


personal injury hazards. Obey all safety messages that follow this
symbol to avoid possible injury or death.

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

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

Title of Documentation Reference Number


M238 ExecLoader User Guide EIO0000000374 (ENG);
EIO0000000737 (FRE);
EIO0000000738 (GER);
EIO0000000739 (SPA);
EIO0000000740 (ITA);
EIO0000000741 (CHS)
Modicon M258 Logic Controller Hardware Guide EIO0000000432 (ENG);
EIO0000000433 (FRE);
EIO0000000434 (GER);
EIO0000000435 (SPA);
EIO0000000436 (ITA);
EIO0000000437 (CHS)
Modicon LMC058 Motion Controller Hardware EIO0000000438 (ENG);
Guide EIO0000000439 (FRE);
EIO0000000440 (GER);
EIO0000000441 (SPA);
EIO0000000442 (ITA);
EIO0000000443 (CHS)
SoMachine Modbus and ASCII Read/Write EIO0000000361 (ENG);
Functions PLCCommunication Library Guide EIO0000000742 (FRE);
EIO0000000743 (GER);
EIO0000000744 (SPA);
EIO0000000745 (ITA);
EIO0000000746 (CHS)
Modicon M238 Logic Controller Programming EIO0000000384 (ENG);
Guide EIO0000000385 (FRE);
EIO0000000386 (GER);
EIO0000000387 (ITA);
EIO0000000388 (SPA);
EIO0000000389 (CHS)
Modicon M258 Logic Controller Programming EIO0000000402 (ENG);
Guide EIO0000000403 (FRE);
EIO0000000404 (GER);
EIO0000000405 (SPA);
EIO0000000406 (ITA);
EIO0000000407 (CHS)
Modicon LMC058 Motion Controller Programming EIO0000000408 (ENG);
Guide EIO0000000409 (FRE);
EIO0000000410 (GER);
EIO0000000411 (ITA);
EIO0000000412 (SPA);
EIO0000000413 (CHS)
Altivar 12 Variable speed drives for asynchronous BBV28581 (ENG);
motors User manual BBV28580 (FRE)
Altivar 12 Variable speed drives for asynchronous BBV28590 (ENG)
motors Modbus Communication Manual
ATV12 Communication Parameters BBV51917 (ENG)

8 EIO0000000913.01 04/2012
About the Book

Product Related Information


This document and its related SoMachine project file focus on specific Functions
and Function Blocks of the Schneider Electric libraries provided with SoMachine,
and on specific features available in SoMachine if these features are related to
these libraries. They are intended to help you with developing, testing,
commissioning, and integrating applicative software of your own design on control
systems.
It is intended for new SoMachine users who already have some degree of expertise
in the design and programming of control systems.

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

Before You Begin


The products specified in this document have been tested under actual service
conditions. Of course, your specific application requirements may be different from
those assumed for this and any related examples described herein. In that case,
you will have to adapt the information provided in this and other related documents
to your particular needs. To do so, you will need to consult the specific product
documentation of the hardware and/or software components that you may add or
substitute for any examples specified in this documentation. Pay particular attention
and conform to any safety information, different electrical requirements and
normative standards that would apply to your adaptation.

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.

Start-up and Test


Before using electrical control and automation equipment after design and
installation, the application and associated functional safety system must be
subjected to a start-up test by qualified personnel to verify correct operation of the
equipment. It is important that arrangements for such testing be made and that
enough time is allowed to perform complete and satisfactory testing.

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

Operation and Adjustments


Regardless of the care exercised in the design and manufacture of equipment or in
the selection and ratings of components, there are hazards that can be encountered
if such equipment is improperly installed and operated.
In some applications, such as packaging machinery, additional operator protection
such as point-of-operation guarding must be provided. This is necessary if the
hands and other parts of the body are free to enter the pinch points or other
hazardous areas where serious injury can occur. Software products alone cannot
protect an operator from injury. For this reason, the software cannot be substituted
for or take the place of point-of-operation protection.

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.

Failure to follow these instructions can result in death, serious injury, or


equipment damage.

Ensure that appropriate safeties and mechanical/electrical interlocks related to


point-of-operation protection have been installed and are operational before placing
the equipment into service. All interlocks and safeties related to point-of-operation
protection must be coordinated with the related automation equipment and software
programming.
NOTE: Coordination of safeties and mechanical/electrical interlocks for point-of-
operation protection is outside the scope of the examples and implementations
suggested herein.
It is sometimes possible to adjust the equipment incorrectly and this may produce
unsatisfactory or unsafe operation. Always use the manufacturer instructions as a
guide to functional adjustments. Personnel who have access to these adjustments
must be familiar with the equipment manufacturer instructions and the machinery
used with the electrical equipment.
Only those operational adjustments actually required by the machine operator
should be accessible to the operator. Access to other controls should be restricted
to help prevent unauthorized changes in operating characteristics.

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.

Related SoMachine project: Modbus_RW_Var.project

Supported SoMachine Languages:  CFC  IL


 ST  FBD
 LD  SFC
Key features: Modbus RTU communications for reading and writing data on a
Modbus slave
Requirements: To use this example, the user must have:
 installed SoMachine V3.1 on a PC;
 run at least one Basic SoMachine example.

PC with
SoMachine

Download
& Monitoring

Serial
Transmissions
Modbus RTU
protocol

LMC058 motion controller ATV12 variable


speed drive

NOTE: Because it is required to run the communication functions used in this


example’s programs on the controller, do not run this example in
SIMULATION mode.

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

1.2. Main Features


The main features of this example include:
 Configuration of a Modbus RTU serial connection using SoMachine.
 Addressing a Modbus slave using the PLCCommunication library.
 Periodic read request of one parameter of the ATV12 Modbus slave (ETA: status
word) using the Modbus function #3 (Read Holding Registers).
 Aperiodic write request of one parameter of the ATV12 Modbus slave (LFR:
frequency setpoint) using the Modbus function #6 (Write Single Register),
followed by a read request of the very same parameter using the Modbus
function #3 (Read Holding Registers).
 Aperiodic write request of two parameters of the ATV12 Modbus slave (ACC &
DEC: acceleration & deceleration) using the Modbus function #16 (Write Multiple
Registers), followed by a read request of the very same parameters using the
Modbus function #3 (Read Holding Registers).
 Aperiodic read/write request of seven parameters of the ATV12 Modbus slave
(SP2 to SP8: preset speeds 2 to 8) using the Modbus function #23 (Read/Write
Multiple Registers).
 Use example of the data read and written by the controller on the ATV12 variable
speed drive.

EIO0000000913.01 04/2012 15
1. Description

1.3. Functional Analysis of the Example


The program described in this example, whatever its programming language,
performs the following treatments:

Start

1-second delay

Yes 1-second periodic Read of the


Formats the ATV12 Result
ETA parameter (@3201)
Modbus address = OK?
on the ATV12 drive
No

Result No
= OK?
End
Yes

ATV12 present: Yes ATV12 present: No


AND Comm. error: No OR Comm. error: Yes

LFR write No ACC & DEC write No SP2 to SP8 No


command? command? R/W command?

Yes Yes Yes

Converts Converts Converts


LFR ACC & DEC SP2 to SP8
(INT to WORD) (INT to WORD) (UINT to WORD)

Write of the ACC & Write + Read of the SP2


Write of the LFR
DEC parameters to SP8 parameters
parameter (@8502)
(@9001 & @9002) (@11410 to @11416) (1)
on the ATV12 drive
on the ATV12 drive on the ATV12 drive

Resets
Sets LFR Sets ACC & DEC
SP2 to SP8
read command read command
R/W command

Read of the ACC &


Read of the LFR Converts
DEC parameters
parameter (@8502) SP2 to SP8
(@9001 & @9002) (WORD to UINT)
on the ATV12 drive
on the ATV12 drive

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

1.4. Functions Used in this Example


The Functions (and Function Blocks) used in this example are listed below, grouped
by library:
 PLCCommunication library (Schneider Electric)
Function Description Location in the Input Assistant
ADDM Convert a string into an address
READ_VAR Reads data from a Modbus device
Function Blocks  { } SEN
SINGLE_WRITE Write a single internal register to a Modbus device
WRITE_READ_VAR Read and write internal registers on a Modbus device
WRITE_VAR Write data to a Modbus device

 Standard library (System)


Function Description Location in the Input Assistant
TON Timer function block: implement a turn-on delay Function Blocks  { } Standard  Timer

 Util library (System)


Function Description Location in the Input Assistant
BLINK Generates a pulsating signal Function Blocks  { } Util  Signals

18 EIO0000000913.01 04/2012
1. Description

Please refer to the SoMachine online help.


NOTE: In the remaining sections of this document, the former sentence instructs
you to refer to the online help of SoMachine which is accessible through the upper-
right help button.
Please refer to the SoMachine online help for detailed information on these
Functions and Function Blocks: Function description, Graphical representation, I/O
Variables description, and more.

To install these libraries in your own project, please refer to Library Manager (see
page 30).

EIO0000000913.01 04/2012 19
1. Description

1.5. Hardware Installation


Required Devices

1
USB 3 5

2a Controller ATV12
or Pgr
2b Port MBS MODBUS / VP8S
(RJ45 connector)

N° Designation Reference Use or Description


1 SoMachine Software MSD CHNLMUA SoMachine Software, 1-station license, installed on a PC
SoMachine Solution MSD CHLLMUV30S0 SoMachine Solution Extension Software, 1-station license,
Extension Software installed on the same PC than SoMachine Software
(1)
2a Terminal port/USB TCS XCN AM UM3P From the mini B USB port on the LMC058, M238, or M258
port cordset controller base to the type A USB port on the PC terminal for
programming and updating firmware; length: 3 m (10 ft)
2b Programming cable BMX XCA USB H018 Same as TCS XCN AM UM3P, but with two ground
connections along the cable; length: 1.8 m (6 ft)
3 Modicon LMC058 LMC058 ••••••• Compact base motion controller
Motion controller (2)
Programming port name: Pgr Port
Modbus port name: MBS
or Modicon M238 TM238 ••••••••• Compact base logic controller with 24 I/O (removable battery to
Logic controller (2) be ordered separately: TSX PLP 01)
Programming port name: Prg. Port
Modbus port name: SL1
or Modicon M258 TM258 •••••••••• Compact base logic controller
Logic controller (2)
Programming port name: Pgr Port
Modbus port name: MBS
4 Modbus RS485 VW3 A8 306 R03, or From the Serial port marked MBS on the LMC058 or M258
cordset with 2 × VW3 A8 306 R10, or controller (or the SL1 port on the M238 controller) to the RJ45
RJ45 connectors VW3 A8 306 R30 connector of the ATV12 drive
Length 0.3 m (1 ft), 1.0 m (3.3 ft), or 3.0 m (10 ft), depending
on the reference of the cable
5 Altivar 12 drive ATV12•••••• Altivar 12 variable speed drive for asynchronous motor, used
here as a Modbus slave

(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

2. Description of the Example Content


In SoMachine, the configuration of the example is made with the following devices:
 1 Motion Controller: LMC058LF42S0
NOTE: This controller can be replaced with any LMC038 Motion
Controller, M238 Logic Controller, or M258 Logic Controller.
 1 Modbus Manager on the controller to configure it as the Master of the
Modbus RTU network
The program of the LMC058, M238, or M258 controller is made of the following
items:
 Library Manager: List of the libraries linked to the programs of this example.
 ST program: Contains the source code for implementing what is described
in Functional Analysis of the Example (see page 16). This is the default
program since it is called by the MAST task of the controller.
 LD program: Translation of the ST program into LD language. To run this
program on the controller, instead of the ST program, change the POU
called by the MAST task of the controller from PLC_PRG_ST to
PLC_PRG_LD.
 CFC program: Translation of the ST program into CFC language. To run
this program on the controller, instead of the ST program, change the POU
called by the MAST task of the controller from PLC_PRG_ST to
PLC_PRG_CFC.
 Task Configuration: The standard MAST task, cyclically called every 20ms.
 Serial Line: Configured as a Modbus_Manager.
Aside from configuring the ATV12 drive, as described in Configuration of the ATV12
Modbus Slave (see page 57), there is no other software operation to perform on this
device.

Example of the content visible in the Devices panel of the Program tab:

22 EIO0000000913.01 04/2012
3. Creation of the Project

3. Creation of the Project


The steps listed in the following table describe how to create the SoMachine project,
including the device(s) used in this example. No details are given here since it is
assumed that you already know the Basic commands of SoMachine.
Step Action
1 In the Create new machine part of the Home tab, select Start with empty project to
create a new SoMachine project.
Give this new project the following name: Modbus_RW_Var.
2 In the Configuration tab:
 Add an LMC058 Motion Controller.
In the following screen capture, a LMC058LF42S0 Motion Controller is selected
and added to the SoMachine 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:

4 Save your new project.

EIO0000000913.01 04/2012 25
4. Serial Line Modbus Manager

4. Serial Line Modbus Manager


The steps listed in the following table describe how to add and configure the
Modbus Manager of the LMC058 controller.
If you use a M238 or a M258 controller instead of a LMC058 controller, these steps
also tell you how to adapt them to your controller.
Step Action
1 LMC058 or M258 controller: Click on the SoMachine-Network_Manager Serial Line
port:

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).

2 LMC058 or M258 controller: Confirm the removal of the SoMachine-


Network_Manager by clicking the OK button:

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.

 Click on the Add and close button.


This will configure the Serial Line port of the LMC058 controller as a Modbus_Manager.
4 Hardware Configuration
To open the hardware configuration of your controller, double-click on its image:

5 LMC058 or M258 controller: In the left-hand panel, select:


 Communication menu
 Serial Line
 Physical Settings
M238 controller: In the left-hand panel, select:
 Communication menu
 Serial Line 1
 Physical Settings

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

7 LMC058 or M258 controller: In the left-hand panel, select:


 Communication menu
 Serial Line
 Protocol Settings
M238 controller: In the left-hand panel, select:
 Communication menu
 Serial Line 1
 Protocol Settings

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:

9 Click on the Back button to revert to the main Configuration tab.


A network object has automatically been connected to the Serial Line port of your
controller to depict the Modbus network:

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

6. ST, LD, or CFC Program


Each of the following three chapters describes how to create the program used in
the example. Choose the language of your program (ST, LD, or CFC) and refer to
the corresponding chapter:
• ST Program ........................................................................................... 32
• LD Program ........................................................................................... 41
• CFC Program ........................................................................................ 50
You only need to write your SoMachine program in one of these three languages.

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.

Upon creation of this POU, it is automatically opened by SoMachine.


2 ST variables: In the upper part of the ST editor, declare the following variables:

PROGRAM PLC_PRG_ST
VAR

(*********************)
(*** TON Variables ***)
(*********************)

// TON Function Block for delaying the start of this program


TON_START : TON;
// Delayed Rising Edge signal for starting the program
v_xStartProgram : BOOL := FALSE;

(**********************)
(*** 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;

// Result of the Address conversion: OK if "Done" without any "Error"


v_xAddressIsOK : 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;

// Command to read the ETA register


v_xReadETARegister : 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;

// Presence (TRUE) or absence (FALSE) of the ATV12 Modbus device


v_xPresenceAtv12 : BOOL := FALSE;
// Communication error with the ATV12 Modbus device (Timeout excluded)
v_xCommErrorAtv12 : BOOL := FALSE;

(******************************)
(*** LFR Register Variables ***)
(******************************)

// MANUAL command for starting one LFR register write operation


v_xCmdManualWriteLFR : BOOL := FALSE;
// Automatic command for reading the new value of the LFR register
v_xCmdAutoReadLFR : BOOL := FALSE;

// Command to write the LFR register


v_xWriteLFRRegister : BOOL := FALSE;

// 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;

// Command to read the LFR register


v_xReadLFRRegister : 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;

// Command to read the ACC & DEC registers


v_xReadACC_DECRegisters : 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;

// Command to write & read the SP2 to SP8 registers


v_xWrRdSP2_SP8Registers : 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 *)
(*************************************************************)

TON_START.IN := TRUE; // IN - Enabled (TRUE)


TON_START.PT := T#1S; // IN - Duration of the TON timer (1 second)
TON_START(); // Function Block call
v_xStartProgram := TON_START.Q; // OUT - Resulting delay before running the rest of
// this program
(*TON_START.ET*) // OUT - This output is not used in 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

(* Result of the Address conversion: OK if 'Done' without any 'Error' *)


v_xAddressIsOK := v_xAddressDone AND NOT v_xAddressError;

(******************************************************************)
(*** 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

(* Command to read the ETA register: IF Address is OK AND 1-second clock *)


v_xReadETARegister := v_xAddressIsOK AND v_xClockReadETARegister;

(* 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.

Upon creation of this POU, it is automatically opened by SoMachine.


3 LD variables: In the upper part of the LD editor, declare the following variables:

PROGRAM PLC_PRG_LD
VAR
(*********************)
(*** TON Variables ***)
(*********************)

// TON Function Block for delaying the start of this program


TON_START : TON;
// Delayed Rising Edge signal for starting the program
v_xStartProgram : BOOL := FALSE;

(**********************)
(*** 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;

// Result of the Address conversion: OK if "Done" without any "Error"


v_xAddressIsOK : BOOL := FALSE;

(******************************)
(*** ETA Register Variables ***)
(******************************)

// 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;

// Command to read the ETA register


v_xReadETARegister : BOOL := FALSE;

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;

// Result of the ETA register read operation: SUCCESS


v_xReadETASuccess : BOOL := FALSE;
// Result of the ETA register read operation: FAILURE
v_xReadETAFailure : BOOL := FALSE;

// Presence (TRUE) or absence (FALSE) of the ATV12 Modbus device


v_xPresenceAtv12 : BOOL := FALSE;
// Communication error with the ATV12 Modbus device (Timeout excluded)
v_xCommErrorAtv12 : BOOL := FALSE;

(******************************)
(*** LFR Register Variables ***)
(******************************)

// MANUAL command for starting one LFR register write operation


v_xCmdManualWriteLFR : BOOL := FALSE;
// Automatic command for reading the new value of the LFR register
v_xCmdAutoReadLFR : BOOL := FALSE;

// Command to write the LFR register


v_xWriteLFRRegister : BOOL := FALSE;

// 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;

// Command to read the LFR register


v_xReadLFRRegister : 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;

// 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;

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;

// Command to read the ACC & DEC registers


v_xReadACC_DECRegisters : 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;

// Command to write & read the SP2 to SP8 registers


v_xWrRdSP2_SP8Registers : 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

6.3. CFC Program

Step Action
1 Creation of the POU: Create a new POU in CFC language, called PLC_PRG_CFC.

Upon creation of this POU, it is automatically opened by SoMachine.


2 CFC variables: In the upper part of the CFC editor, declare the following variables:

PROGRAM PLC_PRG_CFC
VAR
(*********************)
(*** TON Variables ***)
(*********************)

// TON Function Block for delaying the start of this program


TON_START : TON;
// Delayed Rising Edge signal for starting the program
v_xStartProgram : BOOL := FALSE;

(**********************)
(*** 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;

// Result of the Address conversion: OK if "Done" without any "Error"


v_xAddressIsOK : BOOL := FALSE;

(******************************)
(*** ETA Register Variables ***)
(******************************)

// BLINK Function Block for periodic reading of the ETA register


BLINK_ETA : BLINK;

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;

// Command to read the ETA register


v_xReadETARegister : 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;

// Result of the ETA register read operation: SUCCESS


v_xReadETASuccess : BOOL := FALSE;
// Result of the ETA register read operation: FAILURE
v_xReadETAFailure : BOOL := FALSE;

// Presence (TRUE) or absence (FALSE) of the ATV12 Modbus device


v_xPresenceAtv12 : BOOL := FALSE;
// Communication error with the ATV12 Modbus device (Timeout excluded)
v_xCommErrorAtv12 : BOOL := FALSE;

(******************************)
(*** LFR Register Variables ***)
(******************************)

// MANUAL command for starting one LFR register write operation


v_xCmdManualWriteLFR : BOOL := FALSE;
// Automatic command for reading the new value of the LFR register
v_xCmdAutoReadLFR : BOOL := FALSE;

// Command to write the LFR register


v_xWriteLFRRegister : BOOL := FALSE;

// 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;

// Command to read the LFR register


v_xReadLFRRegister : 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;

// Command to read the ACC & DEC registers


v_xReadACC_DECRegisters : 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;

// Command to write & read the SP2 to SP8 registers


v_xWrRdSP2_SP8Registers : 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

4 Order By Data Flow


When you have finished implementing this CFC program, perform the following steps to
correctly set the execution order of its blocks:
 Right-click on an empty area of the central worksheet.
 In the Execution Order part of the contextual menu, execute the Order By Data
Flow command.

56 EIO0000000913.01 04/2012
7. Configuration of the ATV12 Modbus Slave

7. Configuration of the ATV12 Modbus Slave


The steps listed in the following table describe how to configure the parameters and
the Modbus communications of the Altivar 12 (ATV12) variable speed drive used in
this example. Please refer to the Altivar 12 Variable speed drives for asynchronous
motors User manual and to the Altivar 12 Variable speed drives for asynchronous
motors Modbus Communication Manual for further information on how to configure
an ATV12 variable speed drive using the HMI of its front panel.

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)

 Enter the Complete menu (FULL) (HMI display: FULL)

 Enter the Control menu (CtL-) (HMI display: CtL-)

 Edit the Reference channel 1 (Fr1) parameter (HMI display: Fr1)


 Select the Modbus (Mdb) value to configure the drive to connect its Reference
channel 1 to the integrated Modbus port (HMI display: Adb)
 Press the ENT key.
 Press the ESC key to exit the Control menu (CtL-).
 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.
4 Set the Modbus configuration and address of the Altivar 12:
 Press the ENT key.
 Enter the Configuration Mode ConF menu (HMI display: COnF)

 Enter the Complete menu (FULL) (HMI display: FULL)

 Enter the Communication menu (COM-) (HMI display: COA-)

 Edit the Modbus address (Add) parameter (HMI display: Add)


 Select the 2 value to set the Altivar drive to the Modbus address 2
(HMI display: 2)
NOTE: This value must be unique for the devices of the same Modbus network. It
corresponds to the value used by the ADDM_MODBUS_ATV12 Function Block
instance of this program (see page 67) for addressing the Altivar 12 drive.
 Press the ENT key.
 Edit the Modbus baud rate (tbr) parameter (HMI display: tbr)
 If the HMI display shows 19 2:
 Press the ESC key.
 If the HMI display does not show 19 2:
 Select the 19.2 kbps (19.2) value to configure the Altivar drive to communicate
on the Modbus network at 19200 Bauds (HMI display: 19 2)
NOTE: This value corresponds to the Baud rate parameter of the controller’s
Modbus_Manager device in the SoMachine project (see page 28).
 Press the ENT key.

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 Complete menu (FULL) (HMI display: FULL)

 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 Complete menu (FULL) (HMI display: FULL)

 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

8. Running the Example


8.1. MAST Task Configuration

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.

2 In the Input Assistant window that is displayed:


 Select your program.
In the following dialog, the ST Program (see page 32), PLC_PRG_ST, is selected:

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

8.2. Downloading the Example to the Controller


The steps listed in the following table describe how to download the example to the
controller. If needed, please refer to the SoMachine online help for further
information on these steps: search for Communication Settings.
Step Action
1 Connect the USB programming cable between your PC and your controller.
Please refer to Hardware Installation (see page 20), for the reference and usage of this
cable.
NOTE: This USB programming cable is compatible with any LMC058, M238, or M258
controller. Each of these controllers has a mini B USB port designed to program it using
SoMachine.
2 In the Devices tree view, double-click on your controller’s device to open its configuration
panel.
Example: Click on the LMC058_Controller (LMC058LF42S0) item in the case of a
LMC058 controller.
3 In the Communication Settings tab of this panel:
 Click on the Gateway-1 node.
 Click on the Scan network button.
If the controller is switched on and connected to your PC with the USB programming
cable, it will be detected by SoMachine as shown below:

In this example, the LMC058LF42S0 @0080F4400CBC controller has been detected.

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.

This will show SoMachine the way to reach your controller.


Option: Uncheck the  Secure online mode box to avoid validation messages during
future online modifications.
NOTE: The firmware version of your controller is displayed as the Target Version.
5 The following window will display and prompts you to confirm your choice:
 Read the hazard message;
 Simultaneously press the <Alt> and <F> keys to validate your choice and close
this window;
 Or, click on the Cancel button if you can not comply with the statements in the
hazard message.

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:

Click on Yes to download the Application software to the controller.


7b If you download the current project to the controller for the first time and if there is
another project on the controller, the following window is displayed:

Click on Yes to download the Application software to the controller.


7c If you already have downloaded the current project to the controller, the following window
displays if new modifications were made to this project:

 Select the  Login with download choice.


 Click on OK to download the Application software to the controller.
7d If you already have downloaded the current project to the controller, the connection is
immediate if no modifications were made to this project.
8 Wait for the completion of the download operation.
Once it is finished, the status bar of SoMachine displays the state of the controller:
STOP
9 Click on the Start button of the toolbar to run the Application software on the
controller.
The state of the controller switches from STOP to RUN

66 EIO0000000913.01 04/2012
8. Running the Example

8.3. Running the Example on the Controller


The steps listed in the following table describe how to use the example, once it has
been downloaded to the controller.
Step Action
1 In the Devices panel, double-click on your PLC_PRG program to open it (e.g.
PLC_PRG_ST if you previously selected this program as the program run by the MAST
task of your controller).
This command opens your program in the central panel of SoMachine; the online values
of the variables used by this program are also displayed, as shown below:

2 Addressing of the Modbus slave using the ADDM function block :


Name of the ADDM Function Block instance: ADDM_MODBUS_ATV12
The ADDM_MODBUS_ATV12 instance is used to format the address of the Altivar 12 drive
(<slave address> = address = 2) on the Modbus serial line (<communication port
number> = serial line #1 = 1). To do so, this address is set into the Addr input of this
instance, with the following format (in the case of Modbus communications):
'<communication port number>.<slave address>'.
Here, the Addr input is set to '1.2'.
NOTE: Do not forget to configure this address on the Altivar 12 variable speed drive, as
described in Configuration of the ATV12 Modbus Slave (see page 58).

To test this Function Block instance, proceed as follows:


 Check that this ADDM_MODBUS_ATV12 instance works correctly:
 Its Done output (or the v_xAddressDone variable) must be equal to TRUE.
 Its Error output (or the v_xAddressError variable) must be equal to
FALSE.
 Its AddrTable structured output (or the v_addressModbusAtv12 variable)
contains the formatted address that will be used in the rest of this program to
address the Altivar 12 drive on the Modbus network.

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).

To test this Function Block instance, proceed as follows:


 Check that the v_xPresenceAtv12 variable is equal to TRUE and that the
v_xCommErrorAtv12 variable is equal to FALSE.
 Disconnect the Altivar 12 drive from the Modbus network by unplugging its
Modbus RS485 cordset (ref. VW3 A8 306 R••).
 Check that the v_xPresenceAtv12 variable is equal to FALSE and that the
v_xCommErrorAtv12 variable is equal to FALSE.
 Plug back the Modbus RS485 cordset to the Altivar 12 drive.
 Check that the v_xPresenceAtv12 variable is equal to TRUE and that the
v_xCommErrorAtv12 variable is equal to FALSE.
NOTE: For now, the Altivar 12 drive does not report any SLF1 fault, even if the duration
of the disconnection is greater than the duration configured for its Modbus time out (ttO)
parameter (see page 59).
4 Aperiodic write request of one parameter (LFR) of the ATV12 drive using the
SINGLE_WRITE function block:
Name of the SINGLE_WRITE Function Block instance: SINGLE_WRITE_LFR
To test this SINGLE_WRITE_LFR instance, proceed as follows:
 Change the value of the v_iWriteLFRValue variable: its unit is 0.1 Hz and it
ranges from –3,276.7 Hz to +3,276.7 Hz (value = –32,767 to +32,767).
 Set the v_xCmdManualWriteLFR variable to TRUE.
This triggers the execution of the SINGLE_WRITE_LFR instance, followed by the
execution of a READ_VAR_LFR instance of the READ_VAR Function Block.
These Function Block instances update the value of the LFR parameter on the
Altivar 12 drive and read its updated value.
The v_xCmdManualWriteLFR variable is automatically reset to FALSE by the
program after being used by the SINGLE_WRITE_LFR and READ_VAR_LFR
Function Block instances.

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

You might also like