0% found this document useful (0 votes)
508 views

12 TwinCAT PLC Control

The document describes how to create a user-defined function block for an indicator in TwinCAT PLC programming. It involves inserting an FBD function block, adding timing (TON) and logic (AND/NOT) boxes, declaring input and output variables, and wiring the blocks to turn on an output lamp when timing exceeds a set value. The steps show how to develop custom function blocks from standard functions.
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)
508 views

12 TwinCAT PLC Control

The document describes how to create a user-defined function block for an indicator in TwinCAT PLC programming. It involves inserting an FBD function block, adding timing (TON) and logic (AND/NOT) boxes, declaring input and output variables, and wiring the blocks to turn on an output lamp when timing exceeds a set value. The steps show how to develop custom function blocks from standard functions.
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/ 81

New Automation Technology

TwinCAT-Training: PLC Programmng 1


Roland Chia / BASG
New Automation Technology

CONTENTS

1) Standard Data types & Operators.


2) Standard Function Blocks & Functions
3) Development of User defined Function Block and Function
4) Development of User defined Libraries
5) PLC Task and Task Configuration
6) Auto Boot Sequencing
7) Source Code Download
8) Uploading of PLC Program from Controller
9) Data Retaintivity
10) Program Simulation
11) Debugging Features
12) PLC control options
13) Trace Configuration

TwinCAT-Training: PLC Programming


Roland Chia / BASG
Standard Data Types

Data Type Range Memory Use


BOOL 0 OR 1 8 Bit
BYTE 0 To 255 8 Bit
WORD 0 To 65535 16 Bit
DWORD 0 To 4294967295 32 Bit
SINT (-128) To (127) 8 Bit
USINT 0 To 255 8 Bit
INT (-32768) To (32767) 16 Bit
UINT 0 To 65535 16 Bit
DINT (-2147483648) To (2147483648) 32 Bit
UDINT 0 To 4294967295 32 Bit
REAL ~(-3.402823 * 1038) To ~(3.402823 * 32 Bit
1038)
LREAL ~(-1.79769313486231E308) To 64 Bit
~(1.79769313486231E308)

TwinCAT-Training: PLC Programming 3


Roland Chia / BASG
Overview of IEC Operators
Numeric Arithmetic String Shift Select Compare SEL Conversion

ABS ADD AND SHL SEL GT INDEXOF BOOL TO


ACOS MUL OR SHR MAX LT SIZEOF TO BOOL
ASIN SUB XOR ROL MIN LE ADR STRING TO
ATAN DIV NOT ROR LIMIT GE ADRINST TO STRING
COS MOD MUX EQ ^ TIME TO
EXP MOVE NE CAL DATE TO
EXPT BITADR TOD TO
LN DT TO
LOG REAL TO
SIN TRUNC
SQRT
TAN
TwinCAT-Training: PLC Programming 4
Roland Chia / BASG
New Automation Technology

CONTENTS

1) Standard Data types & Operators.


2) Standard Function Blocks & Functions
3) Development of User defined Function Block and Function
4) Development of User defined Libraries
5) PLC Task and Task Configuration
6) Auto Boot Sequencing
7) Source Code Download
8) Uploading of PLC Program from Controller
9) Data Retaintivity
10) Program Simulation
11) Debugging Features
12) PLC control options
13) Trace Configuration

TwinCAT-Training: PLC Programming


Roland Chia / BASG
Standard Functions & Function Blocks

Rising Edge Detector :- Falling Edge Detector :-

TwinCAT-Training: PLC Programming 6


Roland Chia / BASG
Standard Functions & Function Blocks

RS SR

TwinCAT-Training: PLC Programming 7


Roland Chia / BASG
Standard Functions & Function Blocks

UP Counter Down Counter

TwinCAT-Training: PLC Programming 8


Roland Chia / BASG
Standard Functions & Function Blocks

UP-DOWN Counter

TwinCAT-Training: PLC Programming 9


Roland Chia / BASG
Standard Functions & Function Blocks

OFF Delay Timer

TwinCAT-Training: PLC Programming 10


Roland Chia / BASG
Standard Functions & Function Blocks

ON Delay Timer

