100% found this document useful (3 votes)
590 views

TwinCAT Basic Training

This document provides instructions for a series of exercises to learn the basics of the TwinCAT automation technology. The exercises cover topics like auto scanning hardware, creating PLC projects, linking variables to I/Os, downloading and running PLC programs, creating function blocks, configuring auto startup settings, and developing basic PLC functions. The exercises are divided into those for TwinCAT 2 and TwinCAT 3, with the latter focusing on the newer XAE development environment.

Uploaded by

Prengga
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
100% found this document useful (3 votes)
590 views

TwinCAT Basic Training

This document provides instructions for a series of exercises to learn the basics of the TwinCAT automation technology. The exercises cover topics like auto scanning hardware, creating PLC projects, linking variables to I/Os, downloading and running PLC programs, creating function blocks, configuring auto startup settings, and developing basic PLC functions. The exercises are divided into those for TwinCAT 2 and TwinCAT 3, with the latter focusing on the newer XAE development environment.

Uploaded by

Prengga
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/ 21

THE WINDOWS CONTROL AND

AUTOMATION TECHNOLOGY
(TwinCAT)
EXERCISES BASIC TRAINING

1
Contents

Contents…………………………………………………………………………………………………………………………………………….2

TwinCAT 2:

PLC Exercise 1: Auto Scanning of Hardware ................................................................................... 3


PLC Exercise 2: Creating a new PLC project .................................................................................... 3
PLC Exercise 3: Linking Variables with I/Os and Activate Configuration .......................................... 4
PLC Exercise 4: Downloading and Running PLC project ................................................................... 4
PLC Exercise 5: Creating Blinker Function Block .............................................................................. 4
PLC Exercise 6: Configuring Auto-startup Boot Project setting........................................................ 6
PLC Exercise 7: Downloading Source Code ..................................................................................... 7
PLC Exercise 8: Uploading Source Code .......................................................................................... 7
PLC Exercise 9: Uploading System Manager file from Target System .............................................. 8
PLC Exercise 10 : Creating Scale Function ....................................................................................... 8

TwinCAT 3

PLC Exercise 11: Auto Scanning of Hardware ................................................................................. 9


PLC Exercise 12: Creating a new PLC program .............................................................................. 10
PLC Exercise 13: Linking the Variables and Activate Configuration ............................................... 12
PLC Exercise 14: Downloading and Running PLC project ............................................................... 12
PLC Exercise 15: Creating Function Block ..................................................................................... 13
PLC Exercise 16: Configuring Auto Start Boot Project ................................................................... 16
PLC Exercise 17: Uploading Source Code ...................................................................................... 16
PLC Exercise 18 : Creating Scale Function ..................................................................................... 17
PLC Exercise 19: Establishing a remote connection ...................................................................... 18
PLC Exercise 20: Creating Traffic Light Program............................................................................ 20

2
PLC Exercise 1: Auto Scanning of Hardware
1) Start TwinCAT System Manager
2) Create a new TSM file. Click File >> New
3) Select Local Target. Click [Choose Target]
4) Ensure TwinCAT in Config Mode. Click Actions >> Set/Reset TwinCAT to Config Mode
5) Scan Devices. Right click on I/O device, select “Scan Devices”
6) Scan Boxes to auto-detect couplers and IO terminals.
7) Activate Free Run to perform I/O check
8) Now Test all individual I/O points
9) Save the TSM file into Desktop\Exercise folder

PLC Exercise 2: Creating a new PLC project


1) Start TwinCAT PLC control
2) Create a new PRO file. Click File >> New
3) Select the correct Target System type. Select “PC or CX ( x86)”
4) Create a new POU “Main”. Select the preferred IEC61131 programming language.
5) Navigate to Global Variable under Resources tab
6) Declare global variables for I/O.
DIn0 AT %I* : BOOL;
DIn1 AT %I* : BOOL;
DOut0 AT %Q* : BOOL;
DOut1 AT %Q* : BOOL;
AIn0 AT %I* : INT;
AOut0 AT %Q* : INT;

Recommend to follow Programming Convention for creating IEC61131-3


(http://infosys.beckhoff.com/english.php?content=../content/1033/tcplclibsoverview/html/
tcplclibsprogrammingconventions.htm&id=13132)

7) Use Auto Declare wizard. Select Edit >> Auto declare


8) Write Sample code
9) Save project file. File >> Save as…
10) Compile and check for error. Project >> Rebuild All.
11) Ensure there’s no error before proceeding to next exercise.

PLC Exercise 3: Linking Variables with I/Os and Activate Configuration

1) In System Manager, right click on “PLC Configuration” and select “Append PLC project”
2) Select project information file *.TPY
3) Select desired I/O process image and link to corresponding PLC Variables.

3
Din0 EL1012, Channel 1, Input
Din1 EL1012, Channel 2, Input
DOut0 EL2004, Channel 1, Output
DOut1 EL2004, Channel 2, Output
AIn0 EL3102, AI Standard Channel 1, Value
AOut0 EL4102, Channel 1, Output

