TwinCAT3 Setup Guide

E-MCC_ETHERCAT

Preamble

The following guide will assist with setting up a Zaber E-MCC series controller/drive in TwinCAT 3.

Prior to configuring TwinCAT for your E-MCC, it is important to make sure that your physical setup is complete and that TwinCAT 3 is installed and configured on your development computer.

Hardware Setup

Your hardware should all be physically plugged in prior to setting up the E-MCC in TwinCAT.

This includes:

  1. a peripheral stage plugged into the E-MCC
  2. the peripheral stage being activated
    • Note: This occurs automatically the first time a Zaber peripheral is plugged into the E-MCC.
  3. the EtherCAT cable is connected
  4. the Power supply is connected
  5. the Development PC is connected to the EtherCAT master.
    • Note: It is possible to install the TwinCAT development environment (XAE) directly on the EtherCAT master. In this case a development PC is not required. See TwinCAT XAE and XAR.

EtherCAT Network Physical Setup

TwinCAT Installation

If not already installed, download and install TwinCAT 3 on your development computer.

  • Note: This guide is written using TwinCAT 3 build 4026, but the process will be very similar for older versions such as build 4024.

ESI File Installation

  1. Download the ESI file from the product webpage.
  2. Copy the ESI file to the appropriate folder.
    • By Default, this folder is located in the TwinCAT installation directory.
    • Typically C:\Program Files (x86)\Beckhoff\TwinCAT\3.1\Config\Io\EtherCAT
  3. If TwinCAT is already open, reload the ESI files.
    • Select TwinCAT -> EtherCAT Devices -> Reload Device Descriptions
    • Note: This menu is only available if a project is open.
    • Note: TwinCAT automatically performs this action at startup.
      Reload Device Descriptions Button

TwinCAT XAE Project Setup

The following instructions detail how to set up a TwinCAT XAE project which can perform point-to-point (PTP) motion using the E-MCC.

Initial Setup

  1. Open the TwinCAT XAE shell.
    Open XAE Shell
  2. Select File -> New -> Project
    New Project Button
  3. Create a new TwinCAT XAE Project (XML Format).
    • Create the project with the name and folder of your choice.
      New Project Type New Project Naming
  4. Ensure that the TwinCAT XAE is connected to the XAR on your Beckhoff IPC.
    • If you haven’t previously added your IPC, see Setting up a New Target System.
    • If you’re running the TwinCAT XAE directly on the IPC, select <Local>.
      Target System Dropdown Menu
  5. Ensure that TwinCAT is in Config Mode.
    • The blue icon on the bottom status bar confirms that Config Mode is active.
      Config Mode Button Config Mode Active

IO Tree Setup

The I/O tree represents the physical devices on the EtherCAT network. TwinCAT needs to know the layout of devices on the network prior to initializing it. A typical network configuration is one EtherCAT master with multiple slaves connected to it.

To set up the I/O tree with the E-MCC:

  1. Expand the I/O tree.
  2. Right click on Devices -> Add New Item....
    IO Tree New Item
  3. Select EtherCAT Master and click Ok.
    IO Tree Add Master
  4. Select whichever network adapter you intend to be your EtherCAT master.
    • For Beckhoff IPCs these are usually labelled on the device as X000, X001, etc.
    • Note: Network adapters must have the correct driver installed or they won’t show up on the list. If the adapter isn’t listed, see Setting up a Network Adapter.
      Network Card Selection
  5. Once your network adapter is configured, right click on the EtherCAT master and click Scan.
    • This will attempt to find all EtherCAT slaves connected to the network adapter.
      EtherCAT Master Scan
  6. When prompted, click OK to append the linked axis in NC - Configuration.
    • This window appears because a CiA 402 compatible drive was found on the network.
    • Note: CNC - Configuration is out of the scope of this guide.
      Append NC Axis
  7. An E-MCC should appear underneath the master, along with any other connected slave devices.
    • Additionally, an NC Axis (Axis 1) should appear under the MOTION tree.
      New Slave and NC Axis
  8. Expand the E-MCC1 to view its default process data (PDOs).
    • This is the real time data sent over the EtherCAT network:
      • Red items are output data sent from Master to Slave (RxPDO).
      • Yellow items are input data returned from Slave to Master (TxPDO).
      • Green items are generic network diagnostic/configuration information.
    • If you wish to change this data, see Configuring Process Data.
    • Note: For peripherals without an encoder, it is highly recommended to remove Position Actual Value and Following Error Actual Value, since these values are invalid without a position feedback sensor.
      IO Tree Default Process Data
  9. Double click the E-MCC1 and open the DC tab.
    • Click Advanced Settings… to open the advanced distributed clock settings.
      Slave DC Settings Tab
  10. Ensure the Sync Unit Cycle is set to 1x.
    • This ensures that the Sync0 signal fires once for every master trajectory setpoint.
    • Note: The E-MCC uses the Sync0 signal to calculate trajectory interpolation. Setting this field incorrectly may cause jerky motion.
      Slave DC Settings Advanced Window