TwinCAT-Training: PLC Programming 11


Roland Chia / BASG
Standard Functions & Function Blocks

Pulse Timer

TwinCAT-Training: PLC Programming 12


Roland Chia / BASG
Timer

Start

T/10ms

TwinCAT-Training: PLC Programming 13


Roland Chia / BASG
New Automation Technology

CONTENTS

1) Standard Data types & Operators.


2) Standard Function Blocks & Functions
3) Development of User defined Function Block and Function
4) Development of User defined Libraries
5) PLC Task and Task Configuration
6) Auto Boot Sequencing
7) Source Code Download
8) Uploading of PLC Program from Controller
9) Data Retaintivity
10) Program Simulation
11) Debugging Features
12) PLC control options
13) Trace Configuration

TwinCAT-Training: PLC Programming


Roland Chia / BASG
Block types

Program
1. Can call other programs,
function blocks, and functions
2. Retains the state of local variables
between program calls

Function Block
1. Can call other function blocks and functions
2. Retains the state of local variables
between program calls
3. The function block program code
Function can be used repeatedly, in each case
1. Has no memory with a different memory
2. Returns the
result via the
function name LD Var1
ADD Var2
GE limit
ST enable

TwinCAT-Training: PLC Programming 15


Roland Chia / BASG
Example: Indicator under FBD (1)

 First save the project via File/Save As.


 Click on the Blocks tab.
 Right-click the blocks folder at the top
and insert an object.
 Select an FBD function block with the Add
title ”Blinker” (Indicator) and confirm
Object
with OK.

Blocks

TwinCAT-Training: PLC Programming 16


Roland Chia / BASG
Example: Indicator under FBD (2)

 In network 0001, right-click in the


square behind the ???,
 Select Box.
 An AND Box is inserted in the editor.
 Repeat the process at the end of the
AND Box.
 A total of 3 Boxes are required

TwinCAT-Training: PLC Programming 17


Roland Chia / BASG
Example: Indicator under FBD (3)

 Click on the name of the centre


AND Box.
 Call up a new window with Input
Assistant via function key F2.
 The Box can be overwritten.
 Under standard function blocks
select the Timer folder an search
for TON.
 Confirm with OK and click
anywhere in the network in order to
update the diagram.
 Repeat the process for the last
AND Box.

TwinCAT-Training: PLC Programming 18


Roland Chia / BASG
Example: Indicator under FBD (4)

 Enter a name at the ??? above the


first TON Box and click anywhere in
the network.
 The variable declaration window
appears.
 The entries for the Box are correct.
Confirm window with OK and click
anywhere in the network in order to
update the diagram.
 Repeat the process for the second
TON (use a different name).

TwinCAT-Training: PLC Programming 19


Roland Chia / BASG
Example: Indicator under FBD (5)

 Enter the name „Start“ at the ??? for


first AND, then click anywhere in the
network.
 The variable declaration window
appears.
 The entry under class has to be
changed to VAR_INPUT for the
variable. Confirm window with OK
and click anywhere in the network in
order to update the diagram.
 Repeat the process for the variable
TimeValue and change the type to
TIME.

TwinCAT-Training: PLC Programming 20


Roland Chia / BASG
Example: Indicator under FBD (6)

 Right-click next to IN at Timer_2 and


select an Assign.
 Enter lamp as the variable at the new
???, then click anywhere in the
network.
 The variable declaration window
appears.
 The entry under class has to be
changed to VAR_OUTPUT for the
variable. Confirm window with OK
and click anywhere in the network in
order to update the diagram.

TwinCAT-Training: PLC Programming 21


Roland Chia / BASG
Example: Indicator under FBD (7)

 Right-click next to the ??? of AND


and select a negation.
 Then click on the ??? for marking
and press F2. The Input Assistant
opens.
 Select local variables/Timer_2.Q.
Confirm window with OK and click
anywhere in the network in order
to update the diagram.
 The Indicator FB has been
created.

TwinCAT-Training: PLC Programming 22


Roland Chia / BASG
Example: Indicator under FBD (8)

 Double-click on Main to open the


main program.
 In network 0001, right-click in the
