TwinCAT 3 Tutorial

This is an in-depth tutorial on Beckhoff’s TwinCAT 3 PC-based automation software.

Twin cats?

Twin cats?

The tutorial is organized into a chapter format and is meant to be read like a book. Start here with the Table of Contents:

  1. Introduction
  2. Quick Start
  3. Structuring PLC Data
  4. Persistent Variables
  5. Structuring PLC Logic
  6. Multiple Virtual PLCs
  7. Ladder Logic Editor
  8. Writing your own Functions and Function Blocks
  9. Structured Text
  10. Building an HMI in .NET
  11. Introduction to Motion Control
  12. Introduction to TwinSAFE
  13. The Scope View
  14. Part Tracking

Be sure to check out my RSLogix 5000 Tutorial as well.




42 thoughts on “TwinCAT 3 Tutorial

  1. codezs09

    This tutorial is great. Very specific in every details with understandable explanations.
    There are not a lot intro related to TWINCAT 3. This one is really the best I have ever seen.
    Much thanks to your effort! And strongly recommend it to others.

  2. Gerard

    I find it a pity that the tutorials don’t come with a time stamp. One can see how old the blog entries are, but no idea about each of the tutorial chapters.

  3. Ledian

    I come from an Omron plc experience background on Cx-Programmer and now I am trying to learn NJ-controllers (Sysmac Studio) and Backhoff (TwinCat 3) as both environments are based on Codesys. I like the ideology of these products more than Siemens and AB. I found these TwinCAT 3 tutorial useful as it’s detailed and clear to understand with examples. Thank you for your contribution, I will continue to follow every chapter of this tutorial hoping to get all the basic knowledge of PC based Automation Technology from Beckhoff. Good work, thanks again.

  4. John nielsen

    Great tutorial. Very easy to understand and thoug with very detailed and good explanations.
    The Best intro to TWINCAT 3.I have seen so far.
    Are you planning a chapter on scoope view ?
    I very much recommend this tutorial to others.
    Very god work, thank you very much

  5. Scott Whitlock Post author

    @JohnNielsen – Thank you! Yes, after the next chapter (on TwinSAFE) then I’m going to do a chapter on the Scope Viewer, which is a really useful tool, even though it’s a bit intimidating at first.

  6. John C.

    Scott, I very much appreciate your tutorials. I’m in the process of learning TwinCAT 3 and, as others have pointed out, there are virtually no “getting started” materials available from Beckhoff. I found your “Structuring PLC Logic” lesson to be particularly interesting, as I come from an AB background. Keep them coming!

    (If you’re taking suggestions for future lessons, I’d like to learn more about EtherCAT… tips on laying out networks with couplers and terminals, addressing, troubleshooting, etc.)

  7. biruk

    This is a great tutorial, very well organized, simple and tractable explanations. Thank you

  8. Jeyfel Brandauer

    Thank you for this great tutorial!
    I’m a student currently in an internship and i’m kind of new in the automation control world. I do software development. So this tutorial is definitely helpful as I have to use TwinCAT.

    In the 6th part of the tutorial we create a EtherCAT device and its I/O. Each I/O (eg. EL1008 channels) of an EtherCAT device has its own Index group and offset. Does it mean that we can access them remotely with a TwinCAT ADS Client?
    This would be of great help to me.

    Regards
    Jeyfel B

  9. Scott Whitlock Post author

    @JeyfelBrandauer – In theory yes, but I can’t remember ever doing it. If you happen to be doing a non-real-time system (just using Beckhoff I/O controlled from, e.g. C++ or C# in a PC program) then I recall the right way to do that is to create a Task in TwinCAT without creating a PLC (this way you only need the I/O license, not the PLC license). You create variables directly in the Task and you map them to the I/O. I/O needs to be linked to a task for it to “scan”. The task has an ADS port number. You then read and write to the variables you’ve created directly in that task, and TwinCAT handles moving the data to/from the I/O card (e.g. EL1008). That was a long time ago, though, so it’s a bit fuzzy.

  10. Jeyfel Brandauer

    @Scott – Thank you for the reply! I’m working on a virtual commissioning project. We need to test and validate our PLC programs (Ladder, ST etc.) by running them inside of TwinCAT. My goal is to build an external program (i.e an ADS client program, in C++) which will “drive” the validation of our PLC programs by interacting with TwinCAT. Actually I did couple of things such as reading and writing PLC variables. The problem that I’m facing is to subscribe to their “state change” event. TwinCAT provides an ADS notification service to do so, but it’s not available for IO-tasks. @soberschmidt at GitHub suggested me a workaround: a mapping to PLC variables. I thought that I had to create a device (EtherCAT simulation for instance) and map its I/O to my PLC variables.But the device I/O are unreachable through ADS protocol.

    I will try what you suggested to me and combine it with an existing PLC project. Thanks again.

    Jeyfel B
    (sorry for my English, I’m from France)

  11. Ivan

    Hi Scott. Thank you very much for creating this excellent guide. It has been extremely useful in helping me learn TwinCAT 3. Thank you for putting this together and sharing your knowledge.

  12. Sachin Kapatkar

    Nice presentation in tutorial.
    Thanks allot.
    Keep sharing such helpful information.

    Best regards,
    Sachin Kapatkar
    (From India)

  13. Krystian

    Hi.
    I have just little experience with automation and this is very helpful. I just have a question if there is possible to run some kind of simulation mode, to check if my code/diagrams are logically correct. Like Simulation Mode from Siemens Logo!.

    Regards

  14. Armando Narvaez

    Hi Scott,

    I have to say that your tutorial is great! I come from an AB/Ladder background but, ever since I started my Master’s, I had to switch to a CODESYS/ST environtment. It was kind of tough at the beggining but, on the programming aspect, I think I can handle it myself. It is a bit helpfull that I also have a strong background on OOP and CS concepts.

    I wanted to ask you, if you have a “rule of Thumb” or way to choose which PLC should you use or which specs (# of cores, RAM, SDD storage and whatsoever) ?

    I’m asking you this because, outside of my Master’s, I’m working on a project with around 300 IO’s, 30 PTP axes, an OPC UA Server, a MySQL database and an HMI. But I don’t know if a PLC with only 2/4 cores could handle everything.

    Thanks in advance,
    Best Regards,

    Armando Narvaez.

  15. Scott Whitlock Post author

    @ArmandoNarvaez – sorry for the delay. The higher end Beckhoff IPC at the moment is a Core i7 with 4 cores, and even though they force Hyperthreading off in the BIOS, it still screams when it comes to PLC and motion control logic. We always use a Core i5 now, and it just doesn’t seem to make a difference how much logic you throw at it.

    We always use an SSD and 8GB of RAM at the moment.

  16. MaximilianoG

    This is by far the best written tutorial compilation for the TwinCAT Software that I have found. Thank you again Mr. Scott for the detailled explanation. It has eased my begin with the Software a lot.
    Thanks for sharing your knowledge!!

  17. Bernd Esch

    Thanks for your tutorial Scott,
    it helped me very much to run a 400 Volts EXLAR Drive on
    480 Volts in San Francisco, using the settings you recommended in the
    Introduction to Motion Control
    I also can confirm that Beckhoff Motors run without Problems on 480V

    Great Job You made
    Bernd Esch
    (from Switzerland)

  18. Bassam

    this turorial is very helpful for TC3 beginners and it saves a lot of time which would have been lost searching all over the internet.

    thanks for this useful peace of work.

  19. Ravi

    Hi,

    Thanks for the document, very helpful:-) Also could you please provide the same for TwinCAT3 Visualization?

  20. Scott Whitlock Post author

    @Ravi – actually I haven’t used TwinCAT 3 visualization since version 2, so I’m not sure I’d be a good source for that information. We just use Visual Studio and C# internally to build our HMIs.

  21. Joe C.

    Hi Scott,

    I’m a Mechanical Engineer now also a beginner to Beckhoff PLC’s in structured text in the last 12 months & found this very helpful. Thanks for sharing your knowledge. Great way to get started in TwinCAT 3. Very thorough & great referece. Especially helpful for TwinSAFE
    @Ravi / If anyone is looking for more information on TwinCAT / structured text including visualisation, a video series (11 episodes) can be found on YouTube if you search for “Learning PLCs With Structured Text”
    I also found this very helpful & I hope you don’t mind me sharing on your site.

    Joe (From Australia)

  22. Dhruvan Shah

    Hi, I am an Automation Engineer working with a private firm. My company wants to do business with beckhoff and I am in-charge of this project. Honestly I knew nothing regarding beckhoff’s Twincat 3. But this tutorial has given me a lot of insight and made my work much easier. The information is presented in a language that is easily comprehensible. I want to thank you for all your effort in making this tutorial. It’s been more than 2.5 years since you posted this but yet no material is available on the internet that comes anywhere near to you.Thanks again, you did a great job.

  23. Klaus Schermer

    Best Site with description of the TwinCAT3 System i’ve eher seen! Beckhoff should Link your Site, because it’s even better than the Beckhoff Documentation. Thanks a lot to the author for sharing his Knowledge!

  24. r112029

    Hello & thank you,

    This tutorial is fantastic! I’ve been to a lot of manufacturer specific PLC/DDC training courses (Beckhoff included) and I’d say that for an experienced automation engineer/programmer with background in PLC systems, spending one day with this tutorial and playing around in TC3 could spare you the time and money for a week-long training course. You probably know this but Beckhoff sales and training reps are actually referring to this tutorial (I came here trough recommendation from Beckhoff in Sweden).

    I’m mostly used to programming applications for building automation/HVAC and nowadays external data communication needs to be included in almost every application (both low-level like Modbus, Bacnet etc and high-level IoT interfaces). I think that TC3 has fantastic capabilities for that stuff, but it’s not very easy to get started on. Do you have any experience in this field, and if so do you have any plans on writing about it?

  25. Scott Whitlock Post author

    @r112029 – Hello, and thank you! My background is in discrete automation, so I don’t really know anything about building automation. Any project I do uses EtherCAT, and sometimes has EtherCAT to other bus adapters, such as DeviceNET (rare) or Ethernet/IP (common). I haven’t used Bacnet or Modbus with Beckhoff, though I did use Modbus a long time ago and I’m familiar with the protocol. Unfortunately I can only write what I know about, so I’ll have to leave building automation to someone else! 🙂

  26. Mike

    Hey Scott!

    I’ve been trying to learn TwinCAT and programming. I recently acquired an EK1100 with a few cards attached to it. I have successfully created a PLC (EtherCAT master) and some simple logic following your tutorial here (running in XAR) and I even got it connected to the EK1100 through a dedicated Ethernet port. So basically, the simple program turns one of the DOs on or off based upon a global variable. I have been trying to write a basic C# app using the ADS DLLs and all it does is write a true or false to the global variable. This app works great when I run it on the local XAE computer but when I try to run it from a remote computer, the communication fails. The computer has two NICs, one plugged directly into the EK1100 for EtherCAT communications and the other is a WiFi connection to my LAN. The NIC connected to the EK1100 has an IP of 192.168.20.43 and the WiFi card has 192.168.10.43. I’d like to be able to communicate with the virtual PLC from a remote computer on my 10.x network but I can’t seem to get it to work. Have you had any luck with this? I’m used to virtualization from an IT perspective (like Hyper-V and VMware) so I would’ve thought that since the “virtual” PLC that runs in the runtime would be able to see both networks (10.x and 20.x) and communicate on either but I suppose I’m missing something. I’ve also tried plugging the computer and EK1100 directly into my LAN and using a 10.x address and updating the Net ID to match but whenever I start the runtime, I lose all network connectivity to my LAN. I’ve also played around with EoE but I can’t seem to get that to work either. Perhaps I’m misunderstanding what EoE is for.

    Any help you can provide would be greatly appreciated. I can’t afford an actual CX PLC to play around with so this is the best I have for now.

    Thanks,
    Mike

  27. Scott Whitlock Post author

    @Mike – this is a good question. If you followed the tutorial, then you’re using the ADS DLL to talk from C# to the XAR runtime. This works great when the C# program and the XAR runtime are installed on the same computer, but doesn’t work when they’re on different computers.

    To understand why, and how to fix it, you need to know a bit about how ADS works. Your C# DLL didn’t connect directly to the XAR runtime – it connected to an ADS router that was automatically installed on the PC when you installed TwinCAT 3.1, and it passed messages between the Windows side (C#) and the XAR (PLC) side. This all happens transparently when you’re working on the same computer.

    In order to send ADS messages back and forth between two computers, you need 2 things: 1) the ADS router needs to be running on both devices, and 2) you need to define a route between them. Assuming you installed a full TwinCAT 3.1 on both computers, you just need to define the route. If one PC (with say a stand-alone C# program) doesn’t have TwinCAT 3.1 on it, then you only need to download and install TC1000 from Beckhoff and install it on that PC. That installs the ADS service/router.

  28. Erik Stroeken

    Fantastic Tutorial. I only used Beckhoff from CPP and had to learn the PLC part for a new project. Why don’t you consider to publish this tutorial in Plurarsight. In Switzerland Beckhoff is lifting of and engineers need tutorials like this without a lot of commercial bla bla. Straight to the point. Contact Beckhoff and offer them to help them setting up an online education program. Every user they gain increase their turnover so it should be for free.
    Again, compliments!
    Erik Stroeken

  29. Pingback: TwinCAT 3 Tutorial: Introduction | 电力线通讯(PLC)电机控制

  30. Vincent Agu

    Hello Scott

    Thank you for the great job on this site. I am rather coming in new to PLC. I have an Induction Furnace which I need to operate with a PLC only for both analog and digital signal processing. The Furnace will input and output signals in the order of 6KHz – 12KHz. I want to use a PLC with analog and input I/O modules with that signal speed capability.I will like to use an open source like Codesys but out of fear of frequency performance I am looking to Twincat 3 because I found 30KHz I/O modules which I could not find in any of Codesys compliant PLCs. Kindly guige me. Regards

  31. julio cesar Cesar Alvarado Méndez

    Podrían poner algo de comunicación por Profibus y profinet por twincat 3

  32. Scott Whitlock Post author

    @JulioCesarAlvaradoM̩ndez РTwinCAT can support Profibus and ProfiNET by first going to an EtherCAT rack (such as with an EK1100) and then adding an EL6731 (for Profibus) or an EL6631 (for ProfiNET) card.

  33. Adam Haney

    Scott,

    I just wanted to thank you again for all of the work you have put into generating valuable content to help the automation field. I actually e-mailed you in early 2019 about a job I took as an Automation Eng on a greenfield steel project. After completing that, a partner and I started an integration business.

    I really cannot thank you enough for taking the time to e-mail me back then and having these resources online for people to learn from. I truly appreciate it.

  34. Meki

    Some comments on Twinsafe-chapter.
    It seems some updates have clarified the process and wizard automatically performs some parts of the chapter. Not 100% sure, but here’s my experience:

    Twinsafe Group Properties and ErrorAcknowledgement:
    Instead of Properties of Network1, Twincat opened Variable Mapping and Safety Project Online View-windows (which were hiding behind Output-windows in my case)
    In Variable Mapping. – Variables-tab you can find Err Ack.

    Though not sure if this applies to everyone, my mappings were done automatically and didnt have to touch properties/Variables-part at all. (though, in Properties its definitely dissimilar to instructions)

    FbErr and CommErr worked by simply linking to their GVL partners.

    “Writing safety logic” -chapter is identical to instructions so not everything has changed.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.