NC Axis Setup

The NC Axis generates point-to-point motion trajectories on the EtherCAT master. These trajectories are streamed to the drive as individual setpoints via real-time EtherCAT process data (PDOs). The following instructions outline how to configure the NC Axis for use with the E-MCC. For more information see Beckhoff's TF50x0 | TwinCAT 3 NC PTP Manual.

Setting up an NC Axis involves three primary steps:

  1. Timing Settings
  2. General Settings
  3. NC Parameters


These steps are detailed below.

Timing Settings

Timing settings determine the rate at which NC Axis trajectories are calculated and streamed to the drive. There are two separate tasks:

  1. NC-Task 1 SAF - The rate at which individual trajectory points are transmitted over the EtherCAT network.
  2. NC-Task 1 SVB - The rate at which the whole trajectory is evaluated for re-calculation.


Increasing these rates is generally beneficial for motion performance, but also increases CPU usage on the master. Usually the SVB task can be left at the default value. However, it is important to set the NC-Task 1 SAF to a rate supported by the drive because this value determines the EtherCAT process data cycle rate.

To set the cycle rate:

  1. Select the NC-Task 1 SAF.
    NC-Task 1 SAF Selection
  2. If the current Cycle ticks are not within the valid range supported by the E-MCC, adjust the value.
    • The E-MCC supports rates from 1.0 ms to 10.0 ms.
    • 1.0 ms will result in the best motion performance.
    • Note: Cycle ticks cannot be set lower than the system base time. See Configuring System Base Time if you need to change this value.
      SAF Cycle Rate Selection

General Settings

There are a few general settings that are important to configure on an NC-Axis.

  1. Double click the NC Axis.
    • Tip: It’s a good practice to name it something useful (ex. X-Axis).
      NC Axis General Tab
  2. Select the Settings tab. Ensure the NC Axis is linked to the desired physical hardware on the I/O tree.
    • This ensures that process data is transmitted between the NC Axis and the drive.
    • Note: If the box is empty, click Link To I/O… and select the E-MCC.
      NC Axis Settings Tab
  3. Ensure the Axis Type is CANopen DS402/Profile MDP 742 (e.g. EtherCAT CoE Drive), and select the units of your choice.
    NC Axis Type Setting

Parameters

The NC Axis has limited information about the E-MCC. Therefore, certain parameters must be configured to ensure the NC Axis generates trajectories that are suitable for the connected peripheral. These settings include:

  • Scaling factor (unit conversion factor)
  • Maximum speed
  • Jog speeds
  • Acceleration limits
  • Travel limits
  • Following error monitoring


Note: Some steps in the following section involve querying Zaber specific settings from your device. We recommend using our free software, Zaber Launcher for this purpose.