square behind the ???.
 Select Box.
 An AND Box is inserted in the editor.

TwinCAT-Training: PLC Programming 23


Roland Chia / BASG
Example: Indicator under FBD (9)

 Click on the name of the AND Box.


 Call up a new window with Input
Assistant via function key F2.
 The block can be overwritten.
 From the defined function blocks
select the Indicator block.
 Confirm with OK and click anywhere
in the network in order to update the
diagram.

TwinCAT-Training: PLC Programming 24


Roland Chia / BASG
Example: Indicator under FBD (10)

 Enter a name at the ??? above the


indicator Box and click anywhere in
the network.
 The variable declaration window
appears.
 The entries for the Box are correct.
Confirm window with OK and click
anywhere in the network in order to
update the diagram.
 Right-click at the end of the block
and select an Assign.

TwinCAT-Training: PLC Programming 25


Roland Chia / BASG
Example: Indicator under FBD (10)

 Then mark the ??? at the start input


by clicking and press F2. The Input
Assistant appears.
 Select variable bSwitch_1 under
global variables. Confirm window
with OK and click anywhere in the
network in order to update the
diagram.
 Repeat the process at the ??? at
lamp output and select variable
bLamp_1.
 Finally, enter a time at the ??? at the
time value input. T#1s (s=sec.)

TwinCAT-Training: PLC Programming 26


Roland Chia / BASG
Example: Indicator under FBD (11)

 Finally select Project/Compile.


 Check for error messages in the message window.

TwinCAT-Training: PLC Programming 27


Roland Chia / BASG
Instantiation of function blocks

n-1 cycle

n cycle

TwinCAT-Training: PLC Programming 28


Roland Chia / BASG
Display of individual instances

Note the following if this menu item is not


selectable (greyed out):
1. Project must be logged in.
2. The block should be marked in the left
window and displayed in the right window.

TwinCAT-Training: PLC Programming 29


Roland Chia / BASG
New Automation Technology

CONTENTS

1) Standard Data types & Operators.


2) Standard Function Blocks & Functions
3) Development of User defined Function Block and Function
4) Development of User defined Libraries
5) PLC Task and Task Configuration
6) Auto Boot Sequencing
7) Source Code Download
8) Uploading of PLC Program from Controller
9) Data Retaintivity
10) Program Simulation
11) Debugging Features
12) PLC control options
13) Trace Configuration

TwinCAT-Training: PLC Programming


Roland Chia / BASG
New Automation Technology

CONTENTS

1) Standard Data types & Operators.


2) Standard Function Blocks & Functions
3) Development of User defined Function Block and Function
4) Development of User defined Libraries
5) PLC Task and Task Configuration
6) Auto Boot Sequencing
7) Source Code Download
8) Uploading of PLC Program from Controller
9) Data Retaintivity
10) Program Simulation
11) Debugging Features
12) PLC control options
13) Trace Configuration

TwinCAT-Training: PLC Programming


Roland Chia / BASG
PLC Task‘s

 Standard PLC: Programs are processed cyclically:


fixed cycle time is one of the operating modes

Real-time operation of PLC software in a classic PLC

outputs
program

program
Process

Process
outputs

inputs
inputs

Write
Read
Read

Write

PLC cycle PLC cycle t


TwinCAT-Training: PLC Programming 32
Roland Chia / BASG
Implementation: Basic tasks of PC control
Operation of a software PLC on the PC
 Software PLC: Computing capacity is reserved for the PC
operating system
 The software PLC operates with a fixed cycle, the PC operating system
and the user interface in the period between cycles

Real-time operation of PLC software on a PC


Write outputs

Write outputs
Windows NT

Read inputs
Read inputs

Read inputs
program
program

program
Process
and HMI
Process

Process
PLC cycle PLC cycle t
TwinCAT-Training: PLC Programming 33
Roland Chia / BASG
Implementation: Basic tasks of PC control Operation of a
software PLC and software NC on the PC

 PLC tasks and NC drive control processed deterministically via


multitasking
 Computing capacity is regularly made available for the operating
system

Real-time operation of software for PLC and NC on a PC

PLC server Windows NT and HMI NC server (drive control)

