Sei sulla pagina 1di 40

Beckhoff TwinCAT

The Windows Control and Automation Technology

NOTA DE APLICAO 03
Princpios bsicos da programao de PLC para
BC e IL230x-Cxxx com TwinCAT PLC

BRESIMAR (asaTek)
e-mail j.andril@bresimar.pt
B-NA03(v1.1)
Janeiro/2009

Bresimar - Sociedade de Equipamentos Elctricos, Lda.


Geral (Sede)
Quinta do Simo - EN109 - Esgueira
Apartado 3080
3801-101 Aveiro
PORTUGAL
Telf . +351 234 303 320
Telm . +351 939 992 222
Fax +351 234 303 328/9
e-mail bresimar@bresimar.pt

Using BC and IL230x-Cxxx as a Stand-Alone PLC

Table Of Contents
1.

2.

3.

4.

5.

6.

Introduction ....................................................................................................................3
1.1.
PLC Boxes (IL230x-Cxxx)................................................................................................... 3
1.2.
BC9000 and IL230x-C900................................................................................................... 3
1.3.
Firewall and Anti-Virus Programs ....................................................................................... 3
BC I/O System Configuration ....................................................................................................4
2.1.
Configuration for BC9000 and IL230x-Cxxx via Ethernet ................................................. 4
2.1.1.
Settings the IP Address ............................................................................................... 4
2.1.2.
Scan Ethernet network ................................................................................................ 4
2.1.3.
Compatible Terminal Types ....................................................................................... 7
2.1.4.
Download BC9000 Configuration via Ethernet ......................................................... 8
2.2.
Configuration for BC and IL230x-Cxxx via Serial Connection ........................................ 10
2.2.1.
Add I/O Terminals to BC .......................................................................................... 13
2.2.2.
Download Configuration via Serial Connection ....................................................... 15
2.3.
Saving TwinCAT System Manager Configuration File .................................................... 16
Creating the BC PLC Project .................................................................................................. 17
3.1.
Create PLC Project ............................................................................................................. 17
3.2.
BC Input and Output Process Images ................................................................................. 19
3.3.
Writing the BC PLC Program ............................................................................................ 21
3.4.
Compiling the BC PLC Program ....................................................................................... 22
Downloading BC PLC Project................................................................................................. 24
4.1.
Select Target BC9000 for Ethernet Connection ................................................................ 24
4.2.
Configure COM Port for Serial Connection ...................................................................... 26
4.3.
Download BC PLC Program ............................................................................................. 27
4.4.
Editing BC PLC Program................................................................................................... 30
4.5.
Create BC Boot Project ..................................................................................................... 31
Checking BC Input and Output Images ................................................................................ 32
5.1.
Export BC Input and Output Images ................................................................................. 32
5.2.
Import BC Input and Output Images ................................................................................. 33
BC Program Cycle Time ......................................................................................................... 35

Version Updated Changes


V1.2

22/11/2004

Notes for programming BC9000 via Ethernet added


Reference to IP67 PLC Boxes added

V1.3

8/12/2004

Example configuration using serial connection changed to BC3100


to distinguish from BC9000 via Ethernet

V1.4

14/6/2005

Warning to disable firewalls added


Changing non-PLC terminal to PLC terminals added

Changing terminal-type to a compatible type added

Updated: 15/06/2005

Page 2 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

1. Introduction
The BC series of bus controllers have a single PLC task that can be used to implement a
PLC program to interact with the I/O terminals connected to it. This allows the BC to be
used as a stand-alone PLC controller, and is configured using a serial connection

between the PC and the BC.


All screen captures have been taken using TwinCAT V2.9.0. Older versions of TwinCAT
may vary slightly from the screens shown in this document.

1.1. PLC Boxes (IL230x-Cxxx)


PLC Boxes are part of Beckhoffs IP67 range of I/O and are functionally identical to the
BC range of bus controllers. This document uses a BC controller to demonstrate the
different procedures, but all information applies equally to the IL230x-Cxxx range.
NOTE: the serial leads required for the BC and IL230x-Cxxx ranges are different.