To set these parameters:

  1. Expand the NC Axis. Click ENC, then select the Parameter tab.
    • These parameters relate to the device’s encoder.
      NC Axis Enc Parameters
  2. Under Encoder Evaluation, set the Scaling Factor Numerator and Denominator as required for the connected peripheral.
    • Scaling factors are the most important settings for an NC Axis. They determine the conversion ratio from native position units to user units (m, mm, deg, etc.).
    • Zaber devices use the following native units:
      1. Stepper motor axes use native units of microsteps, as indicated by the Microstep Size specification.
      2. Servo (linear motor) axes use native units of encoder counts, as indicated by the Encoder Count Size specification.
    • Set the scaling factors based on your chosen user units and microstep or encoder count size of your peripheral. The value can be found on the product’s webpage, under specifications. The scaling factors shown below are for a servo device with an encoder count size of 1 nm (1,000,000 counts per mm, or 0.001/1000.0 mm/INC).
      NC Axis Scaling Factors
  3. Under Limit Switches, set the following parameters:
    • Soft Position Monitoring: True
    • Minimum Position: Zaber’s limit.min setting
    • Maximum Position: Zaber’s limit.max setting
    • Note: Make sure you query Zaber settings in the same units as TwinCAT (ex. mm).
    • Tip: In most cases, limit.min is 0, and limit.max is the axes physical travel range.
      NC Axis Limit Switch Parameters
  4. For non-encoder peripherals only: Select the NC-Encoder tab and set the type to Simulation encoder.
    • Simulation encoder means that the NC Axis measured position is obtained by directly copying target position values. A real measured position can only be obtained on devices with an encoder.
      NC Axis Simulation Encoder
  5. Under the NC Axis, select Ctrl, then the NC-Controller tab.
    • Ensure that the type is set to SERCOS controller (Position by SERCOS).
    • This ensures that generated trajectory values get sent directly to the drive without filtering.
      NC Axis NC-Controller Setting
  6. Under the Parameter Tab, verify the Monitoring parameters.
    • Position Lag Monitoring will cause the NC Axis to fault if the specified lag distance is exceeded (target position - measured position).
    • Position Lag Monitoring should typically be TRUE, unless:
      1. Your peripheral does not have an encoder.
      2. You have unusual application specific requirements.
    • Set the Maximum Position Lag Value to be suitable for your application (often 1-2 mm/deg).
      NC Axis Lag Monitoring Settings
  7. Select the NC Axis, then the Parameter tab. Set the following Maximum Dynamics parameters:
    • Reference Velocity: The peripheral’s maximum speed specification.
    • Maximum Velocity: Same as reference velocity.
    • Maximum Acceleration: Calculate this based on your payload and device’s peak thrust specification (acceleration = thrust / mass).
    • Maximum Deceleration: Typically the same as Maximum Acceleration.
    • Note: Make sure you query Zaber settings in the same units as TwinCAT (ex. mm/s).
      NC Axis Maximum Dynamics Settings
  8. Under Default Dynamics, set the following parameters:
    • Default Acceleration: Zaber’s accel setting
    • Default Deceleration: Typically the same as Default Acceleration
    • Default Jerk: Your choice. A typical value is 4x acceleration. Lower values produce smoother motion, but may take longer to execute a trajectory.
    • Note: Make sure you query Zaber settings in the same units as TwinCAT (ex. mm/s2).
      NC Axis Default Dynamics Settings
  9. Under Manual Motion and Homing, set the Manual Velocity and Jog Increments.
    • These parameters are optional, as they control the behavior of TwinCAT’s NC Axis Online window. Set them to values that are useful for testing the motion of your device.
      NC Axis Manual Motion Settings
  10. Tip: To save your settings for future use, right click on the NC Axis and select Export XML Parameter....
    • Your NC Axis parameters can be easily loaded from this file in the future.
    • Save the file as a useful name for the device (ex. LDM110C-AE54T10A.xml).
      NC Axis Export XML Parameter.

Testing Motion

Once the I/O tree and NC Axis have been configured, everything should be ready to perform motion with your E-MCC.