e.g.: 1ms 2ms 3ms 4ms 5ms


t
NC cycle (e.g. 1 ms) NC cycle NC cycle NC cycle
t
PLC cycle (e.g. 2 ms) PLC cycle

TwinCAT-Training: PLC Programming 34


Roland Chia / BASG
New Automation Technology

CONTENTS

1) Standard Data types & Operators.


2) Standard Function Blocks & Functions
3) Development of User defined Function Block and Function
4) Development of User defined Libraries
5) PLC Task and Task Configuration
6) Auto Boot Sequencing
7) Source Code Download
8) Uploading of PLC Program from Controller
9) Data Retaintivity
10) Program Simulation
11) Debugging Features
12) PLC control options
13) Trace Configuration

TwinCAT-Training: PLC Programming


Roland Chia / BASG
Automatic PLC start
Procedure
Request:
Power ON
Once the computer has been
switched on, it should be possible to
automate loading and starting of the
PLC project. Start of Win NT & login

Start TwinCAT

Loading of the boot project


into the runtime

Starting of the PLC

TwinCAT-Training: PLC Programming 36


Roland Chia / BASG
TwinCAT autostart

Automatic start of
TwinCAT
System Manager

Automatic login under


Windows with selected
users and password

TwinCAT-Training: PLC Programming 37


Roland Chia / BASG
Selection of runtime [1..4]

1.
The user should know under
which PLC (runtime) the
project was configured in PLC
Control Number of
Run-Times

Run-Time selection
and PLC start
TwinCAT-Training: PLC Programming 38
Roland Chia / BASG
Creation of a boot project in PLC Control

Requirements:
1. The machine should
operate correctly.
2. Hardware, software and
links are correct.
3. PLC Control is logged in

TwinCAT-Training: PLC Programming 39


Roland Chia / BASG
New Automation Technology

CONTENTS

1) Standard Data types & Operators.


2) Standard Function Blocks & Functions
3) Development of User defined Function Block and Function
4) Development of User defined Libraries
5) PLC Task and Task Configuration
6) Auto Boot Sequencing
7) Source Code Download
8) Uploading of PLC Program from Controller
9) Data Retaintivity
10) Program Simulation
11) Debugging Features
12) PLC control options
13) Trace Configuration

TwinCAT-Training: PLC Programming


Roland Chia / BASG
Saving of source code

 Select the „Project“ field in the


menu bar.
 A selection window opens.
 Select „Options“.

TwinCAT-Training: PLC Programming 41


Roland Chia / BASG
Time of source download

Implicit during loading:


The selected scope is written to the
control computer each time the PLC
project is opened.

Notice on loading:
If the PLC project has been modified,
a message box saying „Load source
code into the controller?“ will appear
during loading.

Create implicitly with a boot project:


The selected scope is written to the
control computer each time a boot
project is created.

TwinCAT-Training: PLC Programming 42


Roland Chia / BASG
Time/scope of source download

On Demand:
The source code is only loaded into
the controller on request.
Online/Load source code

Scope:
Source code only;
The PLC project is written to the
control computer.

All files:
The PLC project including the
libraries is written to the control
computer.

TwinCAT-Training: PLC Programming 43


Roland Chia / BASG
New Automation Technology

CONTENTS

1) Standard Data types & Operators.


2) Standard Function Blocks & Functions
3) Development of User defined Function Block and Function
4) Development of User defined Libraries
5) PLC Task and Task Configuration
6) Auto Boot Sequencing
7) Source Code Download
8) Uploading of PLC Program from Controller
9) Data Retaintivity
10) Program Simulation
11) Debugging Features
12) PLC control options
13) Trace Configuration

TwinCAT-Training: PLC Programming


Roland Chia / BASG
Open PLC project from the controller

The current PLC project can


be opened directly from the
controller.
Select button „Open project
from PLC“ under „Open File“.

TwinCAT-Training: PLC Programming 45


Roland Chia / BASG
Open PLC project from the controller

The reloaded project can be used for:

a) Save as „Copy from controller“

b) Comparison with other projects

c) Continue operation directly on the other controller

TwinCAT-Training: PLC Programming 46