1.2. BC9000 and IL230x-C900


BC9000 and IL230x-C900 have Ethernet fieldbus ports, and both can be programmed via

the Ethernet port for the serial connection port. As many modern lap-top computers
have built-in Ethernet ports, but no serial communication ports, the Ethernet connection

is a popular method of programming the BC9000 and IL230x-C900.


The procedures for programming these devices via Ethernet are different in some areas

from the serial connection. If a section heading does not indicate Ethernet or Serial
Connection, the section applies to both methods.

1.3. Firewall and Anti-Virus Programs


Firewalls and some anti-virus programs are known to interfere with TwinCAT traffic over
Ethernet, and can cause problems when using a PC to program a BC9000 or IL230x-C900

via Ethernet.
Wherever possible, firewalls should be disabled completely on a PC being used to
configure a remote TwinCAT device via Ethernet. If this cannot be done, a trusted
zone must be configured for the range of IP addresses in use on the TwinCAT network,
although this does not prevent some firewalls from interfering with TwinCAT traffic.
Norton Personal Firewall is known to cause problems in this respect.

Updated: 15/06/2005

Page 3 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

2. BC I/O System Configuration


I/O terminals in a BC can be attached to the BC PLC or sent directly to the fieldbus port.
In stand-alone mode, any terminals not attached to the BC PLC will not be accessible
within the PLC program. The procedure described in this section ensures that any
previous I/O configuration in the BC will be over-written with the new I/O configuration.

2.1. Configuration for BC9000 and IL230x-Cxxx via Ethernet


2.1.1. Settings the IP Address
All BC9000 and IL230x-Cxxx devices on the network must be assigned an IP address
before they can have their I/O configuration and PLC program downloaded. Refer to
Assigning IP Addresses to Beckhoff Ethernet Devices for further details.

2.1.2. Scan Ethernet network


The Ethernet network must be scanned to allow TwinCAT System Manager to find any
BC9000 and IL230x-Cxxx devices that are available on the network, and make them

available later as target devices for the PLC program. In addition, any terminals
connected to the device can be scanned to check the current I/O configuration.
To scan the Ethernet network:
1. Right click I/O Devices
2. Select Append Device

Updated: 15/06/2005

Page 4 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

3. Select Virtual Ethernet Interface


4. Click OK

5. Right click on the Ethernet device


6. Select Scan Boxes

Updated: 15/06/2005

Page 5 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

7. Select the Ethernet device(s) to be configured


8. Click OK

TwinCAT System Manager will add the selected devices to the Ethernet master, scan the

terminals connected to the devices and display the terminal configuration found.
TwinCAT System Manager

Updated: 15/06/2005

Page 6 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC


Any terminals that do NOT have PLC next to them are assigned to the process image of
the Ethernet port. To assign these terminals to the BC PLC process image:

1. Right click on the terminal to be deleted


2. Select Delete Terminal

3. Click OK to delete the terminal

2.1.3. Compatible Terminal Types


Several Beckhoff I/O terminals are functionally identical to other terminals, so TwinCAT

System Manager cannot always detect exactly what type of terminal has been found.
To correct the list of terminals fitted to a device:
1. Right click on the terminal that is to be changed
2. Select Change to Compatible Type
3. Select the actual terminal fitted.

Updated: 15/06/2005

Page 7 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

2.1.4. Download BC9000 Configuration via Ethernet


If any I/O terminals are not listed as PLC terminals, they are assigned to the Ethernet
port. To over-write the existing I/O configuration:

1. Click on the Activate Configuration icon (

2. Click Yes to generate the project mappings

3. Click OK to generate the project mappings

4. Click OK to acknowledge the Ethernet sync master warning

Updated: 15/06/2005

Page 8 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

5. Click OK to restart the system in run mode, and download the updated I/O
configuration to the BC9000

TwinCAT System Manager will indicate that the local system is now running, and
TwinCAT PLC will be able to access the BC9000 to download the PLC program.

Updated: 15/06/2005

Page 9 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

2.2. Configuration for BC and IL230x-Cxxx via Serial Connection


A fieldbus system has to be created to allow the I/O configuration to be created and
downloaded to the BC or IL230x-Cxxx. This ensures that any previous I/O configuration
will be over-written with the new configuration.
To specify the I/O for a stand-alone BC or IL230x-Cxxx:
1. Right click I/O Devices

2. Select Append Device

3. Select a master controller appropriate for the BC controller you are using. This
example will use a BC3100, so a PROFIBUS-DP master controller must be selected
4. Click OK

Updated: 15/06/2005

Page 10 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC


TwinCAT System Manager will list any PROFIBUS master devices found on the system.

5. Click Cancel

6. Right click on the fieldbus master controller


7. Select Append Box

Updated: 15/06/2005

Page 11 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

8. Select the required BC or IL230x-Cxxx fieldbus controller


9. Click OK

TwinCAT System Manager will show a master controller with a slave BC or IL230x-Cxxx
controller. The example system below shows a PROFIBUS-DP master controller with a
BC3100 connected.

Updated: 15/06/2005

Page 12 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

2.2.1. Add I/O Terminals to BC


To add terminals to the BC or IL230x-Cxxx controller:

1. Right click on the controller


2. Select Append Terminal

3. Select the required group of (BC PLC) terminals

Updated: 15/06/2005

Page 13 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

4. Select the terminal type required.


5. Specify the number of terminals required.
6. Click OK

TwinCAT System Manager will add the selected terminals to the controller. Steps 1 to 6

should be repeated until all required terminals have been added.

Updated: 15/06/2005

Page 14 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

2.2.2. Download Configuration via Serial Connection


When the I/O configuration has been created for the BC, it must be downloaded to the
BC or IL230x-Cxxx using the serial connection.
To download the configuration to the controller:
1. Right click on the BC or IL230x-Cxxx controller
2. Select Terminal Configuration COMx

3. Select COM Port


4. Specify the COM port that is connected to the BC or IL230x-Cxxx

Updated: 15/06/2005

Page 15 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC


TwinCAT System Manager will download the configuration to the controller. When
download is complete, the TwinCAT System Manager will ask to reset the device to

activate the new configuration.


5. Click Yes

2.3. Saving TwinCAT System Manager Configuration File


Even though the fieldbus network created in TwinCAT System Manager is a dummy
network, the TwinCAT System Manager configuration should be saved as part of the BC
or IL230x-Cxxx project files. If the configuration is lost or over-written in future, the

original configuration can be restored at a later date.

Updated: 15/06/2005

Page 16 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

3. Creating the BC PLC Project


3.1. Create PLC Project
To create a new PLC project for the BC or IL230x-Cxxx in TwinCAT PLC:

1. Select the New icon (

) in TwinCAT PLC

2. Select target device and the download method to be used:


BC via AMS or BCxx50 or BX via AMS for BC9000 via Ethernet
BC serial or BCxx50 or BX via serial for BC via serial connection
3. Click OK

Updated: 15/06/2005

Page 17 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

4. Select Program as the the type of Program Organisation Unit (POU)


5. Select the programming language for the POU. The following languages can be
used in TwinCAT PLC:
IL Instruction List

SFC Sequential Function Chart

LD Ladder

ST

FBD Function Block Diagram

CFC Continuous Function Chart

Structured Text

TwinCAT PLC will create a new blank PLC project for the BC controller.

Updated: 15/06/2005

Page 18 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

3.2. BC Input and Output Process Images


The input and output process images are fixed in a BC for a given configuration of

terminals. It is important to know how the input and output images are structured to
ensure that the PLC input and output images correspond to the correct inputs and

outputs.
NOTE: this note assumes that only compact analogue and digital inputs and
outputs were used in the I/O configuration using TwinCAT System Manager.
Working along the K-bus from the BC:

1. Analogue terminals are added to the process images starting at %IW0 and %QW0,
and are added in the order in which they are found.
2. Each channel on compact analogue terminals uses 2 bytes of data.
3. Digital terminals are added to the process images starting AFTER the analogue
inputs and outputs, and are added in the order in which they are found.
4. Each channel on a digital terminal will use 1 bit of data, and is assigned to the
next available bit.
NOTE: if no analogue terminals are fitted, the digital inputs and output will start

in the process image at %IW0 and %QW0.


In the example configuration, the analogue inputs and outputs have been declared as
compact terminals, so each analogue terminal will use the first 4 data bytes. Digital
terminal mapping will start at %IX4.0 and %QX4.0.
Analogue Terminals
KL3002

KL4032

Channel

Input Image

Output Image

%IW0

----

%IW2

----

----

%QW0

----

%QW2

Digital Terminals
KL1002

KL1002

KL2032

KL2032

Updated: 15/06/2005

%IX4.0

----

%IX4.1

----

%IX4.2

----

%IX4.3

----

----

%QX4.0

----

%QX4.1

----

%QX4.2

----

%QX4.3

Page 19 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

The input and output process images can now be declared for the program, and
variables assigned to each input and output. The lines of code required are shown
below. It is advisable to declare input and output variables as global variables to ensure

that they can be accessed from all program modules.


VAR_GLOBAL

(* Inputs *)
AnIn1
AnIn2

DigIn1
DigIn2
DigIn3
DigIn4

(* Outputs *)
AnOut1
AnOut2
DigOut1
DigOut2
DigOut3
DigOut4

AT
AT
AT
AT
AT
AT

%IW0

AT
AT
AT
AT
AT
AT

%QW0

%IW2

:
:

%IX4.0
%IX4.1
%IX4.2
%IX4.3

%QW2

%QX4.0
%QX4.1
%QX4.2
%QX4.3

INT;
INT;
:
:
:
:

:
:

BOOL;
BOOL;
BOOL;
BOOL;

INT;
INT;
:
:
:
:

BOOL;
BOOL;
BOOL;
BOOL;

END_VAR

To declare input and output variables as global variables:


1. Click on the Resources tab
2. Double click Global_Variables

3. Enter the input and output variable declarations as required. Any variables
declared here will be available to all program modules (POUs) in the BC program.

Updated: 15/06/2005

Page 20 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

3.3. Writing the BC PLC Program


The BC PLC program was declared as MAIN and the programming language selected
was LADDER. MAIN is the first POU to run when the BC boots up, but all code added to
MAIN must be written in LADDER. Additional POUs may be created and written in any
available language, and these can be called from MAIN as required.
The example screen below shows a BC program consisting of a single POU and written in
LADDER. There are no variables declared in MAIN as the inputs and outputs have already

been declared globally.

Updated: 15/06/2005

Page 21 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

3.4. Compiling the BC PLC Program


The PLC program must be compiled without errors before it can be downloaded to the
BC. To compile the PLC program:

1. Select Project
2. Select Rebuild all

Updated: 15/06/2005

Page 22 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC


TwinCAT PLC will compile the program and check for errors. If any errors are found,
they will be displayed in the window beneath the program window, along the position in

the program where the error was found.


In the example below, the program has compiled successfully with no errors and no

warnings.

Updated: 15/06/2005

Page 23 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

4. Downloading BC PLC Project


Once the PLC program has been compiled, it must be downloaded to the BC.

4.1. Select Target BC9000 for Ethernet Connection


To select the BC9000 as the target device for the PLC program:

1. Select Online
2. Select Choose Run-Time System

Updated: 15/06/2005

Page 24 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

3. Double click on the BC9000 device


4. Select Run-Time 1 (Port 800) for the BC9000
5. Click OK

TwinCAT PLC will show the BC9000 as the target system for the PLC program in the red

box at the bottom of the screen.

Updated: 15/06/2005

Page 25 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

4.2. Configure COM Port for Serial Connection


To configure the COM port of the PC:

1. Select Online
2. Select Communication Parameters

3.
4.
5.
6.
7.

Select the Baud rate for the BC. Default baud rate is 19200
Select the COM port to be used on the local PC

Set the number of Stop Bits to 1


Set the Parity to Even
Click OK

Updated: 15/06/2005

Page 26 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

4.3. Download BC PLC Program


The PLC program download procedure is the same for a BC9000 via Ethernet and a BC via
serial connection. To download a PLC program to the BC:

1. Select Online
2. Select Login

If the BC does not currently have a program loaded, it will ask if you want to download

the new program.


3. Click Yes

Updated: 15/06/2005

Page 27 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC


To start the newly downloaded program:

4. Select Online
5. Select RUN

Updated: 15/06/2005

Page 28 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC


TwinCAT PLC will display the current run status is green at the bottom of the screen.
The current state of each rung of the LADDER program can also be seen while TwinCAT
PLC is on-line.

Updated: 15/06/2005

Page 29 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

4.4. Editing BC PLC Program


Changes to the BC PLC program cannot be made while TwinCAT PLC is logged on to the
BC. To make changes to the PLC program:

1. Select Online
2. Select Logout

TwinCAT PLC will go off-line, and the PLC program can be edited. When the required

changes have been made, the program must be re-compiled and downloaded to the BC.
(Refer to section 3.4, Compiling the BC PLC Program on page 22 and section 4.3,
Download BC PLC Program on page 27.)

Updated: 15/06/2005

Page 30 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

4.5. Create BC Boot Project


The BC Boot Project is the program that runs automatically when the BC boots-up after
a full reset or power-up. To create the BC Boot Project:

1. Select Online
2. Select Create Bootproject

TwinCAT PLC will create the boot project in the BC. When this process is complete:
3. Click OK to finish.

Updated: 15/06/2005

Page 31 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

5. Checking BC Input and Output Images


The BC input and output process images can be exported from TwinCAT System Manager
and imported into TwinCAT PLC. This allows the user-generated BC input and output

images to be checked against the exported images.


However, it is not recommended to rely on the export/import method for generating the
input and output images. Under TwinCAT System Manager, input and output terminals
dedicated to the BC PLC cannot be given user names, and the exported variable names

are fixed.
The exported variable names may be changed AFTER they have been imported into the
BC PLC program to make them easier to use in the PLC program. However, if the

variable names were to be re-imported at a later date due to a change in the I/O
configuration, the modified names would be lost.

5.1. Export BC Input and Output Images


To export the BC variable information:

1. Right click on the BC


2. Select Export Variable Info

Updated: 15/06/2005

Page 32 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

3. Specify a location to save the file


4. Specify a name for the export file
5. Click Save

5.2. Import BC Input and Output Images


To import the variable information file into TwinCAT PLC:

1. Select Project
2. Select Import

Updated: 15/06/2005

Page 33 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

3. Select the file to be imported

To view the imported input and output image variable information:

4. Select the Resources tab


5. Double click on TwinCAT_Import

The imported input and output process images are shown in the variable declaration

window. These can be compared with the user-generated input and output process
images to ensure that no mistakes have been made.

Updated: 15/06/2005

Page 34 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC

6. BC Program Cycle Time


To start the cycle time measurement of the BC PLC program:

1. Select Online
2. Select Coupler
3. Select Start Cycle Time Measuring

Updated: 15/06/2005

Page 35 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC


To stop the cycle time measurement of the BC PLC program:

4. Select Online
5. Select Coupler
6. Select Stop Cycle Time Measuring

Updated: 15/06/2005

Page 36 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC


To view the cycle time measurement of the BC PLC program:

7. Select Online
8. Select Coupler
9. Select Read Cycle Time Measuring

Updated: 15/06/2005

Page 37 of 38

Revision: 1.4

Using BC and IL230x-Cxxx as a Stand-Alone PLC


The measured PLC cycle times will be displayed. The Minimum and Maximum PLC cycle

times are displayed, along with the Middle cycle time. The Actual cycle time is the
average measured PLC cycle time taken over the number of measured cycles.

Updated: 15/06/2005

Page 38 of 38

Revision: 1.4

Potrebbero piacerti anche