To test that motion is working properly:

  1. Click Activate Configuration.
    • When prompted to Restart in Run Mode, click OK.
    • This tells the TwinCAT XAR to activate and run the configuration you’ve created in the TwinCAT XAE project.
      Activate Configuration Button
  2. You may see the following emergency message: Hex: 8280.
    • This error indicates that one of your assigned process data objects is not supported by the peripheral connected to the E-MCC.
    • The most common reason for this error is that an non-encoder peripheral is connected to the E-MCC. Objects 0x6064 Position Actual Value and 0x60F4 Following Error Actual Value should be removed from the process data configuration, as these values are not valid without a position feedback sensor.
    • See Configuring Process Data.
      Invalid Process Data Emergency Message
  3. You may see the following emergency message: Hex: 8680.
    • This error means the axis hasn’t been homed yet.
    • Please home the axis before proceeding.
    • See Homing an Axis.
      No Reference Flag Emergency Message
  4. Double click the NC Axis. Select the Online Tab, then click the F8 reset button.
    NC Axis Online Reset Button
  5. Click Set. In the popup window click All.
    • This will enable the motor.
    • The All button activates all three checkboxes and sets the velocity override to 100%.
      NC Axis Enable Drive Power Button
  6. Use the jog buttons to move your device around and test that motion works properly.
    NC Axis Online Jog Buttons
  7. If the axis encounters a fault (ex. Following Error), press the F8 reset button to reset the NC Axis.

PLC Project Setup

A PLC project is used for writing automated PLC programs. These programs can interact with the NC Axis and thus control motion on the E-MCC. Below are the basic steps for building a TwinCAT PLC program that can interact with the E-MCC using Beckhoff’s Tc2_MC2 motion library. The library contains many function blocks which can be used to interact with the NC Axis. For more information, see the Tc2_MC2 Manual.

Note: TwinCAT’s MC_Home function block will not work properly with the E-MCC. For information on homing, see Homing From a PLC Project.


The following instructions assume you have already set up your TwinCAT XAE project as documented in the previous sections.


To create a PLC project:

  1. Right click on PLC and select Add New Item….
    Add New PLC Project Button
  2. Add a new Standard PLC Project with the name of your choice.
    Add New PLC Project Dialog
  3. Expand the project. Right click on References and select Add library….
    PLC Project Add Library Button
  4. Add the Tc2_MC2 and Tc2_NC libraries to your project.
    • Only one library can be added at once.
    • Once added, both libraries should be visible under References.
      Add PLC Libraries Dialog NC Libraries Added
  5. Expand the POUs folder and double click MAIN (PRG).
    • This file is the primary execution point of your PLC program.
      PLC Project Main POU
  6. Add a variable of type AXIS_REF to the program.
    • The AXIS_REF variable provides an interface between the PLC program and NC Axis.
      PLC Project AXIS_REF Variable
  7. Click Build -> Build Solution to compile the program.
    Build Solution Button
  8. Expand the MOTION tree and double click the NC Axis. In the Settings tab, click Link To PLC…. Select the MAIN.axis1 variable from your PLC project and click OK.
    • This links the NC Axis to your AXIS_REF variable.
    • Since the NC Axis is also linked to the E-MCC, motion can be directly controlled from the PLC program.
      PLC Project NC Axis Link
  9. Add the MC_Power function block variable to the program, and the following lines of code as shown below.
    • axis1.ReadStatus() is not required, but is a good practice to call at the start of all PLC programs. It updates the internal state of the AXIS_REF function block.
      PLC Project MC_Power Variable
  10. Re-compile the PLC program.
  11. Click Activate Configuration and restart TwinCAT in Run Mode.
    Activate Configuration Button
  12. Click Login, then Yes on the popup dialog.
    • This enables access to view and control code execution on the PLC.
      PLC Project Login Button
  13. Click Start to start execution of the PLC program.
    • This should enable motor power on the E-MCC.
      PLC Project Start Button
  14. The real-time status of the NC Axis can be viewed by expanding the axis1 variable.
    PLC Project Online Variable View
  15. To stop the program execution, press Stop, followed by Logout.
    • This will disable the motor power.
      PLC Project Logout Button

At this point, initial setup is complete.

Example Projects

This section contains TwinCAT3 example projects available for download.

Can't find what you're looking for? If there's a different type of example you'd like to see here, please contact us.

Drive Based Homing Example

This example demonstrates how to perform drive based homing (CiA 402 operation mode 6) from a TwinCAT PLC program. For more information see Homing From a PLC Project.

Basic Motion Example

This example demonstrates how to use basic drive functionality and perform point-to-point motion from a TwinCAT PLC program.



Appendix

This section contains optional steps and reference information about TwinCAT.

TwinCAT XAE and XAR