Roland Chia / BASG
Select target system for PLC Control
connection (1) (target computer + PLC runtime)

IMPORTANT!!!!

TwinCAT-Training: PLC Programming 47


Roland Chia / BASG
Select target system for PLC Control
connection (2)

IMPORTANT!!!!

On login the target system displayed is used!


TwinCAT-Training: PLC Programming 48
Roland Chia / BASG
Opening a System Manager project from the
target system
The System Manager
project may be loaded
from the controller.

TwinCAT-Training: PLC Programming 49


Roland Chia / BASG
New Automation Technology

CONTENTS

1) Standard Data types & Operators.


2) Standard Function Blocks & Functions
3) Development of User defined Function Block and Function
4) Development of User defined Libraries
5) PLC Task and Task Configuration
6) Auto Boot Sequencing
7) Source Code Download
8) Uploading of PLC Program from Controller
9) Data Retentivity
10) Program Simulation
11) Debugging Features
12) PLC control options
13) Trace Configuration

TwinCAT-Training: PLC Programming


Roland Chia / BASG
Data Retentivity

RETAIN
PERSISTENT

The data can be


The data can only be deleted deleted through
through a Reset All „Reset“ or „Clean
all“

Enable
archiving

Enable archiving not required

TwinCAT-Training: PLC Programming 51


Roland Chia / BASG
Data Retentivity

Notes:
Remanent data (persistent and retain) are only stored if the
TwinCAT system service is terminated cleanly. This usually
involves using a UPS for shutting down the computer.
Data are also written if the computer is shut down manually
A new boot project has to be created if „persistent“ and
„retain“ variables are modified.

TwinCAT-Training: Maintenance / Comissioning 52


New Automation Technology

CONTENTS

1) Standard Data types & Operators.


2) Standard Function Blocks & Functions
3) Development of User defined Function Block and Function
4) Development of User defined Libraries
5) PLC Task and Task Configuration
6) Auto Boot Sequencing
7) Source Code Download
8) Uploading of PLC Program from Controller
9) Data Retaintivity
10) Program Simulation
11) Debugging Features
12) PLC control options
13) Trace Configuration

TwinCAT-Training: PLC Programming


Roland Chia / BASG
New Automation Technology

CONTENTS

1) Standard Data types & Operators.


2) Standard Function Blocks & Functions
3) Development of User defined Function Block and Function
4) Development of User defined Libraries
5) PLC Task and Task Configuration
6) Auto Boot Sequencing
7) Source Code Download
8) Uploading of PLC Program from Controller
9) Data Retaintivity
10) Program Simulation
11) Debugging Features
12) PLC control options
13) Trace Configuration

TwinCAT-Training: PLC Programming


Roland Chia / BASG
Debugging and search functions in PLC Control
and in the System Manager
Requirement:
 Project must be logged in
 Project must be running

If flow control is activated, each line or network


executed during the last control cycle is
marked.
The number field of the active rows or networks
are shown in green.

TwinCAT-Training: PLC Programming 55


Roland Chia / BASG
Flow Control

 A further field is inserted for


all connecting lines not
transporting Boolean values.
 If these outputs and inputs
are assigned, the value
transported via the
connecting line is displayed
in this field.

TwinCAT-Training: PLC Programming 56


Roland Chia / BASG
Flow Control

Connecting lines exclusively


transporting Boolean values are
only shown in blue if the transport
is TRUE.
The flow of information can thus
be monitored continuously.

TwinCAT-Training: PLC Programming 57


Roland Chia / BASG
Cross-reference list 1

Mark variable 2x

TwinCAT-Training: PLC Programming 58


Roland Chia / BASG
Cross-reference list 2

Read/Write

Block name Variable name Global/local


Network/line no. Variable address

TwinCAT-Training: PLC Programming 59


Roland Chia / BASG
Cross-reference list 3

Click on Line which you


want to chose and press
Goto
Change to selected
network/line of code

Cross-references to:
Variables – bLamp_4
addresses - %QX20.3
blocks – Test5
TwinCAT-Training: PLC Programming 60
Roland Chia / BASG
Cross-reference list in the System Manager
(select)

TwinCAT-Training: PLC Programming 61


