304
Teknologi otomatisasi baru Beckhoff TwinCAT 2 Direvisi: 28 Mei 2012 Brian McClure [email protected] Multilizer PDF Translator Free version - translation is limited to ~ 3 pages per translation. Multilizer PDF Translator Free version - translation is limited to ~ 3 pages per translation.

TwinCAT 2 Manual v2_1_0

Embed Size (px)

DESCRIPTION

manual twincat

Citation preview

  • Teknologi otomatisasi baru BeckhoffTwinCAT 2

    Direvisi: 28 Mei 2012Brian McClure

    [email protected]

    Multilizer PDF Translator Free version - translation is limited to ~ 3 pages per translation.

    Multilizer PDF Translator Free version - translation is limited to ~ 3 pages per translation.

  • #Pages [7]#Pages [7]#Pages [13]#Pages [21]#Pages [38]

    #Pages [39]#Pages [39]#Pages [41]#Pages [54]

    #Pages [56]#Pages [56]#Pages [60]#Pages [61]#Pages [64]#Pages [68]#Pages [73]#Pages [76]#Pages [83]#Pages [84]#Pages [86]#Pages [89]#Pages [92]#Pages [94]

    #Pages [98]#Pages [98]

    #Pages [171]#Pages [171]#Pages [175]#Pages [180]#Pages [184]#Pages [190]#Pages [196]

    TwinCAT 2

    Daftar isiSAYA.TwinCAT Overview............................................................................................................................................................ 7

    1. Overview ............................................................................................................................................................. 72. System Service .................................................................................................................................................. 133. System Manager ............................................................................................................................................... 214. PLC Control ........................................................................................................................................................ 38

    II. TwinCAT Software Installation ....................................................................................................................................... 395. TwinCAT Versions .............................................................................................................................................. 396. Software, Download & Installation ................................................................................................................... 417. Licensing and Registration ................................................................................................................................ 54

    III. PLC Ikhtisar.... 568. IDE ..................................................................................................................................................................... 569. Programs ........................................................................................................................................................... 6010. Data Types and Conversions ......................................................................................................................... 6111. Variables ........................................................................................................................................................ 6412. Languages ...................................................................................................................................................... 6813. Functions ....................................................................................................................................................... 7314. Function Blocks ............................................................................................................................................. 7615. Actions ........................................................................................................................................................... 8316. Structures ...................................................................................................................................................... 8417. Enumerations ................................................................................................................................................ 8618. Arrays ............................................................................................................................................................ 8919. Boot Project .................................................................................................................................................. 9220. Source code Download ................................................................................................................................. 94

    IV. PLC Programming "Inspeksi Conveyor".... 9821. Kontrol mesin dengan pemrograman... Top-Down. 98

    V. Trouble shooting .......................................................................................................................................................... 17122. Code Sequencing ......................................................................................................................................... 17123. Break Points ................................................................................................................................................ 17524. Flow Control ................................................................................................................................................ 18025. Global Search .............................................................................................................................................. 18426. Cross Reference .......................................................................................................................................... 19027. Scope View .................................................................................................................................................. 196

    Multilizer PDF Translator Free version - translation is limited to ~ 3 pages per translation.

    Multilizer PDF Translator Free version - translation is limited to ~ 3 pages per translation.

  • #Pages [203]#Pages [203]#Pages [204]#Pages [204]#Pages [208]#Pages [210]#Pages [211]#Pages [211]#Pages [212]#Pages [213]#Pages [214]#Pages [215]#Pages [215]#Pages [215]#Pages [215]#Pages [217]#Pages [219]#Pages [219]#Pages [219]#Pages [219]#Pages [220]#Pages [221]#Pages [221]#Pages [222]#Pages [222]#Pages [222]#Pages [223]#Pages [224]#Pages [224]#Pages [224]#Pages [227]#Pages [230]#Pages [230]

    TwinCAT 2VI. Camming ....................................................................................................................................................................... 203

    28. Preface ........................................................................................................................................................ 20329. Intro to TcMC2.Lib....................................................................................................................................... 204a. Overview ......................................................................................................................................................... 204b. Migration from TcMC to TcMC2 ..................................................................................................................... 208c. Status information .......................................................................................................................................... 21030. When to use a Cam Table ........................................................................................................................... 211a. Overview ......................................................................................................................................................... 211b. Gearing ............................................................................................................................................................ 212c. Linier meningkatkan rasio Gear (dinamis).... 213d. Cam Table ........................................................................................................................................................ 21431. Membuat tabel Cam dengan fungsi blok.... 215a. Overview ......................................................................................................................................................... 215b. Mendefinisikan poin pada tabel Cam.... 215saya.Motion Function Point .................................................................................................................................... 215II. Sample Code: .................................................................................................................................................. 21732. Defining the Cam Table in the PLC .............................................................................................................. 219a. Overview ......................................................................................................................................................... 219b. MC_CAM_REF ................................................................................................................................................. 219saya.Contoh 1: Posisi keterangan struktur tabel.... 219II. Contoh 2: Struktur Deskripsi fungsi gerak.... 220c. MC_TableType ................................................................................................................................................ 221saya. Sample Code: .................................................................................................................................................. 22133. Creating the Cam Table ............................................................................................................................... 222a. Overview ......................................................................................................................................................... 222b. MC_CamTableSelect ....................................................................................................................................... 222saya. Sample Code: .................................................................................................................................................. 22334. Mengimpor tabel Cam untuk verifikasi.... 224a. Overview ......................................................................................................................................................... 224b. Creating a Blank Table ..................................................................................................................................... 224c. Importing the Cam Table ................................................................................................................................ 22735. Camming the two Axes together ................................................................................................................ 230a. Overview ......................................................................................................................................................... 230

    Multilizer PDF Translator Free version - translation is limited to ~ 3 pages per translation.

    Multilizer PDF Translator Free version - translation is limited to ~ 3 pages per translation.

  • TwinCAT 2 Once the Cam Table has been defined, verified, and created; the two axes are now ready to be cammed together.................................................................................................................................................................................. 230 b. MC_CamIn....................................................................................................................................................... 230 i. Sample Code: .................................................................................................................................................. 232 36. Changing a table point via the PLC .............................................................................................................. 233 a. Overview ......................................................................................................................................................... 233 b. MC_WriteMotionFunctionPoint ..................................................................................................................... 233 c. MC_SetCamOnlineChangeMode .................................................................................................................... 234 d. MC_CamActivationMode ................................................................................................................................ 236 i. Sample Code: .................................................................................................................................................. 237 37. Motion Functions vs. Position Tables ......................................................................................................... 239 a. Position Tables ................................................................................................................................................ 239 b. Motion Functions ............................................................................................................................................ 241 c. Definition of a Point ........................................................................................................................................ 242 d. Point structure ................................................................................................................................................ 242 e. Point types ...................................................................................................................................................... 243 38. Cam Design Tool .......................................................................................................................................... 244 a. Overview ......................................................................................................................................................... 244 b. Creating a Cam Table ...................................................................................................................................... 245 i. Master Tab ...................................................................................................................................................... 250 ii. Slave Tab ......................................................................................................................................................... 251 c. Graphic Window ............................................................................................................................................. 252 d. Tables Window ................................................................................................................................................ 254 i. Function Types ................................................................................................................................................ 255 ii. Commands ...................................................................................................................................................... 256 39. Cam Table Scaling ....................................................................................................................................... 258 a. Overview ......................................................................................................................................................... 258 b. MC_CamScaling............................................................................................................................................... 258 c. MC_CamScalingMode ..................................................................................................................................... 260 i. Example: .......................................................................................................................................................... 261 ii. Sample Code: .................................................................................................................................................. 263 40. Cyclic Cam Plates with Lift........................................................................................................................... 264 a. MC_StartMode ................................................................................................................................................ 266 41. Cam Out and Restarting .............................................................................................................................. 268

  • TwinCAT 2 a. Overview ......................................................................................................................................................... 268 b. MC_CamOut.................................................................................................................................................... 269 c. MC_Halt .......................................................................................................................................................... 270 42. MC_CamIn Appendix................................................................................................................................... 272 a. Axis coupling with cam plates ......................................................................................................................... 272 b. Linear cam plates ............................................................................................................................................ 273 c. Cyclic cam plates without lift .......................................................................................................................... 274 d. Cyclic cam plates with lift ................................................................................................................................ 275 e. Uncoupling and re-coupling for cyclic cam plates with lift ............................................................................. 276 43. Diagnostics .................................................................................................................................................. 277 a. Overview ......................................................................................................................................................... 277 b. Error Format .................................................................................................................................................... 277 Error Groups ............................................................................................................................................................ 278 c. Global Error Codes 0x0000.............................................................................................................................. 278 d. General ADS Error Codes 0x0700 .................................................................................................................... 278 e. NC Errors 0x4000 ............................................................................................................................................ 279 f. General NC Errors 0x40nn ............................................................................................................................... 279 Group Errors 0x42nn............................................................................................................................................... 280 g. Table Errors 0x4Ann ........................................................................................................................................ 281

    VII. Remote Connections .................................................................................................................................................... 282 44. Embedded Controllers ................................................................................................................................ 282

    VIII.Appendix I Variable Naming Convention ................................................................................................................... 294 45. Scope ........................................................................................................................................................... 294 46. Programming System Settings .................................................................................................................... 294 a. Font ................................................................................................................................................................. 294 b. Tab Width........................................................................................................................................................ 294 47. Naming ........................................................................................................................................................ 295 a. General............................................................................................................................................................ 295 b. Case Sensitivity ................................................................................................................................................ 295 c. Valid Characters .............................................................................................................................................. 295 d. Prefix Types ..................................................................................................................................................... 295 e. Scope Prefix ..................................................................................................................................................... 297 f. Type Prefix ....................................................................................................................................................... 298 g. Property Prefix ................................................................................................................................................ 299

  • TwinCAT 2 h. POU Prefix ....................................................................................................................................................... 300 i. Structures ........................................................................................................................................................ 301 j. List Types ......................................................................................................................................................... 302 k. Libraries ........................................................................................................................................................... 303 48. Good Programming Practices ..................................................................................................................... 304 a. Comments ....................................................................................................................................................... 304 b. Array Indexing ................................................................................................................................................. 304 c. Program Calls .................................................................................................................................................. 304

  • TwinCAT 2

    I. TwinCAT Overview

    1. OverviewThe Windows Control and Automation Technology

    The Beckhoff TwinCAT software system turns any compatible PC into a real-time controller with a multi-PLC system, NC axis control, programming environment and operating station. TwinCAT replaces conventional PLC and NC/CNC controllers as well as operating devices with:

    open, compatible PC hardware

    embedded IEC 61131-3 software PLC, software NC and software CNC in Windows NT/2000/XP/Vista, Windows 7, NT/XP Embedded, CE

    programming and run-time systems optionally together on one PC or separated

    connection to all common fieldbuses

    PC interface support

    data communication with user interfaces and other programs by means of open Microsoft standards (OPC, OCX, DLL, etc.)

    Architecture

    TwinCAT consists of run-time systems that execute control programs in real-time and the development environments for programming, diagnostics and configuration. Any Windows programs; for instance, visualization programs or MS Office programs, can access TwinCAT data via Microsoft interfaces, or can execute commands.

    A practical oriented software solution

    TwinCAT offers a precise time base in which programs are executed with the highest deterministic features, independently of other processor tasks. The real-time load on a PC is set with TwinCAT; defined operating behavior is achieved in this way. TwinCAT indicates the system load for programs that are running. A load threshold can be set in order to assure a defined computing capacity for the operating programs and for Windows NT/2000/XP/Vista. If this threshold is exceeded, a system message is generated.

    TwinCAT supports system diagnosis

    The general use of hardware and software from the open PC world requires some checking: Unsuitable components can upset the PC system. Beckhoff has integrated a practical indicator of the real-time jitter, giving administrators an easy way to evaluate the hardware and software. A system message during operation can draw attention to incorrect states.

  • TwinCAT 2

    Start/Stop behavior

    Depending on the setting, TwinCAT is started and stopped manually or automatically. Since TwinCAT is integrated into Windows NT/2000/XP/Vista and Windows 7as a service, an operator is not needed to start the system: switching on is enough.

    Restarting and data backup

    When a program is started or restarted, TwinCAT loads programs and remnant data. To back up data and to shut down Windows NT/2000/XP/Vista and Windows 7 correctly, a UPS (uninterruptible power supply) is of great value.

    World-wide connection through message routing remote connection is inherent to the system

    According to the requirement for operating resources, the TwinCAT software devices can be distributed: TwinCAT PLC programs can run on the PCs or on Beckhoff Bus Terminal Controllers. A message router manages and distributes all the messages, both in the system and via TCP/IP connections. PC systems can be connected with each other via TCP/IP; Bus Terminal Controllers are integrated via serial interfaces and fieldbuses (EtherCAT, Lightbus, PROFIBUS DP, CANopen, RS232, RS485, Ethernet TCP/IP).

    World-wide access

    Since standard TCP/IP services of NT/2000/XP/Vista/CE and Windows 7 can be used, this data can be exchanged across the world. The system offers scalable communication capacity and timeout periods for the supervision of communications. OPC provides a standardized means for accessing many different SCADA/MES/ERP packets.

    PLC and Motion Control on the PC

    TwinCAT I/O universal I/O interface for all common fieldbuses

    Many PC fieldbus cards from various manufacturers are supported. It is possible to operate more than one fieldbus card per PC. Master and slave functionality is supported, depending on the selected fieldbus card. The fieldbus cards can be configured and diagnosed conveniently via the TwinCAT System Manager. TwinCAT I/O includes the TwinCAT real-time system for operating the fieldbuses and a DLL interface to application programs.

  • TwinCAT 2

    TwinCAT PLC the central pillar of automation software

    Conceived as a pure software PLC, TwinCAT PLC allows up to four virtual PLC CPUs, each running up to fouruser tasks, on one PC. The PLC program can be written in one or more of the languages provided for in the IEC 61131-3 standard:

    IL (Instruction List),

    LD (Ladder Diagram),

    FBD/CFC (Function Block Diagram),

    SFC (Sequential Function Chart) and

    ST (Structured Text).

    TwinCAT PLC running under the Windows NT/2000/XP/Vista operating systems includes both the programming environment and the run-time system, so that an additional programming device is not required. ander the CE operating system and the embedded operating systems for the series BX and BC controllers, only TwinCAT run-time is available. Program modifications are implemented via network-capable powerful communication with the run-time system. Programming can be done

    locally,

    via TCP/IP or

    via the fieldbus (BXxxxx and BCxxxx).

    IEC 61131-3 advanced programming standard for all Beckhoff controllers

    The TwinCAT PLC is programmed in accordance with IEC 61131-3 independently of the manufacturer. TwinCAT supports all the IEC 61131-3 programming languages with convenient editors and a fast, effective compiler, so that the development cycle for the creation even of large PLC programs of several megabytes can be short. Incremental compilation prevents long turnaroand times. Only genuinely new sections are compiled. Powerful editor features, such as autoformat, autodeclare or find and replace enable fast programming. For all programming languages, the project comparison function facilitates differences to be identified and accepted if appropriate. If a project (comments, directories, etc.) is to be translated into a language other than the original language, all terms can be exported into a table, translated and re-imported. If a team is dealing with the development, all objects (blocks, data types, lists) can be managed within a source code management tool via the TwinCAT Engineering Interface. This enables changes to be traced back and differences between individual versions to be displayed.

    The concept of the instantiation of function blocks, in which each instance is associated with its own data, leads naturally to object-oriented and structured programming styles. All common data types specified in IEC 61131-3 are supported. Multi-dimensional fields and structures are possible, as are enumeration and subrange types.

  • TwinCAT 2 TwinCAT PLC is certified for the languages IL and ST (base level). The online change function can be used for

    code and/or data modifications while the PLC is running, providing maximum data retention. Source code can be stored in the target system (except for BCxxxx series controllers). The criteria analysis function is very helpful for the detection of process errors.

    Code can very easily be reused via the convenient library manager. For know-how protection, multi-stage password protection can be applied to programs and libraries.

    Many target platforms one tool

    The PLC programs created with TwinCAT PLC can be executed on a number of target platforms. Apart from Industrial PCs and the Embedded PCs, the PLC project can also be loaded into the BC and BX series fieldbus controllers from Beckhoff. Program development and debugging proceed in the same working environment, regardless of which unit is executing the program.

    Extensive supplementary libraries

    As an extension to the blocks defined by the IEC language standard, Beckhoff offers a wide range of supplementary libraries for the execution of tasks typical in automation technology: e.g. libraries for controlling electrical and hydraulic axes via TwinCAT NC, serial communication libraries, system libraries for message outputs, write/read files, control technology blocks, etc.

    Helpful practice tools

    Extensive fault finding functions in TwinCAT PLC facilitate the solution of problems either on site or via remote maintenance. For this purpose, the PLC programming environment in TwinCAT offers:

    Online Monitoring

    Power Flow (flow control)

    Break Points

    Sampling trace of PLC variables

    Single step

    Watchlist

    Call hierarchy

    Forcing of variables.

    In addition, the TwinCAT ScopeView (a software oscilloscope) can be used to record one or several variables simultaneously.

  • TwinCAT 2

    TwinCAT NC Motion Control on the PC

    A software NC consists of:

    positioning (set value generation and position control)

    integrated PLC with NC interface

    operating programs for commissioning purposes

    I/O connection for axes via fieldbus

    With TwinCAT NC, the position controller is calculated on the PC processor as standard. It exchanges data cyclically with drives and measurement systems via the fieldbus.

    Central NC positioning on the PC

    The computing capacity of a PC enables axis motion simultaneously with the PLC, whereby the position controller is usually calculated on the PC: The computing capacity of a PC enables many axes to be positioned simultaneously.

    TwinCAT enables a PC to process the operating programs, the PLC and the NC at the same time. The division of the system load is supported by TwinCAT with appropriate functions.

    Analytical path calculation

    The algorithms that TwinCAT NC/NC I/CNC uses to control axes take account of the dynamic parameters of the axis: speed, acceleration and jerk. In this way, the axes are moved at any time within the limits of what is dynamically possible, and are precisely analytically coordinated. A range of different regulation algorithms are available in order to reduce the deviations from the ideal trajectory that will occur in practice.

    Individual or joint

    Based on the normal methods for positioning an individual electrical axis, moving from its starting point to its destination (point-to-point positioning), TwinCAT NC also allows the coordinated movement of a number of axes in multi-stage master-slave operation (e.g. gearing functions or cam plates) to be executed. TwinCAT NC I further allows the interpolated path sequencing described in accordance with DIN 66025 to be carried out involving up to three axes.

    Software PLC included

    TwinCAT combines software NC and software PLC to form a powerful controller. The communication between the two packages is a pure software/software channel with minimum delay times. The NC functionalities are called from the PLC program via standardized, PLCopen-certified function blocks.

    Axis movements can be simulated without hardware; the actual value is instructed to ideally track the set value, and the complete machine flow is checked. TwinCAT ScopeView is helpful for commissioning and maintenance. It records all axis variables such as position, speed, acceleration and jerk.

  • TwinCAT 2

    Convenient commissioning

    Commissioning is simplified significantly by the configuration and diagnostic dialogs offered in the TwinCAT System Manager. For each axis, all main data are displayed at a glance. The axes can be moved via function keys. Special functions such as couplings, cam plates or distance compensation can be triggered and observed via the System Manager. A convenient dialog enables the dynamic parameters of an axis to be determined.

    TwinCAT NC I axis interpolation in three dimensions

    TwinCAT NC I (interpolation) is the NC system for linear and circular interpolated path movements of axis groups each involving two or three drives. The system includes interpreter, set value generation and position controller. PLC functionality is integrated, as is the connection of the axes with the fieldbus.

    The interpreter interprets the code described in DIN 66025. Comprehensive PLC libraries enable interaction between NC and PLC. NC programs, for example, can be loaded directly from the PLC program into the interpreter.

    TwinCAT CNC the software CNC for toughest requirements

    TwinCAT CNC expands TwinCAT NC I with classic CNC features: Up to 32 interpolating axes and comprehensive coordinate and kinematic transformations are possible. Parts programming is carried out according to DIN 66025 using high-level language extensions. TwinCAT CNC can operate with up to 64 axes or 32 path axes and controlled spindles that can be distributed across up to twelve CNC channels. In a CNC channel, up to 32 axes can be interpolated simultaneously, enabling even the most difficult motion tasks to be solved.

  • TwinCAT 2

    2. System Service

    The TwinCAT System Service is represented by the TwinCAT icon in the Windows system tray.

    The TwinCAT System Service can be accessed through the TwinCAT icon in the windows system tray (Right-Click and Left-Click provides the same menu)

    From this menu the other parts of the TwinCAT system can be accessed and the TwinCAT System Properties can be changed

  • TwinCAT 2

    The General tab of the system properties provides the version number and registration information of TwinCAT

    Note that the 30 day counter has started and the Reg. Key is empty

  • TwinCAT 2 The upper half of the System Tab shows which TwinCAT servers are installed

    The lower half provides settings for how TwinCAT will act when windows boots up

    Auto Boot:

    Disable The TwinCAT System Service will boot in Stop Mode

    Enable The TwinCAT System Service will boot in Run Mode

    This would be the preferred setting on a running machine

    Config Mode The TwinCAT System Service will boot in Config Mode

    ADS services are running, remote communication is possible

    Auto Logon:

    Enabling this option and providing a User Name and Password will allow for the Windows Logon screen to be bypassed, this is ideal for a running machine but not for a development laptop as this information is stored in plain text in the windows registry.

    Note: See the security section for protecting the windows registry.

  • TwinCAT 2

    AMS Router Automation Machine Specification

    AMS Router Automation Machine Specification

    The AMS Router is the communication router for TwinCAT

    Every piece of information that travels from one piece of software to another must go through the AMS Router

    AMS NetID xxx.xxx.xxx.xxx.1.1

    The address of the local TwinCAT Service

    Every address on the network should be unique

    The default address is generated by the IP address of the network card with an additional .1.1 added to the end

    The first four octets of the address can be changed to any number between 0 and 255. They do not have to match the IP address

    The last two octets should not be changed as .1.1 represents the external address and other values are used internally

  • TwinCAT 2

    Remote Computers

    The lower section provides a list of remote computers than have been previously configured for AMS communication

    Remote Computers can be manually added or removed from here

    The list of computers is loaded when TwinCAT enters either Config or Run mode, therefore if a computer is added or removed from here, TwinCAT must be restarted to update the list of Target Computers in the System Manager

  • TwinCAT 2

    PLC

    Up to 4 PLC Run-Times can be configured

    The path of the Boot Project can be changed

    The selection to enable the Boot Project and Retain Data can be made

  • TwinCAT 2

    Registration

    The System ID is needed for licensing

    It is advised that on a running machine the customer should record the System ID and Registration Key. In the event of a Hard Disk failure these two numbers and the new System ID can be used to generate a new Registration Key Otherwise the original PO is needed to generate a new Registration Key

  • TwinCAT 2

    The System Manager and PLC Control can be also be accessed through this menu or the Windows Start menu

    Additionally the local TwinCAT System can be placed into its different modes

    Stop Mode

    The system is not capable of communication and no services are running

    Config Mode

    The ADS Router is running and communication is possible

    Scanning of hardware is done is this mode only

    I/O values are updated at the hardware level

    Run Mode (Requires License beyond 30 Trial)

    All services are enabled and running if configured to do so (i.e. Boot Project)

  • TwinCAT 2

    3. System Manager The TwinCAT System Manager is used to configure the links between Hardware and Software

    I/O Configuration All Fieldbus Hardware

    PLC Configuration PLC Run-Times (up to 4)

    NC Configuration Axes (real and virtual), Cam Tables, Interpolation Channels

    System Configuration Properties of the Target System and Real-Time Usage

  • TwinCAT 2 Menus and Controls

    File Menu Allows for Creating a new file or opening a saved file.

    Additionally provides a way to open the CurrentConfig.tsm file from the Boot folder, by using Open from Target also referred to as The Red Folder.

  • TwinCAT 2 Actions Any time a change is made to the System Manager, the Activate Configuration must be done to

    implement this change into the running system.

    Note: The first 6 commands in the Actions menu will be sent to the Target system either local or remote.

  • TwinCAT 2 The tree view on the left provides access to the configurations of the system manager. When an item on the left is selected its information will be displayed on the right. Items can be added to the System Manager be Right-Clicking on an existing item. Become familiar with this, almost every item you wish to add in both the system manager and the PLC will be done by Right-Clicking and select Add.. or Append

    System Configuration Provides information and settings for the overall TwinCAT System

    The settings available from the Properties of the TwinCAT icon can be accessed from here on a remote system.

  • TwinCAT 2 General The TwinCAT version is provided here in bold

    The Choose Target button can be used to access a remote TwinCAT system.

  • TwinCAT 2 Boot Settings can be used to set the TwinCAT Mode on startup and the Auto Logon

    When pointed to a remote system these setting will be applied to the remote system. The Apply button must be used, and an Administrator level user name and password must be provided.

  • TwinCAT 2 Real-Time Settings

    Settings Here the Base Time is set; no task can be set to a faster interval than the base time.

    The CPU limit of 80% means that TwinCAT will consume no more than 80% to run all of its tasks.

  • TwinCAT 2 Online The Real Time Usage is graphed and the limit from the Settings tab is indicated by the thick green line

    System Latency should be no more than 5 micro seconds

    Note: Image taken from a laptop with power save features and CPU throttling enabled, both of these create latency problems.

  • TwinCAT 2 Priorities The list of tasks and their priorities can be seen here

    Additional Tasks

  • TwinCAT 2

    Task 1 (added by Right-Clicking on Additional Tasks)

    These additional tasks are used by C++ code to talk to variables that are linked to hardware I/O

    They can also be used for simulation

    When used for simulation the Auto start must be checked

  • TwinCAT 2

    Route Settings

    Current Routes The Remote Computers shown in this list are the same as in the Properties of the TwinCAT icon.

  • TwinCAT 2

    NC Configuration (Numerical Control) This is the software based motion controller of TwinCAT. The software side of all axes are configured here.

    Axes The software limits the total number of axes to 255, the real limit is the amount of CPU and RAM in the computer.

  • TwinCAT 2

    The Online tab provides an overview of the status of all axes

  • TwinCAT 2

    Axes 1 Online

    The Online tab of each axis provides a useful interface to setup and troubleshoot an axis

  • TwinCAT 2

    PLC Configuration

    IEC Project The PLC editor will create a tpy file that contains addressed variables that can be linked to hardware. The name of the PLC project file is shown directly below the PLC-Configuration

    The IEC1131 Tab shows the path of where the tpy file was located when it was added to the project. If addressed variables are added to the PLC program the ReScan button can be used to update the list of variables in the System Manager

  • TwinCAT 2

    Standard Task The default task in the PLC is the Standard task and runs every 10ms

    Inputs of the PLC Program Input variables have a yellow icon, Output variables have a red icon

  • TwinCAT 2

    Once a variable has been linked (connected) to hardware the icon changes as below

  • TwinCAT 2

    4. PLC Control The PLC Control provides the user with a combination of tools.

    The IEC 61131-3 Language editors

    A Visualization Editor

    Task Configuration Utility

    The Beckhoff Compilers specific to the Target Hardware (BC, BX, CX-ARM, X86)

  • TwinCAT 2

    II. TwinCAT Software Installation

    5. TwinCAT VersionsThere are several builds within each version

    New builds are released primarily to accommodate new hardware

    New versions are released when features are added

    A Brief History

    TwinCAT 2.6 Build 315 August 2, 1999

    TwinCAT 2.7

    TwinCAT 2.8

    Change from wsm to tsm

    Use of XML for system configuration

    Config Mode for scanning hardware

    TwinCAT 2.9

    TwinCAT 2.10

    TcMC2.lib

    TwinCAT 2.11 Build 1552

    TwinCAT 2.11 R2

    Change in preparation for TwinCAT 3

    Required for CX5000

    TwinCAT 2.11 R3

    Release Notes:

    Changes from 2.10 to 2.11TwinCAT Base System

    Integration of MDP (Modular Device Profile a generic interface for device information) Integration of configuration tool for AX5xxx drives Optimized behavior for use with Windows Vista and Windows 7 Optimization for TwinCAT running on Quad-core and Octo-core CPUs Time synchronization with EL6692 (EtherCAT bridge) Time synchronization with EL6688 (IEEE 1588/Precision Time Protocol) New modular structure of I/O drivers Base for new supplement products like TwinCAT Kinematic Transformation

  • TwinCAT 2

    In addition to the features available in 2.11, the following new features were implemented in Release 2 (2.11 R2):

    support for CX50xx controllers support for CU2508 (port multiplier) support for AX5805 (safety card for AX5xxx) support for EP1908 new Motion Control feature: multi-cam extended slave error handling for NC multi-linear coupling (multi-GearIn)

    In addition to the features available in 2.11 R2, the following new features were implemented in Release 3 (2.11 R3):

    CX50xx, additional interfaces like EtherCAT Slave EL7201 support (NC PTP) Supports new PCIe fieldbus adapters New Phasing functionality for NC PTP

  • TwinCAT 2

    6. Software, Download & Installation The TwinCAT software can be downloaded from www.beckhoff.com Select Download from the top of the page

    Scroll down to the Software section and select TwinCAT 30 days version

  • TwinCAT 2 Select TwinCAT

  • TwinCAT 2 The form must be filled in with a valid email address

    Below the form you can select the version and build of TwinCAT you would like to download

    After selecting the Registration button an email will be sent; to the address provided, containing a link to download the software

  • TwinCAT 2

    Selecting the link in the email will start the download

    Double-Click the exe file to start the installation process

    The file name will match the version number and build that you selected during the registration process

    If you receive the following warning select Run

  • TwinCAT 2 Select your preferred language and then select next

    The InstallShield Wizard will begin the install process

  • TwinCAT 2 When prompted select next

    Accept the license agreement and select next

  • TwinCAT 2 Fill in the User Name and Company Name (This information will be viewable in the software)

    Use DEMO for the serial number

  • TwinCAT 2 Selecting the level of TwinCAT to install (All levels are inclusive of lower levels)

    CP Includes the ADS driver, used for OPC Server, Beckhoff Control Panels, and other ADS communication

    I/O Includes the system manager for configuring hardware, used when writing C/C++ code to control the I/O

    PLC Includes the IEC 61131-3 PLC editor and the Beckhoff compilers

    NC PTP Numerical Control for Point to Point motion with associated libraries

    NC I Numerical Control for Interpolated motion with associated libraries

  • TwinCAT 2 Registration Type

    30 Day demo Full functionality for 30 days, after 30 days TwinCAT will no longer go into run mode. Development and Remote connections are still possible. Re-installing will provide another 30 days

    Register now A System ID will be provided for you to call in with

    The recommended practice is to select the 30 Demo and then send screenshots of the System ID via email. Licenses can be provided within 24 hours except weekends and holidays

  • TwinCAT 2 Select the additional features to install with TwinCAT

    The desired features should be selected here, afterwards select Next to continue

    TwinCAT I/O Allows the direct access to IO via a DLL. Can be installed with TwinCAT PLC or TwinCAT NC PTP.

    TwinCAT Scope View A software Oscilloscope for monitoring variables in real time

    TwinCAT Cam Server A Cam tool for setting outputs on Lightbus, has never been sold in North America, replaced by newer technology

    TwinCAT EDS and GSD files files for DeviceNet and Profibus hardware

    TwinCAT Remote Manager For managing different versions of TwinCAT on one PC.

    TwinCAT Drive Manager Used for Configuring the AX5000 servo drives

    TwinCAT BACnet/IP BACnet Server for building Automation and HVAC systems.

  • TwinCAT 2 Specify the path for the TwinCAT installation

    The default path is highly recommended, project files that the user creates can be stored in any desired location

  • TwinCAT 2 Specify the Program Folder for the TwinCAT installation

    The default path is highly recommended, project files that the user creates can be stored in any desired location

    The installer will now install the needed components

  • TwinCAT 2 You must reboot the PC after the installer has completed

    After rebooting the PC you will see the TwinCAT icon in the Windows System Tray

    TwinCAT is in Stop Mode by default

  • TwinCAT 2

    7. Licensing and Registration

    Single left click the TwinCAT Icon in the system tray, and select properties

    Once properties is selected the TwinCAT System Properties window will appear. Select the last tab (Registration) on the top of the window. At this point you can take a screen capture of the current System ID and report it to your Inside Sales Representative.

  • TwinCAT 2

  • TwinCAT 2

    III. PLC Overview

    8. IDE The Integrated Development Environment (IDE) of TwinCAT provides a complete set of development tools for

    the PLC. TwinCAT PLC Control puts a simple approach to the powerful IEC languages at the disposal of the PLC programmer. Use of the editors and debugging functions is based upon the proven development program environments of advanced programming languages.

    The Left column provides four tabs at the bottom.

    POUs Program Organizational Units This will contain the code written by the programmer, Programs, Function Blocks, and Functions

  • TwinCAT 2 Data Types Here the programmer can create Structures and Enumerations to be used in the PLC code

    Visualizations Interface screens for use by Maintenance personnel or Operators can be created.

    Resources The resources tab contains several items. The Global Variable Lists, Library Manager, PLC Configuration, and Task Configuration are all accessible from this tab.

  • TwinCAT 2 A POU is opened by double-clicking on it.

    The POU contains 2 parts, the Declaration section, and the Code section. The first line of the declaration section defines the type of POU and the name of the POU. Following this is the local variable declaration, the variables that are local to this POU are defined between the Keywords VAR and END_VAR. Below the Declaration section is the Code section, this part of the window will contain the PLC code of the POU.

  • TwinCAT 2 Additionally there is a Message Window at the bottom.

    The Message Window can be hidden or shown, from the Window menu select Messages or the keyboard shortcut Ctrl + K

    The Message window will show Errors, Warnings, and compile information.

  • TwinCAT 2

    9. ProgramsA program is a POU which returns several values during operation. Programs are recognized globally throughout the project. All values are retained from the last time the program was run until the next. Programs are called from either a PLC Task or another Program. If a one program calls another program, and if thereby values of the program are changed, then these changes are retained the next time the program is called, even if the program has been called from within a different program.

    Programs can call all types of POUs, they can call Functions, Function Blocks, and other Programs. By default when a new Project is started, a Standard Task is created that calls the Program MAIN, from MAIN all other POUs are called. Because Programs are recognized globally, the local variables declared inside of them will referenced by first using the name of the program and then the name of the variable, separated by a dot ., for example is the variable bStart is defined with an address as a local variable in MAIN, in the PLC-Configuration of the TwinCAT System Manager the variable will be MAIN.bStart. Where as a variable defined globally will only show the name of the variable.

  • TwinCAT 2

    10. Data Types and Conversions

    Elementary data types form the foundation of the programmers tools to represent and use information. The elementary data types within TwinCAT Plc Control are below.

    The BOOL data type is used to define a Boolean or Bit-wise variable. The BOOL data type takes the value of either TRUE or FALSE at runtime. The conversion operator BOOL_TO_INT may be used to convert a TRUE/FALSE into 1/0, respectively.

    Declaration syntax: VariableName : BOOL := InitialValue ;

    Example: pushButton01 : BOOL ;

    Declaration with Initial Value: drainValveOpen : BOOL := TRUE ;

  • TwinCAT 2

    Use the {BYTE, WORD, DWORD, SINT, USINT, INT, UINT, REAL, LREAL} data set is to definean appropriate value range for a variable.

    Declaration syntax: VariableName : DataType { :=

  • TwinCAT 2

    The function returns the arguments value as the desired, converted data type. The general scheme is defined as DataType1_TO_DataType2 ( VariableToConvert ) Where DataType1 is the data type of the variable being converted and DataType2 is the desired data type. For example, the code snippet converts MyWordVariable from WORD to INT (integer).

    WORD_TO_INT(MyWordVariable)

    The variable, MyReturnedInt, is assigned to this converted value.MyReturnedInt := WORD_TO_INT(MyWordVariable) ;

  • TwinCAT 2

    11. Variables

    A Variable is a name given to a location in memory that stores a value

    A Variable has up to 5 properties

    1. Name

    2. Size (Defined by the Type)

    3. Value

    4. Memory Location

    5. PLC Address

    In accordance with IEC 61131-3 a variable name must adhere to the following rules

    1. Must begin with a Letter or an Underscore

    2. Can followed by Letters, Underscores, or Numbers

    No distinction is made between Uppercase and Lowercase Letters

    Special characters cannot be used (!@#$%^&*)

    Blanks or Spaces are not allowed

    Repeated or Sequential Underscores are not allowed

    Descriptive abbreviations aid in understanding the value that is held by the variable

  • TwinCAT 2 The use of abbreviated data types in the name of the variable help in the understanding of what the variable is. By placing a lower case b in front of all BOOLEAN variables the person reading the program will know that this variable is of type BOOL without having to refer to the variables declaration. Additionally using a Capital letter at the beginning of each word in the variable name will aid in understanding

    For example:

    bStartConveyor is much easier to read and understand than bstartconveyor

    Declaration

    All variables must be defined between VAR and END_VAR

    Place the name of the variable to the left of the colon

    Place the data type to the right of the colon

    VariableName : VariableType ;

    bStart : BOOL ; (*bStart is of type BOOL*)

    iProductNumber : INT; (*iProduct Number is of type INT*)

    lrPressure : LREAL ; (*lrPressure is of type LREAL*)

    Variable Scope

    Global Variables can be read and written to from anywhere in the PLC program

    Local Variables can only be written to from within the POU where they are defined

    The local variable of any POU can be read by first accessing the POU instance that the variable is defined in and then using the . to access the local variables defined within that POU

    Local variables cannot be written to from another POU

    Initial Values

    All Variables have the option of assigning an initial value

    This value will be written to memory when the PLC starts, after which the code of the PLC will control the value

    bStart : BOOL := FALSE ; (*bStart is of type BOOL and has an initial value of FALSE*)

    iProductNumber : INT := 1 ; (*iProduct Number is of type INT and has an initial value of 1*)

    lrPressure : LREAL := 2.3 ; (*lrPressure is of type LREAL and has an initial value of 2.3*)

    It is also possible to assign an initial value to a variable in an instance of a function block

    fbTON1 : TON := (PT := T#1s) ; (*fbTON1 is of type TON and the PT input has an initial value of 1 second*)

  • TwinCAT 2 Constants

    Variables defined as Constants cannot be written to by the PLC

    Constants are declared similar to initial values

    Use of the keyword Constant at the beginning of the declaration section signals the compiler that the variable is a constant.

    Remnant Variables

    Remnant variables can retain their value throughout the usual program run period. These include Retain variables and Persistent variables.

    Retained Data

    These variables maintain their value even after an uncontrolled shutdown of the controller as well as after a normal switching off and on of the controller or at the command 'Online', 'Reset. When the program is run again, the stored values will be processed further. A concrete example would be a piece-counter in a production line that recommences counting after a power failure. Retain-Variables are reinitialized at a new download of the program unlike persistent variables. Variables stored with RETAIN are initialized after a "Rebuild all" of the PLC program. With a Reset all RETAIN variables are initialized.

    Persistent Data

    These variables are stored with the complete symbol. Therefore symbol generation must be selected. Persistent variables conserve their old values after a "Rebuild all" of the PLC program. To initialize the PERSISTENT variables choose Reset all. On a TwinCAT shutdown the persistent variables are written in a special file. This file contains the old values of the persistent variables and is read on a TwinCAT start.

  • TwinCAT 2

  • TwinCAT 2

    12. LanguagesThe IEC 61131-3 specifies 5 languages for writing PLC code. TwinCAT provides these plus 1 extra

    IL Instruction List

    LD Ladder Diagram

    FBD Function Block Diagram

    SFC Sequential Function Chart

    ST Structured Text

    CFC Continuous Function Chart (Non-IEC)

    IL Instruction List

    IL has a similar structure to assembly language and is comparable to the statement list language provided by Siemens.

    In IL only 1 command can be processed per line of code.

    The command is then followed by a variable or a literal value.

    For example the following will increase the variable Speed by a value of 5

  • TwinCAT 2 LD Ladder Diagram

    LD was created with the intention of representing the electrical wiring diagrams of relay logic

    LD is a graphical language that displays a power rail on each side that represents the supply and the common of the wiring diagram

    The below examples shows a common latching circuit in LD

    FBD Function Block Diagram

    FBD is a graphical language that is similar to an electronic circuit diagram

    The below example has the same functionality as the above latching circuit

  • TwinCAT 2

    SFC Sequential Function Chart

    SFC; although defined as a language, is better thought of as a way to organize code and control the sequence of operation

    Each Step and Transition in SFC has code inside of it that can be written in any of the other languages including SFC

  • TwinCAT 2 ST Structured Text

    ST is a high level language which looks similar in syntax to PASCAL

    ST is the most powerful and flexible of all the languages

    When using ST it is important to remember that the variable being written to (the output) is on the left

    The below example provides the same latching circuit operation as the ones above

  • TwinCAT 2 CFC Continuous Function Chart (Non-IEC)

    CFC is an additional language provided within TwinCAT, yet it is not a part of the IEC 61131-3 Standard

    CFC is a graphical language very similar to FBD

    The order of execution is determined by the number, and is able to be modified by the programmer

  • TwinCAT 2

    13. Functions A Function is a re-useable piece of code that will process the defined inputs and return a single result

    AND, OR, SQRT, SIN, COS, GT, LE are all examples of Functions

    The programmer can also create their own Functions that normally involve more complicated tasks, such as converting a temperature value from Celsius to Fahrenheit or scaling an analog input value from 0-32767 to 0-10

    Functions can be called from any other POU type, but are only capable of calling other functions

    Note: Functions have no memory space and therefore they do not retain any values from one PLC scan to the next. Each function starts new each PLC scan.

    Declaration

    The Declaration of a Function contains 4 parts

    The Name of the Function

    The Return type of the Function

    The Variables to be passed into the Function

    The local variables used by the Function

    The Name of the Function

    Following the Beckhoff coding convention, the name of the Function starts with F_

    The same IEC rules for naming of variables apply to the naming of Functions

    Following the Name of the Function is the Return Type

    A Function can only Return one variable

  • TwinCAT 2 The Variables to be passed into the Function

    In the below example iTempInCelsius is the Variable that is being passed into the function

    Code

    The working code of the Function

    Tf := 9/5 * Tc + 32

    In the example code the integer value iTempInCelsius is converted to a real number. This is a Function that is built into TwinCAT

    The literal values of 9 and 5 both have a decimal point to signify them as REAL numbers and not integers.

    Before writing the calculated value to the output the number is converted back to an integer. (Yes, this does cause inaccuracy due to rounding.)

  • TwinCAT 2 Implementation

    iTempC is declared as an INT with an initial value of 100

    iTempF is declared as an INT with no initial value

    In the code the Function F_CtoF is called and iTempC is passed into it.

    The result of the Function is then stored in iTempF.

  • TwinCAT 2

    14. Function Blocks A Function Block is a re-useable piece of code that can have multiple inputs and outputs. Function Blocks are

    instantiated; therefore each time a Function Block is used it must be assigned a unique instance name. Each instance receives its own space in memory and therefore will retain its values from one PLC scan to the next.

    TON, CTU, R_Trig, FB_FileOpen, ADSREAD, are just a few examples of Function Blocks

    The programmer can also create their own Function Blocks to perform a variety of tasks.

    Function Blocks can be called by Programs or other Function Blocks. Function Blocks can all other Function Blocks and Functions.

    Note: It is possible to call a Program from a Function Block. Just because you can doesnt mean you should. TwinCAT provides you with the flexibility to do many things (some good, some not so good), once you understand the inner workings of the software you will understand why doing this can cause problems, all of which must be handled by the programmer.

  • TwinCAT 2 Declaration

    The Declaration of a Function Block contains 4 parts

    The Name of the Function Block

    The Variables to be passed into the Function Block

    The Variables to be passed out of the Function Block

    The Variables that are internal to the Function Block

    The Name of the Function Block

    Following the Beckhoff coding convention, the name of the Function Block starts with FB_

    The same IEC rules for naming of variables apply to the naming of Function Blocks

  • TwinCAT 2 The Variables to be passed into the Function Block

    Below the Enable, Time On, and Time Off values are being passed into the Function Block

    The Variables to be passed out of the Function Block

    Below the Output variable has been added

  • TwinCAT 2 The Variables that are internal to the Function Block

    Below the two timers to be used have been instantiated

    fbTON is of type TON

    fbTOF is of type TOF

  • TwinCAT 2 Code

    The working Code of the Function Block

    Below the two timers are called with their instance name

    The := symbol signifies that a value of the variable is being passed into the FB and the => symbol signifies that a value of the variable is being passed out of the FB

    The IN of fbTON is TRUE if bEnable is TRUE and fbTOF.Q is FALSE

    What is fbTOF.Q?

    Anytime the . symbol is used it signifies that the variable on the right exists inside of the variable on the left.

    Q is an output of a TOF, therefore calling the instance name fbTOF followed by . will allow access to the variables that are declared inside of fbTOF

  • TwinCAT 2

    Also notice that fbTON.Q is passed into fbTOF, this will cause the two timers to toggle based on the values of tTimeOff and tTimeOn

    Finally the output of fbTOF is passed to bPulse. bPulse is the output of FB_Pulse

    This could have been done with the following

    bPulse := fbTOF.Q;

  • TwinCAT 2 Implementation

    fbPulse1 is of type FB_Pulse fbPulse1 is an instance of FB_Pulse

    bSwitch is passed into the bEnable input of fbPulse1

    tTimeOn and tTimeOff are assigned literal values in the proper TIME format

    bPulse is passed out of fbPulse1 into bLight1

    fbPulse2 is a second instance of FB_Pulse. It is coded differently but works exactly the same.

    In the above example of fbPulse2 the input variables are first assigned; followed by a call of the Function Block instance on line 6. This is extremely important to understand; if line 6 was removed from the code then the Function Block would never run. The line of code that calls the instance name and uses the parentheses is the line of code that updates the values inside of the Function Block.

  • TwinCAT 2

    15. Actions Actions are used to organize code. Both Programs and Function Blocks can use Actions (They are not allowed

    with Functions).

    Actions share their local declaration section with the POU they are attached to.

    To add an Action to a POU, right-click on the POU and select Add Action

    The name of the Action must follow the rules of the IEC Standard, the language can be of any type

    In the below example the Program MAIN has four Actions. A_Enable is called from the code of MAIN. The instance of fbMC_Power_Ax1 is called inside of the action A_Enable, but is declared locally in MAIN

  • TwinCAT 2

    16. Structures Structures are used to define elements of a larger item and are commonly referred to as custom data types

    A temperature sensor; for example, is more than just the temperature value

    The status of the Analog input card, the scaling parameters, and the offset are all possible elements that are directly related to the temperature sensor

    In order to keep these elements together and make the code more re-useable a structure of these elements can be created

    Declaration

    The structure is created with its element names and data types

    Initial values can be given

    A structure can also contain other structures

  • TwinCAT 2 Implementation

    A structure must be instantiated just like a Function Block

    After typing the instance name of the structure place a . immediately after it and the intelli-sense window will appear, showing what elements exist inside of the structure

    The elements in a structure can be written to and/or read from

  • TwinCAT 2

    17. Enumerations

    Enumerations can be used to assign a variable name to a number.

    Enumerations can be used in two different ways; with or without being instantiated.

    If the Enumeration is not instantiated then the Enumeration works similar to a list of constants.

    If the Enumeration is instantiated then the instance of the enumeration will hold the variable of the current value of the Enumeration

    When the Enumeration is defined the first variable in the list will be assigned a value of 0, the variables following will be assigned their values in ascending order

    Manual = 0

    Semi_Auto = 1

    Auto = 2

    If a variable in the list is explicitly assigned a value then the following variables will be incremented from this value

    Manual = 1

    Semi_Auto = 2

    Auto = 3

  • TwinCAT 2 Manual = 1

    Semi_Auto = 2

    Auto = 3

    Maintenance = 10

    Unknown = 11

    Using Enumerations in this manner allows for easier understanding of the code when it is being read

    In this Case statement the Variables in the Enumeration are used to represent the number equivalent of iStep1.

    As iStep1 changes in value the Case statement will change states

    iStep1 can be assigned a numerical value or an Enumeration variable

    The displayed online value of iStep1 will always be an INT value because iStep1 is declared as an INT

  • TwinCAT 2

    If an instance of the Enumeration is declared then the instance of the Enumeration holds the variable name of the value of the Enumeration

    If iStep2 is of type E_Mode then iStep2 holds either Manual, Semi_Auto, or Auto

  • TwinCAT 2

    18. Arrays An Array is a list of data, the data in the Array can be of any type

    An Array can contain more than one dimension

    Think of a Notebook of graph paper

    The column on a single sheet of paper would be a 1 dimensional array

    The entire sheet with its rows and columns would be a 2 dimensional array

    The Notebook with all of its sheets would be a 3 dimensional array

    1 Dimensional Array

    The Array is defined from 1 to 10 of type INT

    This Array will hold 10 integer values

    The position in the Array is referred to as the index

    The Array name along with an index can be used just like any other variable

  • TwinCAT 2 2 Dimensional Array

    The Array is defined from 1 to 10 and 1 to 3 of type String

    This Array will hold 30 (3*10) String values

    The comma , is used to denote the multiple dimensions of the array

    3 Dimensional Array

    Initializing each index of an array

  • TwinCAT 2 Initializing multiple indexes with the same value

    2(3) indicates that the first 2 Indexes will be given a value of 3

    The above 2 examples can be mixed together

    Indexing through an Array with a FOR loop

    A FOR loop can be used to easily fill an Array or read the values in an array

    The following will set all values in the Array to 0

  • TwinCAT 2

    19. Boot Project The TwinCAT Boot Project is used on a production machine as the PLC code to be run when TwinCAT starts.

    The Boot Project must be enabled and also created.

    Enabling

    Enabling the Boot Project is done through the TwinCAT System Service

    Right Click on the TwinCAT icon in the Windows system tray and select properties

    Click on the PLC tab and place a check mark in the Run-Time

    Creation

    To create the Boot Project: login with the PLC and select Create Boot Project from the Online menu

  • TwinCAT 2

  • TwinCAT 2

    20. Source code Download The use of the Source Code Download allows for a copy of the code to be placed on the device.

    This copy of the code can be opened later either directly on the PC or through a remote connection.

    To create the Source Code Download file you must be logged in to the PLC

    From the Online menu select Sourcecode Download

    The Source Code file will be created in the C:\TwinCAT\Boot folder

    The name of the file will be TCPLC_S_x.wbp where x will be a number from 1 to 4 which represents the runtime number.

  • TwinCAT 2

    To open the Source Code Download file, Select Open from the File Menu

    On the Open file dialog select the PLC button

    Select the correct Target System Type

  • TwinCAT 2

    Select the Run-Time on the Target

    The files will be copied in to your local Upload folder

    C:\TwinCAT\PLC\Upload

    If any of the files already exist you will be asked if you would to overwrite these files

    The code will then open

  • TwinCAT 2

    If the source code download has not been performed you will get the following error message

  • TwinCAT 2

    IV. PLC Programming The Inspection Conveyor

    21. Machine Control with Top-Down Programming

    Intro

    This section is going to cover the design and programming of a modular conveyor. With each module a new concept and/or topic will be introduced. As the saying goes Prior proper planning, prevents poor performance. With that in mind the first topic will cover the overall machine control and the use of a state machine for automatic or manual operation. The first conveyor module will be for adding product to the system using only digital Input and Outputs. The second module will use an analog input to measure the size of the product. Next an analog output will be added to control the conveyor speed using a Variable Frequency Drive (VFD).

    Machine Control/State Machine

    There are many ways to do overall machine control and to implement a state machine, both of which are outside the scope of this document. For the purpose of this document I have chosen to use a state machine that best serves the purpose of learning to use the TwinCAT software. The overall machine control will be handled in a CASE statement. The machine will have the following States:

    Undefined: When no State is defined by the PLC this will be the default State. This state is not allowed to be set by the operator. This State will be used when the machine is first powered on and when a problem in the PLC code occurs.

    Maintenance: Used for making adjustments to the machine or for troubleshooting individual components. Operations will be allowed in this mode that could be harmful to the equipment. Access to this mode will be restricted.

    Manual: Used to start up the machine and prepare for operation, or to shut down the machine after Automatic operation. Requires operator intervention for all functions of the machine.

    Automatic: Used for routine production. The machine will process product based on the conditions of the I/O with minimal operator intervention.

  • TwinCAT 2 Modular Conveyor System

    Each conveyor module will need to work as a standalone piece and also in conjunction with other modules in front of and/or after it. Using a photo eye at each end of the conveyor will aid in this process. For the programming of this system each conveyor module will be a Function Block; therefore, if multiples of a module are needed they can be easily instantiated. Additionally, standard data Structures for all conveyor modules will be used by each of the Function Blocks to aid in communication between modules.

    Machine data Structure: contains status information for the overall machine including the current State.

    Module data Structure: contains information about the configuration of the module, including information about the previous and following module.

    Creating the program

    Open the PLC Control by selecting the TwinCAT icon in the Windows System Tray and the select PLC Control

  • TwinCAT 2 From the File menu, select New

    For most of this project we will not be connecting to hardware. Therefore everything will run in simulation on the computer you are using.

    Note: The TwinCAT 2 Run-Time is only available on Windows 32-bit Operating Systems

    In the Choose Target System Type window, select PC or CX (x86), then click on OK

  • TwinCAT 2 In the New POU window the Type of POU should be a Program

    The Name of the new POU: should be MAIN

    The Language of the POU should be set to ST for Structured Text

    Note: Even if you are an experienced programmer in one of the other languages, it is my recommendation that when starting a new project the MAIN program should always be done in ST. This will allow the programmer to easily call other programs and also easily comment out large parts of the program. Additionally I would advise that the MAIN program never be done in SFC, doing so will make using the special SFC flags much more difficult, if not impossible.

  • TwinCAT 2 You should now have the following

    Place a semicolon on Line 1 of MAIN.

  • TwinCAT 2 From the Project Menu, select Rebuild All

  • TwinCAT 2 In the Message Window at the bottom, you should receive 0 Errors and 1 Warning.

    The Warning is because we have not saved the file with a name.

  • TwinCAT 2 From the File Menu, select Save As

    The file can be saved anywhere you would like. I would recommend against saving it on the desktop, the PLC Control will also create other supporting files that will clutter your desktop quickly. I have created a folder called TwinCAT 2 Manual Samples directly on the root of my C:\ drive.

    Give your project a name and press the Save button. I would recommend that you use the same file name that I have used.

    Adding a version number to your project name is an easy way to have multiple versions of the program, so that you can go back to a previous version later on.

  • TwinCAT 2 You will now see that the file name of the project is placed across the top of the PLC Control

    Before writing any real code we will first declare all known variables that will later be connected to hardware.

    Select the Resources tab at the bottom of the left column

  • TwinCAT 2 Expand the Global Variables folder by clicking on the + sign

    In the Global Variables folder there are two lists by default.

    The Global_Variables and the Variable_Configuration

    The Variable_Configuration list is only used for the BC line of controllers.

    The Global_Variables list is included by default; however, on large machines it is good practice to create multiple lists to help organize the variables into smaller more manageable lists. Therefore, we are going to start by creating a couple of Global Variable Lists.

    Right Click on the Global Variables folder, select Add Object

  • TwinCAT 2 Change the name of the list by adding _IO to the end of the name, and then click on OK

    Note: The name of this list must follow the IEC 61131-3 naming rules, the same as variable names. If it does not, or the name has already been used the OK button will be grayed out.

    Double-Click on Global_Variables_IO

    This will open the Global Variable list.

    Place the cursor at the end of line 1 and press the enter key a couple of times.

  • TwinCAT 2 Between the key words VAR_GLOBAL and END_VAR is where we will declare our variables.

    Note: Please refer to the Appendix Variable Naming Convention for a better understanding of the variable names used throughout this project.

    Comments can be added to the code by placing (* at the beginning of the comment, and *) at the end of the comment. All comments will turn green.

    (*Machine Control*)

    The following will be Boolean inputs of type BOOL, therefore when the hardware detects 24 Volts DC the PLC will represent this with TRUE, when the hardware detects 0 Volts DC the PLC will represent this with FALSE.

    gati_xMan_Auto_SS will be a two position Selector Switch between Manual and Auto. When the switch is in the Manual position the input will be off, when the switch is in the Auto position the input will be on.

    gati_xMaintenance will be a push button to request the State Machine to go into Maintenance

    gati_xReset will be a push button for resetting faults

    (*Stack Lights*)

    The use of Stack Lights allows everyone in the area of the machine to easily know the status of the machine. The definitions of what the colors represent vary between industries and countries.

    For this project the following colors will be used as defined here:

    Yellow will be used when the machine is in Automatic

    Green will be used when the machine is in Manual

    Red will be used when a Fault is active

    Blue will indicate that the machine is in Maintenance

    Between Yellow, Green, and Blue only one of the can be on at any given time.

    Red can be on in addition to any of the others

    gatq_xAutoLight will be written with a value of TRUE when the machine is in Auto, thereby applying 24 Volts DC to the output and turning on the light.

    gatq_xManualLight will be written with a value of TRUE when the machine is in Auto, thereby applying 24 Volts DC to the output and turning on the light.

    gatq_xFaultLight will be written with a value of TRUE when the machine is in Auto, thereby applying 24 Volts DC to the output and turning on the light.

    gatq_xMaintenanceLight will be written with a value of TRUE when the machine is in Auto, thereby applying 24 Volts DC to the output and turning on the light.

  • TwinCAT 2

  • TwinCAT 2 Next we will create an Enumeration that will be used to represent the possible States of the State Machine.

    Select the Data Types tab at the bottom of the left column

  • TwinCAT 2 Right-Click on the Data Types folder and select Add Object

    Type in E_MachineState as the Name of the new data type, and click OK

    You should now have the following

  • TwinCAT 2 Data Types always default to a STRUCT, this can be changed to an Enumeration by simply removing STRUCT and END_STRUCT from lines 2 and 3 and replacing them with ();

    When creating an Enumeration the first Variable will receive a value of zero by default, each value after that will be incremented by one. The variables of the Enumeration must be placed between ( and ) and each one separated by a comma ,.

  • TwinCAT 2 Now would be a good time to save the changes that have been made. From the File menu, select Save. Or simply press and hold the Ctrl key and the press the S key.

    Notice that the asterisk * and the end of the file name disappears. The asterisk is there to indicate that changes have been made but not saved.

    To check the Enumeration and the Global Variables for any possible typing errors go to the Project menu, and select Rebuild All

    If you have any errors, they should be fixed before moving on.

    As an example I have removed the semicolon from the end of one of the Global Variable declarations.

    When preforming a Rebuild All this generates 2 errors, which can be seen in the Message Window

  • TwinCAT 2 Place your mouse at the top of the Message Window

    Click and Drag the bar upwards to see more of the Message Window

    It is best to start with the first error in the list, many times one problem will create others for the compiler.

    The easiest way to find the first error in the list is to press the F4 key. Repeatedly pressing F4 will go to the next error in the list. You could also scroll through the error list and Double-Click on the error.

    When the error is selected, the location of the error will be shown, and the line of code that has the problem will be highlighted. Repeatedly pressing F4 will go to the next error in the list.

  • TwinCAT 2 The full error message states that the complier is Expecting the end of line character or an assignment before seeing a new variable name. To the compiler the problem occurred on line 9, the appropriate way to fix the problem is to find the variable declared before line 9 and place the semicolon at the end of the line.

    After fixing any errors you may have had, preform another Rebuild All from the Project menu.

    Once, you have zero errors, you will get 7 warnings. Generally speaking warnings can be ignored. These 7 warnings are created by the use of %I* and %Q* variables. The warning simply states that the VAR_CONFIG file has not been created for these variables. F4 will scroll through the warnings. Ignore them for now and continue on.

    Now would be a good time to Save your project.

  • TwinCAT 2 Finally, it is time to write some code. Click on the POUs tab at the bottom of the left column.

  • TwinCAT 2 Double-Click on the MAIN program.

    Note: You may or may not have the small blue arrow next to the icon for MAIN. This blue arrow simply indicates that changes have been made to this POU that have not been downloaded into the running PLC.

    In the local declaration section of MAIN define a variable called eStep as of type E_MachineState

    The best way to do this is to first type in the new variable name eStep, then place a colon after it, then press the F2 key which opens the Input assistant.

  • TwinCAT 2 Select User defined Types from the left column and then E_MachineState, press OK

    This will bring you back to the declaration section; place a semicolon at the end of the line.

    By declaring eStep to be of type E_MachineState the value of the variable eStep will be the text in the Enumeration. eStep will be used as the condition variable of the CASE statement that will control the State Machine.

  • TwinCAT 2 The general layout of a CASE statement is as follows:

    The variable