TwinCAT consists of two independent software packages:

  1. eXtended Automation Engineering (XAE)
    • This is the TwinCAT development environment, which is based on a modified version of Visual Studio. It is used for tasks like configuring the EtherCAT network, writing PLC programs, and testing motion.
    • The XAE has an unlimited free license.
  2. eXtended Automation Runtime (XAR)
    • This software is what makes a computer an EtherCAT master. It runs the EtherCAT network and executes user generated code in soft real-time.
    • The XAR has unlimited free 7-day trial licenses. A CAPTCHA has to be entered every 7 days to continue operation.

The most common TwinCAT setup is to have the XAR installed on a Beckhoff IPC (industrial PC) and the XAE installed on the user’s development PC. The two software packages communicate over Ethernet using Beckhoff’s proprietary protocol, ADS. PLC programs and network configuration are generated in the XAE, and then pushed to the XAR (activated) using ADS. However, another common configuration is to install both the XAE and XAR on the same computer. This guide is valid regardless of whether the XAR is installed on the local computer or a remote computer.

For more information, see Beckhoff’s documentation: TwinCAT 3 Philosophy.

Setting up a New Target System

The TwinCAT XAE development environment can remotely connect to TwinCAT runtime environments on a network attached computer or IPC, also known as the target system. The desired target system can be selected from the dropdown menu shown below in TwinCAT. However, the remote machine will not show up on this list unless you’ve configured it first. The instructions below show how to set up a new target system.

Choose Target System Dropdown

Note: Ensure both your development computer and remote machine are physically connected to the same Local Area Network (LAN) before proceeding. If a LAN network is not available, it is also possible to connect two computers with a single Ethernet cable. To connect computers with a single cable, you must set static IP addresses on the network adapters of both computers. It is recommended to set your development machine’s IP to 192.168.1.1 and the remote machine’s IP to 192.169.1.2.

To set up a new target system:

  1. Open the dropdown menu and select Choose Target System....
    Choose Target System Dropdown
  2. In the popup menu, select Search (Ethernet)....
    Target System Search Ethernet Button
  3. Click Broadcast Search.
    • This will search the LAN network for remote computers with the TwinCAT runtime installed.
    • Note: Occasionally the broadcast search will not find any devices. In this case, connect a mouse and monitor to the remote machine and manually check its network IP address, or use third party network scanning software to scan all the IP addresses on your network. The IP address can be entered manually in the upper text field, followed by clicking Enter Host Name / IP.
      Add Route Broadcast Search Button
  4. Select the desired machine and click Add Route.
    Add Route Dialog
  5. Enter the User and Password for the remote machine and click OK.
    • This is typically the user’s Windows account credentials.
      Add Route Credentials Dialog
  6. The device should appear as connected, indicated by the checkmark. Click Close to close the window.
    Add Route Success
  7. Select your new target system and click OK.
    Choose Target System Dialog
  8. Your new target system should now be selected in the dropdown menu. This means TwinCAT is successfully connected to the remote machine.
    • The target system’s mode (Run or Config) should also be visible on the bottom toolstrip.
      Choose Target System Dropdown Collapsed TwinCAT Config Mode Active

With the new target system setup, you are ready to configure your remote machine.

Setting up a Network Adapter

Network Interface Controllers (NICs) need a specific real-time driver installed before they can be used with TwinCAT. These drivers come pre-installed on Beckhoff IPCs, but may have to be installed manually for other systems. Note that only certain network adapters are compatible with TwinCAT. See Supported network controllers.

To set up a network adapter:

  1. Double click your EtherCAT master on the I/O Tree.
    IO Tree EtherCAT Master Selected
  2. Navigate to the Adapter tab and select Compatible Devices...
    Adapter Settings Compatible Devices Button
  3. Select your desired network adapter and click Install.
    • The adapter must appear under the Compatible devices section. If the adapter is listed under Incompatible devices, it cannot be used with TwinCAT.
      Compatible Adapters List
  4. Close the previous window.
  5. Click Search....
    Adapter Settings Search Button
  6. Select your desired network adapter and click OK.
    Select Adapter Dialog