Roland Chia / BASG
Cross-reference list in the System Manager
(print)

TwinCAT-Training: PLC Programming 62


Roland Chia / BASG
Show Call Tree

TwinCAT-Training: PLC Programming 63


Roland Chia / BASG
Global search and replace

TwinCAT-Training: PLC Programming 64


Roland Chia / BASG
Break points

Setting a break point

Program flow

If the program overruns a


break point, the colour
changes to red, and
program execution is
stopped

TwinCAT-Training: PLC Programming 65


Roland Chia / BASG
Break points

Data exchange is As a result, the slave module


interrupted, since in most watchdog is deactivated after
bus systems data 100 ms, and the outputs are
exchange is requested by reset.
the PLC.

Lifting axes are held by the


brakes.
Pneumatic valves drop out

TwinCAT-Training: PLC Programming 66


Roland Chia / BASG
New Automation Technology

CONTENTS

1) Standard Data types & Operators.


2) Standard Function Blocks & Functions
3) Development of User defined Function Block and Function
4) Development of User defined Libraries
5) PLC Task and Task Configuration
6) Auto Boot Sequencing
7) Source Code Download
8) Uploading of PLC Program from Controller
9) Data Retaintivity
10) Program Simulation
11) Debugging Features
12) PLC control options
13) Trace Configuration

TwinCAT-Training: PLC Programming


Roland Chia / BASG
PLC Control options

TwinCAT-Training: PLC Programming 68


Roland Chia / BASG
Options (working area)

TwinCAT-Training: PLC Programming 69


Roland Chia / BASG
Options (password)

Absolute password
(reading and writing)

View enabled; the


program can only be
changed with a
password
TwinCAT-Training: PLC Programming 70
Roland Chia / BASG
Options (TwinCAT)

Break points can be


set by clicking on the
network field or a row
number

TwinCAT-Training: PLC Programming 71


Roland Chia / BASG
Watch window 1

Precondition for entering


variables in the required
list:
 PLC Control should be
offline with the required
project.

2x

TwinCAT-Training: PLC Programming 72


Roland Chia / BASG
Watch window 2

Several lists can be created

Subsequent switching between lists is


possible

TwinCAT-Training: PLC Programming 73


Roland Chia / BASG
New Automation Technology

CONTENTS

1) Standard Data types & Operators.


2) Standard Function Blocks & Functions
3) Development of User defined Function Block and Function
4) Development of User defined Libraries
5) PLC Task and Task Configuration
6) Auto Boot Sequencing
7) Source Code Download
8) Uploading of PLC Program from Controller
9) Data Retaintivity
10) Program Simulation
11) Debugging Features
12) PLC control options
13) Trace Configuration

TwinCAT-Training: PLC Programming


Roland Chia / BASG
Trace Configuration

2x

TwinCAT-Training: PLC Programming 75


Roland Chia / BASG
Trace configuration 1

Zero corresponds
to the cycle time,
otherwise xx ms

TwinCAT-Training: PLC Programming 76


Roland Chia / BASG
Trace configuration 2

As soon as the trigger is


active, an individual
recording (or consecutive
recording with each
trigger) is started.

Insert Trace
Variables
TwinCAT-Training: PLc Programming 77
Roland Chia / BASG
Trace configuration 3

The selected trigger


variable is displayed
here
The list of
available variables
is displayed here

Start Read Stop Zoom

TwinCAT-Training: PLC Programming 78


Roland Chia / BASG
Cursor
Cycle number

Automatic
scaling

Automatic Press and


colour hold the
selection Variable
left mouse
value at the
button
intersection
with the
cursor

TwinCAT-Training: PLC Programming 79


Roland Chia / BASG
Sampling Trace

Requirements: Trace recording started.


Waiting for trigger event
 PLC Control should be
online with the required
project.
 The project is in „running“ The trigger event has occurred;
mode. trace recording running

Once the selected number of


recordings is reached
(1-2048), recording is complete

TwinCAT-Training: PLC Programming 80


Roland Chia / BASG
THANK YOU!!!

TwinCAT-Training: PLC Programming 81


Roland Chia / BASG

You might also like