4) Save TSM file. File >> Save


5) Enable TwinCAT System to RUN mode. Actions >> Activate Configuration…

PLC Exercise 4: Downloading and Running PLC project


1) In PLC Control, select the Target Runtime Port. Click Online >> Choose RunTime system
2) Connect to PLC Controller. Click Online >> Login
3) Download PLC program to Controller.
4) Switch Controller to RUN mode. Click Online >> Run
5) After testing and finalizing the PLC program, remember to Create Boot project.
Click Online >> Create Boot Project

PLC Exercise 5: Creating Blinker Function Block


1) Add Object under POUs.
2) Enter the Name of new POU: FB_Blinker
Type of POU: Function block
Language of POU: FBD (Function Block Diagram)
3) Declare Variables
VAR_INPUT
Start : BOOL;
TimeVal : TIME;
END_VAR
VAR_OUTPUT
Blink : BOOL;
END_VAR
VAR
Timer1 : TON;
Timer2 : TON;
END_VAR
4) Create the logic diagram as below

4
5) Call the Blinker function block in Main Program

6) Compile and check for error. Project >> Rebuild All


7) Download and run the program

5
PLC Exercise 6: Configuring Auto-startup Boot Project setting
1) In the System Manager, select “System configuration”. Click on the “Boot Settings” tab.

2) Ensure that “Run Mode (Enable)” radio button is selected.


3) Ensure “Auto Logon” check box is tick. User name: Administrator. Password: 1 (default for
Beckhofff iPC)
4) Click “Apply” button
5) Select “PLC Configuration”. Click on the “Plc Settings” tab.

6) Ensure ”Run-Time System (Port:801)” check box is tick.


7) Click “Apply” button
8) Enable TwinCAT System to RUN mode. Actions >> Activate Configuration…

6
PLC Exercise 7: Downloading Source Code
1) Project >> Options…

2) Online >> Login


3) Online >> SourceCode Download

PLC Exercise 8: Uploading Source Code


1) File >> Open. Click on the “PLC…” button

2) Choose the correct Runtime target system

7
PLC Exercise 9: Uploading System Manager file from Target System
1) File >> Open from Target

2) Choose the correct Runtime target system

PLC Exercise 10 : Creating Scale Function


1) Add Object under POUs.
2) Enter the Name of new POU: Scale
Type of POU: Function
Return Type: Real
Language of POU: ST (Structured Text)
3) Declare Variables
FUNCTION Scale : REAL
VAR_INPUT
Ain : REAL;
XUpp, XLow, YUpp, YLow : REAL;
END_VAR
VAR
ScaleFactor, Offset : REAL;
END_VAR
4) Programmed the following codes.
ScaleFactor := (YUpp – YLow) / (XUpp – XLow);
Scale := ScaleFactor * Ain + Offset;
5) Call the Scale function in the MAIN program
TempRead := Scale( Ain := Ain0, XUpp := 32767, XLow := 0, YUpp := 100, YLow := 0);
6) Result of the Scale function is in TempRead

8
PLC Exercise 11: Auto Scanning of Hardware
1) Start TwinCAT3 XAE. Click START>> All Programs >> Beckhoff >> TwinCAT3 >> TwinCAT XAE.
2) Create a new XAE project. Click File >> New >> Project
3) Select “TwinCAT XAE Project (XML Format)” template
4) Enter the Project name : “Tc3Exercise”
5) Choose “Local” as Target System

6) Ensure TwinCAT in Config Mode. TWINCAT >> Restart TWINCAT (Config Mode)

9
7) Scan Devices. Right click on I/O device, select “Scan”

8) Scan Boxes to auto-detect couplers and IO terminals.


9) Activate Free Run to perform I/O check
10) Now Test all individual I/O points
11) Save the Solution File. Click File >> Save All

PLC Exercise 12: Creating a new PLC program


1) Create a new PLC Project. Right click on PLC icon, select “Add New Item”

2) Select the “Standard PLC Template”. Enter the name: Exercise1.


3) Create a Global Variable List (GVLs). Right click on the GVLs folder, Select Add >> Global
Variable List. Enter the Name: GVL_IO

10
4) Declare global variables for I/O. You may use the Auto Declare wizard to assist you. Click
EDIT >> AUTO DECLARE

VAR_GLOBAL
bDin1 AT %I*: BOOL;
bDin2 AT %I*: BOOL;
bDin3 AT %I*: BOOL;
bDin4 AT %I*: BOOL;

bDout1 AT %Q*: BOOL;


bDout2 AT %Q*: BOOL;
bDout3 AT %Q*: BOOL;
bDout4 AT %Q*: BOOL;
bDout5 AT %Q*: BOOL;
bDout6 AT %Q*: BOOL;
bDout7 AT %Q*: BOOL;
bDout8 AT %Q*: BOOL;

nAin1 AT %I*: INT;


nAout1 AT %Q*: INT;