Your network adapter is now properly configured to function as an EtherCAT master with TwinCAT.

  • Information about the adapter can be seen in the TwinCAT interface.
    Adapter Settings

Configuring System Base Time

The system base time represents the minimum possible TwinCAT cycle time on each CPU core. This time can be configured independently for different cores. Specific TwinCAT tasks can also be allocated to certain cores. For performance reasons it may be beneficial to put certain fast processes onto one specific core.

To adjust the system base time:

  1. Expand the SYSTEM tree, and double click Real-Time.
    • This will open the list of cores and tasks on the EtherCAT master.
      Real-Time Menu
  2. Click Read from Target.
    • This will list all the available cores on your machine.
  3. Select your desired base time for the given core.
    System Base Time Selection
  4. If needed, adjust the core for any TwinCAT tasks.
    • This can be useful if one core has a high CPU usage.
      Task Core Selection

Configuring Process Data

The default process data configuration on the E-MCC will usually suffice for basic motion purposes. However, in certain cases it may be desirable to modify the process data. One particular example is for non-encoder devices; it is desirable to remove the Position Actual Value and Following Error Actual Value objects because these values are invalid without a position feedback sensor.

There are three methods to adjust process data:

  1. Changing Modules - Simple for basic changes
  2. Adjusting Modules Process Data - Recommended for axis specific changes
  3. Manually Adjusting Process Data - For other changes


Note: Any time the TwinCAT process data has changed, Activate Configuration needs to be clicked to apply the new configuration to your physical EtherCAT network.

Changing Modules

Modules/Slots provide convenient presets of process data which can be assigned individually to an E-MCC axis.

To modify the module configuration:

  1. Select the E-MCC in the I/O tree, then open the Slots tab.
    • This allows viewing the existing module configuration for each axis, and list of available modules.
      Slave Device Slots Tab
  2. To un-assign a module, select it and click the X button.
    Unassign Module Button
  3. To assign a new module, select it and click the < button.
    Assign Module Button
  4. The process data objects for the assigned module can be viewed in the I/O tree.
    • Note: Process data for a specific module always appears under a separate sub-item (Module 1) beneath the E-MCC.
      IO Tree Module Process Data

Adjusting Modules Process Data

If you desire more process data configurability than what the default modules provide, it’s possible to manually edit the process data assigned by the module.

To manually edit the module’s process data:

  1. Select the E-MCC in the I/O tree, then open the Process Data tab.
    • This tab can be used to manually edit all process data on the E-MCC.
      Process Data Tab
  2. Select the process data (PDO) mapping for the module you want to edit.
    • Module input mappings start at index 0x1B00 + 0x010 per axis.
    • Module output mappings start at index 0x1700 + 0x010 per axis.
      Module TxPDO Mapping Selection
  3. The contents of the PDO mapping can be seen in the PDO Content list below. To remove an object, right click on it and select Delete. Click Yes to delete the item.
    • In this example, we’ll remove Position Actual Value (object 0x6064).
      Module TxPDO Mapping Delete
  4. In the I/O tree, confirm that your process data has been modified correctly.
    • Tip: If you’ve made a mistake, un-assigning and re-assigning the module will reset any module specific PDO mappings to the module’s default objects.
      IO Tree TxPDO View

Manually Adjusting Process Data

In addition to modules, the E-MCC has eight PDO mappings intended for general purpose use:

  • Four input mappings (0x1A00 - 0x1A03)
  • Four output mappings (0x1600 - 0x1603)

By default these mappings are unassigned. However, if you want to transfer general purpose process data it is recommended to use these mappings.

To use these general purpose PDO mappings:

  1. Select the E-MCC in the I/O tree, then open the Process Data tab.
    • This tab can be used to manually edit all process data on the E-MCC.
      Process Data Tab
  2. Select the PDO mapping you want to edit.
    • We’ll edit TxPDO Mapping 1 (0x1A00) in this example.
      TxPDO Mapping 1 Selected
  3. With the mapping selected, right click on the empty PDO Content line and click Add New Item....
    Add New PDO Item
  4. Select the object you want to add to the PDO mapping and click OK.
    • Note: Only certain objects can be PDO mapped. Available objects will show up on the list.
      Edit PDO Entry Dialog
  5. To assign (activate) the PDO mapping, click Inputs and select the checkbox next to the corresponding mapping (0x1A00 for this example).
    • Note: If you’re working with RxPDO mappings, select Outputs instead of Inputs.
      PDO Mapping Assignment
  6. In the I/O tree, confirm that your changes have been applied.
    • Note: Because 0x1A00 is a general purpose mapping, it is displayed under the E-MCC instead of Module 1.
      General Purpose Mapping Completed

This procedure is the same for input and output (Tx and Rx) PDO mappings. PDO mappings can also be unassigned in a similar manner.

Homing an Axis

TwinCAT does not include default homing support for third party drives like Zaber’s E-MCC. The E-MCC uses CiA 402 Operation Mode 6 (HM mode) for homing, which is also known as drive based homing. There are two recommended methods to use drive based homing in TwinCAT:

  1. Homing Manually
  2. Homing From a PLC Project


Manual homing is convenient if you haven't setup a PLC project yet. For most use-cases, you'll want to perform homing in the PLC project.

Note: An un-homed axis will transmit an emergency message with error code Hex: 8680 upon the ESM entering OP state. Once homing has completed, another emergency message with error code Hex: 0000 will be transmitted to indicate the warning has been cleared.

Homing Emergency Messages

Homing Manually

To home an axis manually:

  1. Ensure TwinCAT is in Run Mode.
  2. Expand the I/O tree to view the process data of your axis.
    I/O Tree Process Data
  3. Right click on Modes of Operation. Click Online Force... and set the value to 6 (decimal).
    • This temporarily overrides the EtherCAT process data and forces the axis into homing mode (CiA 402 mode 6).
      Op Mode Online Force Online Force Dialog
  4. Right click on Controlword and select Online Force.... Set the value to 15 (decimal).
  5. Repeat the last step and Online Force the Controlword value to 31 (decimal).
    • This will initiate the homing process.
    • Value 31 (decimal) raises the first 5 bits of object 0x6040 ControlWord. A rising edge of bit 5 causes homing to initiate.
  6. Once homing is completed, you will see the error Hex: 0000.
    • This indicates the previous error has been cleared (homing has completed).
      Homing Completed Emergency Message
  7. Right click on Controlword and select Release Force.
    • This returns control of the process data to the NC Axis.
      ControlWord Release Force
  8. Right click on Modes of Operation and select Release Force.
    • This returns control of the process data to the NC Axis.

Homing From a PLC Project

Zaber provides example code with a function block FB_HomeDriveBased to perform homing from a PLC project. This function block adheres to standard PLCopen programming conventions.

Homing Function Block Overview

Download: Zaber TwinCAT Homing Example.zip

This code can be directly opened, run, and modified as a TwinCAT PLC project. However, for simple re-use it is recommended to save the PLC project as a TwinCAT library. See Library Creation for more details from Beckhoff.

To use the example code as a library:

  1. Download the project and open Zaber TwinCAT Homing Example.sln.
  2. Expand the PLC tree. Right click on HomingExample Project and select Save as library and install....
    Save Project as library
  3. Save the file HomingExample.compiled-library to a folder of your choice.
    • Note: It is not required to keep this file. TwinCAT will automatically install it to your library repository folder (usually C:\ProgramData\Beckhoff\TwinCAT\PlcEngineering\Managed Libraries).
      Save Project Dialog
  4. Close the example project.
  5. Create a new TwinCAT XAE project, or open an existing project of your choice.
  6. If creating a new project, right click on PLC and select Add New Item....
    PLC Add Item Button
  7. Add a new Standard PLC Project with the name of your choice.
    Add Project Dialog
  8. Expand the PLC project. Right click on References and select Add library....
    Add Library Button
  9. Select HomingExample and click OK.
    Add Library Dialog
  10. The library should be added to your PLC project.
    Homing Project Library Added
  11. The FB_HomeDriveBased function block is now ready for use in your PLC project. For more information, double click on the library and expand the POUs section to view available function blocks in the library.
    • This includes documentation on the function block’s inputs and outputs.
      Library Documentation