END_VAR
Recommend to follow Programming Convention for creating IEC61131-3
(http://infosys.beckhoff.com/english.php?content=../content/1033/tcplclibsoverview/html/
tcplclibsprogrammingconventions.htm&id=13132)

5) Save the Solution file.


6) Compile the project. Click BUILD >> Rebuild Solution. Ensure there’s no error before
proceeding to next step.

11
PLC Exercise 13: Linking the Variables and Activate Configuration
1) Linking the Variables. Right click on the Channel1 Input of EL1012, select “Change Link”

2) Select desired I/O process image and link to corresponding PLC Variables.

bDin1 EL1012, Channel 1, Input


bDin2 EL1012, Channel 2, Input
bDOut1 EL2004, Channel 1, Output
bDOut2 EL2004, Channel 2, Output
bDOut3 EL2004, Channel 1, Output
bDOut4 EL2004, Channel 2, Output
AIn0 EL3102, AI Standard Channel 1, Value
AOut0 EL4102, Channel 1, Output

3) Activate the Configuration. Click TWINCAT >> Activate Configuration. Enter the Security
code if prompted.

PLC Exercise 14: Downloading and Running PLC project


1) Logon to the PLC project. Click PLC >> Login.
2) Open the GVL_IO list and monitor the online values.
3) Double click on the Prepared Value column of bDout1 to set it TRUE. Click PLC >> Write
Values.
4) Logout of the PLC. Click PLC >> Logout.

12
PLC Exercise 15: Creating Function Block
1) Add Function Block under POUs (Program Organization Units). Right click on the POUs
folder, select Add >> POU.

2) Enter the Name of new POU: FB_Flash


Type : Function block
Implementation Language : FBD (Function Block Diagram)

3) Browse into the Toolbox, insert TON (Timer with On-delay) into the network rung.

13
4) Enter the variables name into the “???”
5) Right click on the ET (Elapse Time) output of TON, select “Set output connection”.
6) Complete the FB accordingly

7) In the variable declaration of MAIN, define fbFlash1 function block using Auto Declare

14
8) Call the fbFlash1 function block in the MAIN program using Input Assistant [F2]

9) Configure the input and output


E.g fbFlash1(tFlashTime:= T#500ms, bOut=> bDout5);
10) Save and Rebuild Solution. Ensure there’s no error.

15
PLC Exercise 16: Configuring Auto Start Boot Project
1) Right click on the Exercise1, select “Autostart Boot Project”

2) Double click on the System Node. In the Settings tab, check “Run Mode (Enable)” radio
button. Then, click “Apply” button.

3) When prompted with the User name and password. Username: Administrator, Default
Password : 1
4) Activate Configuration
5) Login to the PLC. Click PLC >> Login
6) Start the PLC program. Click PLC >> Start.

PLC Exercise 17: Uploading Source Code


1) If there’s any currently open solution file, close the solution file now. Click FILE >> Close
Solution.

16
2) To upload the Source code, click File >> Open >> Open Project From Target.

3) Choose the correct Runtime target system

PLC Exercise 18 : Creating Scale Function


1) Add Function under POUs . Right click on the POUs folder, select Add >> POU
2) Enter the Name of new POU: Scale
Type of POU: Function
Return Type: Real
Language of POU: ST (Structured Text)
3) Declare Variables
FUNCTION Scale : REAL
VAR_INPUT
Ain : REAL;
XUpp, XLow, YUpp, YLow : REAL;
END_VAR
VAR
ScaleFactor, Offset : REAL;
END_VAR
4) Programmed the following codes.
ScaleFactor := (YUpp – YLow) / (XUpp – XLow);
Scale := ScaleFactor * Ain + Offset;
5) Call the Scale function in the MAIN program
TempRead := Scale( Ain := Ain0, XUpp := 32767, XLow := 0, YUpp := 100, YLow := 0);
6) Result of the Scale function is in TempRead

17
PLC Exercise 19: Establishing a remote connection
1) Double click on “SYSTEM-Configuration”.

2) Click on “Choose Target” button

3) Select “Local” target, then “Search Ethernet”.

18
4) If Host name or IP address is known, this can be entered directly. Otherwise, perform a
“Broadcast Search”.

5) After selection of a device from the list, the route can be added

19
6) Select the Target sytem

PLC Exercise 20: Creating Traffic Light Program


1) Declare the Global Variable
VAR_GLOBAL
Button AT %I* : BOOL;
Red AT %Q* : BOOL;
Yellow AT %Q* : BOOL;
Green AT %Q* : BOOL;
RedMan AT %Q* : BOOL;
GreenMan AT %Q* : BOOL;
END_VAR
2) Code the traffic light program logic
3) Download the test run your program.

20
Support, Service, Training:

Beckhoff Automation Pte. Ltd.

Alamanda Tower, 25th Floor


Jl. T. B. Simatupang, Kav. 23-24
Jakarta 12430
Phone: + 62 (21) 2965 7847
www.beckhoff.co.id
[email protected]

21

You might also like