You are on page 1of 51

Application Note EL9800

Section I Getting started Section II Slave Sample Code

Version 1.0 Date: 2010-01-05

LEGAL NOTICE

Trademarks Beckhoff, TwinCAT, EtherCAT, Safety over EtherCAT, TwinSAFE and XFC are registered trademarks of and licensed by Beckhoff Automation GmbH. Other designations used in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owners. Patent Pending The EtherCAT Technology is covered, including but not limited to the following German patent applications and patents: DE10304637, DE102004044764, DE102005009224, DE102007017835 with corresponding applications or registrations in various other countries. Disclaimer The documentation has been prepared with care. The products described are, however, constantly under development. For that reason the documentation is not in every case checked for consistency with performance data, standards or other characteristics. In the event that it contains technical or editorial errors, we retain the right to make alterations at any time and without warning. No claims for the modification of products that have already been supplied may be made on the basis of the data, diagrams and descriptions in this documentation. Copyright Beckhoff Automation GmbH 05/2009. The reproduction, distribution and utilization of this document as well as the communication of its contents to others without express authorization are prohibited. Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of a patent, utility model or design.

I-II

Application Note EL9800

DOCUMENT HISTORY Version 0.1 0.2 Comment


Documentation based on EL9800_2 (PIC18) Add EtherCAT piggyback notes Additional Instructions for PIC24 Evaluation board (EL9800_4A) Note for EL9800 / FB1111-014x setup Add Section II Chapter 2 Slave Sample Code

1.0

Application Note EL9800

I-1

Application Note EL9800

Section I Getting Started

Version 0.2 Date: 2009-07-31

LEGAL NOTICE

Trademarks Beckhoff, TwinCAT, EtherCAT, Safety over EtherCAT, TwinSAFE and XFC are registered trademarks of and licensed by Beckhoff Automation GmbH. Other designations used in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owners. Patent Pending The EtherCAT Technology is covered, including but not limited to the following German patent applications and patents: DE10304637, DE102004044764, DE102005009224, DE102007017835 with corresponding applications or registrations in various other countries. Disclaimer The documentation has been prepared with care. The products described are, however, constantly under development. For that reason the documentation is not in every case checked for consistency with performance data, standards or other characteristics. In the event that it contains technical or editorial errors, we retain the right to make alterations at any time and without warning. No claims for the modification of products that have already been supplied may be made on the basis of the data, diagrams and descriptions in this documentation. Copyright Beckhoff Automation GmbH 05/2009. The reproduction, distribution and utilization of this document as well as the communication of its contents to others without express authorization are prohibited. Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of a patent, utility model or design.

I-II

Application Note EL9800

DOCUMENT HISTORY Version 0.1 0.2 Comment


Documentation based on EL9800_2 (PIC18) Add EtherCAT piggyback notes Additional Instructions for PIC24 Evaluation board (EL9800_4A) Note for EL9800 / FB1111-014x setup

Application Note EL9800

I-1

CONTENTS 1 2 GENERAL NOTES Software installation 2.1 2.2 2.3 2.4 2.5 2.6 3 3.1 MPLAB IDE HI-TECH PICC-18 STD Microchip C30 compiler HI-TECH Universal Toolsuite plugin for MPLAB (optional) MPLAB ICD2 driver TwinCAT installation 6 7 7 7 8 9 9 9 10 10 Install Ethernet real-time driver Setup an EtherCAT network Distributed Clocks 10 11 12 15 Recommend EL9800 / FB1111-014x setup EEPROM 15 15 17 17 19 20 22 22 28

EtherCAT setup Master 3.1.1 3.1.2 3.1.3 3.2 Slave 3.2.1 3.2.2

Slave Sample Code 4.1 4.2 4.3 Create Project Project settings 4.2.1 4.3.1 Compiler/PIC specific settings

Download binary Debugger

Known issues

I-2

Application Note EL9800

FIGURES Figure 1: Execute Installation file ............................................................................................................ 7 Figure 2: Select setup type ..................................................................................................................... 7 Figure 3: Compiler installation ................................................................................................................ 7 Figure 4: Installation type ........................................................................................................................ 8 Figure 5: Activation successful ............................................................................................................... 8 Figure 6: Additional software .................................................................................................................. 8 Figure 7: Driver installation ..................................................................................................................... 9 Figure 8: TwinCAT installation level........................................................................................................ 9 Figure 9: Real time driver...................................................................................................................... 10 Figure 10: Real time driver installation menu........................................................................................ 10 Figure 11: Perform device scan ............................................................................................................ 11 Figure 12: Successful device scan ....................................................................................................... 12 Figure 13: Master startup behaviour ..................................................................................................... 12 Figure 14: Append task ......................................................................................................................... 13 Figure 15: Insert variable ...................................................................................................................... 13 Figure 16: Variable type ........................................................................................................................ 13 Figure 17: Link new variable ................................................................................................................. 14 Figure 18: Enable Auto start ................................................................................................................. 14 Figure 19: Reload Devices.................................................................................................................... 15 Figure 20: Select EEPROM update ...................................................................................................... 15 Figure 21: device descriptions .............................................................................................................. 16 Figure 22: TwinCAT status ready ......................................................................................................... 16 Figure 23: Create a new Project ........................................................................................................... 17 Figure 24: Project Details...................................................................................................................... 17 Figure 25: Activate Project Manager..................................................................................................... 17 Figure 26: Add source files ................................................................................................................... 18 Figure 27: Select source files................................................................................................................ 18 Figure 28: Select tools .......................................................................................................................... 19 Figure 29: Selection of the controller .................................................................................................... 19 Figure 30: HI-TECH Toolsuite............................................................................................................... 20 Figure 31: Heap setting for Microchip C30 compiler............................................................................. 20 Figure 32: Compiler Settings................................................................................................................. 21 Figure 33: PIC define ............................................................................................................................ 21 Figure 34: Rebuild Project..................................................................................................................... 22 Figure 35: Build succeed output ........................................................................................................... 22 Figure 36: Select "MPLAB ICD 2" ......................................................................................................... 23 Figure 37: ICD 2 setup wizard............................................................................................................... 23 Figure 38: Communication interface selection...................................................................................... 23 Figure 39: Power supply selection ........................................................................................................ 24 Figure 40: Auto connect ........................................................................................................................ 24 Figure 41: Download OS....................................................................................................................... 24 Figure 42: Connect to debugger ........................................................................................................... 25 Figure 43: Download warning ............................................................................................................... 25 Figure 44: Output window: connection successful................................................................................ 25 Figure 45: Program PIC memory .......................................................................................................... 26 Figure 46: Output window: Programming successful ........................................................................... 26 Figure 47: Run binary............................................................................................................................ 27

Application Note EL9800

I-3

Table Table 1: Used Software............................................................................................................................6 Table 2: Used Hardware ..........................................................................................................................6 Table 3: EL9800 / piggyback setup........................................................................................................15

I-4

Application Note EL9800

ABBREVIATIONS DC EEPROM I/O ICD IDE NIC OS PDI PIC PICC PDO RT SDO SM SPI SSC Distributed clocks Electrically erasable programmable read only memory Input/Output In circuit debugger Integrated development environment Network interface card Operating system Process data interface Peripheral interface controller PIC compiler Process Data Object Real Time Service data object Sync Manager Serial peripheral interface Slave sample code

Application Note EL9800

I-5

GENERAL NOTES

This document helps to start working with the Slave Sample Code for Evaluation Board PIC. Workshops and Trainings referred to the Slave Sample Code listed in the events section on ETG website (http://www.ethercat.org). The software and hardware used to create this manual are listed in Table 1 and Table 2. Table 1: Used Software Software Name Code Beckhoff EtherCAT Slave Sample Code Compiler Compiler Compiler IDE OS EtherCAT Master HI-TECH PICC-18 STD Microchip C30 HI-TECH Universal Toolsuite plugin for MPLAB MPLAB IDE Microsoft Windows TwinCAT Version(2009.03.06) 4.10 Comment Beckhoff ftp server (please see SSC Update mail)
http://www.htsoft.com

9.51PL2 3.02 1.31 8.20 XP SP3 2.10 Build 1334

http://www.microchip.com
http://www.htsoft.com http://www.microchip.com http://www.beckhoff.com

Table 2: Used Hardware Hardware Evaluation board Evauation board EtherCAT piggyback controller EtherCAT piggyback adapter Name EL9800 EL9800 FB11110142 EL9803 Version(2009.03.06) 2 (PIC18) 4A (PIC24) Comment http://www.beckhoff.com http://www.beckhoff.com http://www.beckhoff.com http://www.beckhoff.com

Its also possible to use other software / hardware to develop EtherCAT slaves based on the SSC but the listed tools are tested and well known.

I-6

Application Note EL9800

2
2.1

Software installation
MPLAB IDE Unzip MPLAB_v8.20.zip Execute Install_MPLAB_v820.exe

Figure 1: Execute Installation file

Select Complete installation

(To handle the SSC not all components from the MPLAB IDE are required but in the first move its recommend to install the complete package.)

Figure 2: Select setup type

Dont install the HCPIC18-pro-960PL5 compiler

Figure 3: Compiler installation

2.2

HI-TECH PICC-18 STD

This compiler is desired to compile the slave sample code for Evaluation boards up to version EL9800_2 (PIC18 C). If a board with a PIC24 C is used (EL9800_4A or later) go to step 2.3) Execute HCPIC18-std-9.51PL2.exe Ensure that internet connection is available Select Activate demo with 45 day evaluation license Application Note EL9800 I-7

Figure 4: Installation type

If the terms of license agreement are accepted the Activation successful message box appears

Figure 5: Activation successful

Uncheck HI-TIDE Integrated Development Environment

Figure 6: Additional software

2.3

Microchip C30 compiler

The Microchip compiler is desired for PIC24 versions of the Evaluation board EL9800 Download the Microchip C30 compiler from the Microchip homepage Execute the setup (the installation routine is self-explanatory)

I-8

Application Note EL9800

2.4

HI-TECH Universal Toolsuite plugin for MPLAB (optional)

The Toolsuite is recommended if the MPLAB IDE is used with several compilers. (If the HCPIC18pro-960PL5 compiler was installed within the MPLAB IDE installation the HI-TECH Toolsuite shall be install) 2.5 MPLAB ICD2 driver Connect the USB-cable with the evaluation board and the PC Set SW600 (>= EL9800.4) or SW800 (<= EL9800.2) to enable the onboard debugger interface. Power on the evaluation board A new device is detected on the PC Select automatic installation

Figure 7: Driver installation

2.6

TwinCAT installation A 30 days trail version is available on evaluation Kit CD or can be downloaded from http://www.beckhoff.com/english/twincat/tcatdow.htm?id=34792042844 Run the setup and select TwinCAT PLC installation level.

Figure 8: TwinCAT installation level

Include the device description for the evaluation board to TwinCAT. Copy el9800-V410.xml from the xml-folder on the CD delivered with the EL9800 to <TwinCAT installation folder>\Io\EtherCAT\ (default: c:\TwinCAT\Io\EtherCAT\) To update the device database TwinCAT needs to restart.

To register TwinCAT installation please contact sales@beckhoff.com Application Note EL9800 I-9

3
3.1

EtherCAT setup
Master Install Ethernet real-time driver

3.1.1

Start TwinCAT System Manager Open [Options] [Show Real Time Ethernet Compatible Devices]

Figure 9: Real time driver

All available network cards are listed

Figure 10: Real time driver installation menu

NOTE: Installed and ready to use devices NICs for which the TwinCAT RT-Ethernet intermediate driver* or the Beckhoff Ethernet driver* was installed Compatible devices NICs which are compatible to the Beckhoff Ethernet driver* but not installed yet

I-10

Application Note EL9800

Incompatible devices NICs which are not installed yet and accessible by the TwinCAT RT-Ethernet intermediate driver*. Only NICs which are shown within Installed and ready to use devices can be used for EtherCAT purpose. To add a NIC to the Installed and ready to use devices list select the device and click install. *the Beckhoff Ethernet driver shall be used for high real time requirements. A list of compatible NICs are listed on http://infosys.beckhoff.com/english.php?content=content/1033/tcsystemmanager/reference/ethercat/ht ml/ethercat_supnetworkcontroller.htm The TwinCAT RT-Ethernet intermediate driver provides also an EtherCAT interface but without high real time behaviour. This driver is sufficient for basic EtherCAT functionality. Some applications/services (e.g. firewalls) may disturb access to the real time driver interface. In first place disable all applications/services which access the selected network card 3.1.2 Setup an EtherCAT network

Connect the IN port of the EtherCAT piggyback controller with your installed and ready to use network card Perform automatic device scan: right mouse click on [I/O Devices] [Scan Devices]

Figure 11: Perform device scan

A device window is shown. Select only the device which is connected to the EL9800 evaluation board click [OK] Acknowledge scan for Boxes message with [YES] Activate Free Run

Application Note EL9800

I-11

Figure 12: Successful device scan

In this configuration the evaluation board operates in digital I/O mode. The PDI selector(S200) shall be set to 4. Distributed Clocks

3.1.3

If the slave supports DC the master requires a sync task to trigger cyclic events. This could be a simple task (chapter 3.1.3.1) or a PLC project. The sync task shall set to Auto start and linked to an I/O device. If the sync task is missing the master remains in PRE-OP State. This setting is enabled by default. Select [Device xx (EtherCAT)] tab [EtherCAT] [Advanced Settings]

Figure 13: Master startup behaviour

3.1.3.1

Additional task right mouse click on [Additional Task] [Append Task]

Expand [System configuration]

I-12

Application Note EL9800

Figure 14: Append task

Insert a output variable to the task: right mouse click on [outputs]

[Insert Variable]

Figure 15: Insert variable

Select variable type BIT and click [OK]

Figure 16: Variable type

Create a connection with the new variable and one of the digital outputs. (Double click on the new variable and select LED 1)

Application Note EL9800

I-13

Figure 17: Link new variable

Select the new task and check Auto start

Figure 18: Enable Auto start

Reload device to apply changes: [Actions]

[Reload Devices]

I-14

Application Note EL9800

Figure 19: Reload Devices

3.2 3.2.1

Slave Recommend EL9800 / FB1111-014x setup

In this case the target C for the slave sample code is the C mounted on the EL9800 which is connected via SPI to the ESC. Consequently a piggyback with SPI PDI is required. Table 3: EL9800 / piggyback setup < = EL9800_2 >= EL9800_4A 3.2.2 EEPROM FB1111-0141 valid NOT valid FB1111-0142 Only with EL9803 valid

Depending on the ESC configuration the EEPROM content must be updated. All available configurations for the EL9800 are described in el9800-Vxxx.xml located in the XML folder on the CD shipped with the EL9800 (see chapter 2.6 TwinCAT installation). Referring to the partitions and content of the EEPROM take a look at the EtherCAT Knowledge Base->EtherCAT Technology Description->EEPROM/SII For Safety reasons set the PDI selector (S200) to 0 before each EEPROM update Select [Device xx (EtherCAT)] tab [online] right mouse click on the listed device [EEPROM Update]

Figure 20: Select EEPROM update

In the following window all available device descriptions are listed Application Note EL9800 I-15

Figure 21: device descriptions

Eva Board (Sample Source Demos) 0100-0001) and click OK

Select EL9800(Vx.xx)(PICxx, SPI,ET1100) (EL9800-

If the device is not listed include the device description (chapter 2.6 TwinCAT installation) Dont power down the evaluation board while updating the EEPROM! After successful update the TwinCAT status is set to ready

Figure 22: TwinCAT status ready

Reset the evaluation board (power down power up) so the ESC loads the new EEPROM content. Create a new configuration [file] [new] and repeat chapter 3.1.2 Setup an EtherCAT network Set the PDI selector (S200) to 5 Confirm that the used EtherCAT piggyback is compatible to the selected PDI. For more information see FB11xx datasheets on the Beckhoff download website!

I-16

Application Note EL9800

4
4.1

Slave Sample Code


Create Project Copy the source files from the SPI folder on CD delivered with the EtherCAT evaluation board EL8900 to a folder on the hard disk (e.g. c:\SSC_410\SPI\) Open the MPLAB and click [Project] [New] in menu bar.

Figure 23: Create a new Project

Enter a name and the path where you want to store the project file and all other created files. Then press the [OK] button.

Figure 24: Project Details

If the project manager is not already displayed in MPLAB choose [View]

[Project] in menu bar.

Figure 25: Activate Project Manager

To add the SSC source files select [Project]

[Add Files to Project] in menu bar.

Application Note EL9800

I-17

Figure 26: Add source files

Select all *.c and *.h files except of mcihw.c and mcihw.h. Then press [Open] button. You can also add all files and delete the two mcihw.* files afterwards from project manager.

Figure 27: Select source files

I-18

Application Note EL9800

4.2

Project settings To select the compiler, linker and assembler choose [Project] menu bar. [Select Language Toolsuite] in

Figure 28: Select tools

Select the corresponding PIC for the EtherCAT slave platform. Therefore click [Configure] [Select Device]. For evaluation boards up to and including version EL9800_2 select PIC18F452. For evaluation boards from version EL9800_4A select PIC24HJ128GP306

Figure 29: Selection of the controller

Choose the corresponding toolsuite - <= EL9800_2: HI-TECH PICC-18 Toolsuite. - >= EL98004A Microchip C30 Toolsuite If necessary correct the path in the location field. Application Note EL9800 I-19

Figure 30: HI-TECH Toolsuite

4.2.1

Compiler/PIC specific settings

Microchip C30 compiler (PIC24): Define a head size (Project->Build Options->Project-> tab MPLAB LINK30)!

Figure 31: Heap setting for Microchip C30 compiler

I-20

Application Note EL9800

HI-TECH PICC-18 STD compiler (PIC18): Increment the identifier length > 60 and disable code optimization ([Project] [Project] [Compiler] tab).

[Build Options]

Figure 32: Compiler Settings

Confirm that the correct PIC define is set. These defines are located in ecat_def.h.

For EL9800 hardware up to and version 2 select _PIC18. Its not possible to get full feature setup for the PIC18 in addition to other reasons caused by limited program memory. So its necessary to check which features are required for the desired EtherCAT slave. The corresponding defines are located in ecat_def.h. For EL9800 hardware from version 4 select _PIC24

Figure 33: PIC define

To compile the SSC select [Project]

[Rebuild] in menu bar.

Application Note EL9800

I-21

Figure 34: Rebuild Project

An output window with further information appears. The *.hex and *.cof (for debugging) files are created in the project folder.

Figure 35: Build succeed output

4.3 4.3.1

Download binary Debugger

The Evaluation Kit from hardware version 4 supports two PIC debugger interfaces. One fixed connected to onboard ICD 2 debugger (communication channel 3) and an open interface on J1005 (communication channel 2). The In-Circuit Debugger register need to be configured depending on the desired interface. The register is set in ecatappl.c. fixed connected debugger: _FICD(ICS_PGD3 & JTAGEN_OFF); open interface: _FICD(ICS_PGD2 & JTAGEN_OFF);

The following instructions referring to the fixed connected onboard ICD 2 debugger.

I-22

Application Note EL9800

Enable the on board debugger interface. Set dipswitch SW600 (>= EL9800.4) or SW800 (<=EL9800.2) to on All EL9800 EtherCAT development boards contain a MPLAB ICD 2 onboard debugger. So select the "MPLAB ICD 2.

Figure 36: Select "MPLAB ICD 2"

The MPLAB ICD2 setup wizard start up

Figure 37: ICD 2 setup wizard

Select USB

Figure 38: Communication interface selection

Select Target has own power supply

Application Note EL9800

I-23

Figure 39: Power supply selection

Dont check automatic connection

Figure 40: Auto connect

Check automatic download operating system

Figure 41: Download OS

Connect to debugger

I-24

Application Note EL9800

Figure 42: Connect to debugger

Acknowledge the download warning with [OK]

Figure 43: Download warning

Output if connection succeeds

Figure 44: Output window: connection successful

Application Note EL9800

I-25

Download the binary file

Figure 45: Program PIC memory

Output if programming succeeds

Figure 46: Output window: Programming successful

Select [Debugger]

[Run]

I-26

Application Note EL9800

Figure 47: Run binary

Application Note EL9800

I-27

Known issues
Issue Possible workaround Software / Platform

Compiler / Code Editor could be caused by trimming defines to 31 chars (default identifier length) Compiler warning: => increase the maximal identifier length redefining preprocessor macro ([Project] [Build Options] [Project] tabcompiler) Set SDO to online update causes EtherCAT error: disable code optimization abnormal state change (from OP to ([Project] [Build Options] [Project] Invalid(xx)).Go to INIT and try get tabcompiler) back to OP Compiler error: Required Program memory exceeds can't find 0xxxx words (0xxxx withtotal) available memory for psect "text" in segment "CODE" Undefined (exclude) Code modules unable to connect to debugger or use older debugger driver or an old eg. general debugger connection problems 8.20 MPLAB IDE version Running Code Confirm the slave sample code is running (if the binary was downloaded The EtherCAT slave remains in INITwith the debugger the program needs a state run trigger to start) The EtherCAT slave supports DC an dont get to OP state The downloaded release binary dont starts up The master needs a sync task (chapter 3.1.3 Distributed Clocks) Disable the debugger interface.

-HI-TECH PICC18 STD (9.51PL2)

-HI-TECH PICC18 STD (9.51PL2) -HI-TECH PICC18 STD (9.51PL2) MPLAB IDE 8.40

I-28

Application Note EL9800

Application Note EL9800

Section II Slave Sample Code

Version 1.0 Date: 2010-01-05

LEGAL NOTICE

Trademarks Beckhoff, TwinCAT, EtherCAT, Safety over EtherCAT, TwinSAFE and XFC are registered trademarks of and licensed by Beckhoff Automation GmbH. Other designations used in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owners. Patent Pending The EtherCAT Technology is covered, including but not limited to the following German patent applications and patents: DE10304637, DE102004044764, DE102005009224, DE102007017835 with corresponding applications or registrations in various other countries. Disclaimer The documentation has been prepared with care. The products described are, however, constantly under development. For that reason the documentation is not in every case checked for consistency with performance data, standards or other characteristics. In the event that it contains technical or editorial errors, we retain the right to make alterations at any time and without warning. No claims for the modification of products that have already been supplied may be made on the basis of the data, diagrams and descriptions in this documentation. Copyright Beckhoff Automation GmbH 05/2009. The reproduction, distribution and utilization of this document as well as the communication of its contents to others without express authorization are prohibited. Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of a patent, utility model or design.

II-II

Application Note EL9800

DOCUMENT HISTORY Version 1.0 Comment


Description of the CiA402 implementation (based on Slave Sample Code V4.30)

NOTE: This document makes no claim to be complete regarding to the containing topics or the slave sample code. For annotations or comments to this document please send an email to EthercatSSC@beckhoff.com.

Application Note EL9800

II-1

CONTENTS 1 2 References CiA402 drive profile 2.1 2.2 2.3 2.4 Objects State machine Operation modes TwinCAT setup 2.4.1 2.4.2 2.4.3 3 Known issues Automatic network setup Manual network setup NC parameter setup 6 7 7 9 10 11 12 12 14 15

II-2

Application Note EL9800

FIGURES Figure 1: CiA402 state transitions and option codes............................................................................... 9 Figure 2: Axis configuration ................................................................................................................... 11 Figure 3: Set device variable without PLC link ...................................................................................... 11 Figure 4: Scan for new EtherCAT devices ............................................................................................ 12 Figure 5: CiA402 axis setup .................................................................................................................. 12 Figure 6: Add CiA402 device................................................................................................................. 13 Figure 7: Link multiple variables............................................................................................................ 13 Figure 8: Encoder scaling...................................................................................................................... 14 Figure 9: Velocity scaling....................................................................................................................... 14

Application Note EL9800

II-3

TABLES Table 1: Object definitions in file cia402appl.h .................................................................................. 8 Table 2: State machine.......................................................................................................................... 10 Table 3: Linking of device and NC variables ......................................................................................... 13

II-4

Application Note EL9800

ABBREVIATIONS CiA csp csv DC NC PDO PLC SM CAN in Automation cycle synchronous position cycle synchronous velocity Distributed Clocks Numeric Control Process Data Object Programmable Logic Controller Sync Manager

Application Note EL9800

II-5

References
[1] ETG Implementation Guideline for the CiA402 Drive Profile (V0.2.0)

II-6

Application Note EL9800

CiA402 drive profile

Since version 4.30 the slave sample code contains a sample implementation of the CiA402 drive profile as described in [1] . This implementation provides the interface between the motion controller application and communication layer. Following features are supported: CiA402 objects (see chapter 2.1 Objects) CiA402 state machine (see chapter 2.2 State machine) This implementation supports cyclic synchronous position (csp) and cyclic synchronous velocity (csv) operation modes.

CiA402 specific files: cia402appl.c : CiA402 drive profile implementation cia402appl.h : Drive profile specific objects, definitions and axes structures All motion controller related values are encapsulated in structure TCiA402Axis (file: cia402appl.h). The configuration parameters and error codes are directly mapped to the corresponding objects. The process data objects are updated in the input/output mapping functions (file: ecatappl.c). Currently the sample supports maximum of two axes. The axes are initialized in the EtherCAT state change from PREOP to SAFEOP. The motion controller is a simple integration, which just copies the target values to the actual values (see chapter 2.3 Operation modes). 2.1 Objects

All CiA402 specific objects are defined in file cia402appl.h. All mandatory and some optional object are defined in this sample implementation. Table 1 contains a list of all defined objects. the object variables are located in the structure CiA402Objects.

Application Note EL9800

II-7

Table 1: Object definitions in file cia402appl.h Index Object name Variable in source code 0x1600 0x1601 0x1602 0x1A00 0x1A01 0x1A02 Rx PDOs Rx PDOs Rx PDOs Tx PDOs Tx PDOs Tx PDOs SyncManger 2 PDO assign (Rx PDOs) SyncManger 3 PDO assign (Tx PDOs) Error Code Controlword Status word Quick stop option code Shutdown option code Disable operation option code Fault reaction option code Modes of operation Modes of operation display Position actual value Velocity actual value Torque actual value Target position Software position limit Quick stop declaration Interpolation time period Target velocity Supported drive modes sRxPDOMap0 sRxPDOMap1 sRxPDOMap2 sTxPDOMap0 sTxPDOMap1 sTxPDOMap2

0x1C12

sRxPDOassign

Comment/Description includes all objects required for dynamic change between csv/csp includes objects required for csp mode of operation includes objects required for csv mode of operation includes all objects required for dynamic change between csv/csp includes objects required for csp mode of operation includes objects required for csv mode of operation this object is written in change state from PREOP to SAFEOP; the configuration depends on the number of axes (not include in CiA402Objects) equal to 0x1C12 (not include in CiA402Objects) this value shall be set if an error in the PDS occurs object for the output commands from the master current axis status predefined ramp if an quick stop shall be performed predefined action in state transition 8 predefined action in state transition 5 predefined action in state Fault reaction active requested operation mode current operation mode current position value (delivered by encoder) velocity feedback currently not used (only for completion) requested Postion value (set in csp mode) includes the minimum and maximum actual position limit predefined action in state Quick stop active

0x1C13 0x603F 0x6040 0x6041 0x605A 0x605B 0x605C 0x605E 0x6060 0x6061 0x6064 0x606C 0x6077 0x607A 0x607D 0x6085 0x60C2 0x60FF 0x6502

sTxPDOassign objErrorCode objControlWord objStatusWord objQuickStopOptionCode objShutdownOptionCode objDisableOperationOptionCode objFaultReactionCode objModesOfOperation objModesOfOperationDisplay objPositionActualValue objVelocityActualValue objTorqueActualValue objTargetPosition objSoftwarePositionLimit objQuickStopDeclaration objInterpolationTimePeriod objTargetVelocity objSupportedDriveModes

target velocity requested by the master list of all supported operation modes

II-8

Application Note EL9800

The objects from 0x6000 to 0x67FF are incremented with 0x800 for each axis (Index + #Error! Bookmark not defined. *0x800). 2.2 State machine

Figure 1 shows the state machine described in [1] . State changes are requested by setting 0x6040 (Controlword) or by a local event (if an error occurs). If the device is in state OP the transitions 0, 1 and 2 are skipped. The option codes next to the transition lines indicate that a specific action which shall be performed in of one of these state changes. All handled state transitions including the required Controlword, resulting state and corresponding functions are listed in Table 2: State machine. The bits 0,1,2,3 and 7 of the control word are taken into consideration in this sample implementation. Drive functions e.g.Break applied or Axis function enabled need to be activated or deactivated corresponding to the current state. In this sample these functions are handled by Boolean variables.

Figure 1: CiA402 state transitions and option codes

Application Note EL9800

II-9

Table 2: State machine Control word bits Bit 3 (enable operation) Bit 1 (enable voltage) Bit 2 (quick stop) Bit 7 (fault reset) Bit 0 (switch on) bBrakeApplied Variable (Function) bHighLevelPower Applied bLowLevelPower Applied bConfiguration Allowed bAxisFunction Enabled

Transition

Resulting state

3 4 5 6 7 8 9 10 11 12 13 14 15 16

0 0 0 0 0 0 0 0 0 0 0 0

x 1 0 x x x x x x x x x

1 1 1 1 x 0 1 x x 0 0 x

1 1 1 1 0 1 1 0 0 1 1 0

1 1 1 0 x x 0 x x x x x

Switched on Operation enabled Switch on Ready to switch on Switch on disabled Ready to switch on Switch on disabled Switch on disabled Quick stop active Switch on disbaled Fault reaction active Fault

true false true true true true true true false true false true true false

true true true true true true true true true true true true true true

true true true false false false false false true false true false false true

false true false false false false false false true false true false false true

true false true true true true true true false true false true true false

Triggered by application Transition if option code 0x605E is finished 1 x x x x

After quick stop always goto Switch on disabled

Switch on disabled (Operation enabled)

The transition number in Table 1 referring to the transition number in Figure 1.[1] 2.3 Operation modes

In general this sample supports the csv and csp mode of operation. Each axis can be configured as csv, csp or combined controller via modules (Figure 2). In last case the mode of operation can be switch dynamically. For this reason all objects required for motion control are mapped to PDOs. In the current TwinCAT Version (2.11 build 1539) the NC task doesnt provide a variable for the objects 0x6060 (Mode of operation) and 0x6061 (Mode of operation display), so these objects values need to be directly provided by the PLC. The motion controller function (CiA402_DummyMotionControl()) just copies the target velocity values to the actual velocity. The actual position is calculated by the actual velocity and the motion controller cycle time. If the device is in SM Sync mode the cycle time is calculated by an internal timer within the first application cycle. In DC Sync mode the cycle time is set to Sync0 cycle value.

II-10

Application Note EL9800

Figure 2: Axis configuration

NOTE: This sample doesnt provide a target value overflow control! 2.4 TwinCAT setup

This chapter describes the setup of motion control loop over EtherCAT. It is based on TwinCAT Version V2.11 build 1539. At least the TwinCAT level NC is required. The position control is located on the EtherCAT master so in this case only the target velocity and actual position need to be linked to the NC task. The mode of operation shall be set to cyclic synchronous velocity mode (csv). For the corresponding objects 0x6061 (Mode of operation display) and 0x6060 (Mode of operation) is no NC axis variable reserved. So these drive variables should be mapped direct to the PLC application. For testing purposes 0x6060 (Mode of operation) could be set manually at each EtherCAT master restart.

Figure 3: Set device variable without PLC link

Application Note EL9800

II-11

2.4.1

Automatic network setup

The TwinCAT System Manger provides a comfortable master setup. Open a new System Manager configuration and scan the network for new devices (Figure 4).

Figure 4: Scan for new EtherCAT devices

After the network scan is complete a message box appears with a notification that an EtherCAT drive was found. If the this message is acknowledged with Yes the System Manager will automatically create an NC task with the correct process data mapping. 2.4.2 Manual network setup

First add a NC task including a CiA402 Axis to the System configuration. Add NC task ->Add continuous Axis -> set Axis type to CANopen DS402 (see Figure 5).

Figure 5: CiA402 axis setup

Add a new EtherCAT device and append the device EL9800 (Vx.xx/CiA402) (PIC24, SPI, ET1100) (Figure 6).

II-12

Application Note EL9800

Figure 6: Add CiA402 device

Now the device variables (objects) need to be linked to the axis variables as shown in Table 3. Table 3: Linking of device and NC variables variable name object index type device NC axis 0x6040 output Controlword Drive_Out -> nCtrl1 + nCtrl2 0x60FF output Target velocity Drive_Out -> nOutData2 0x6041 input Statusword Drive_In -> nStatus1 + nStatus2 0x6064 input Actual position Enc_In -> nInData1

For the Stausword and Controlword continues process data mapping is required. This can be performed in the linking window (eg. Statusword link window Figure 7). Enable All Types, Continuous and select the desired variables. TwinCAT will map nStatus1 to the low byte and nStatus2 to the high byte of the Statusword.

Figure 7: Link multiple variables

Application Note EL9800

II-13

2.4.3

NC parameter setup

It is required to setup the encoder and velocity output scaling in the NC-task of the EtherCAT master according to the drive parameters. The sample implementation not supports user defined factor group objects so the default units are used. Position unit: inc velocity unit: inc/s Encoder resolution: 2^16 inc/rev

If a non predefined drive is used two basic information are required, the target velocity value for 1rev/min (=> target velocity resolution) and the encoder resolution. The encoder resolution defined as 2^16 inc/rev and if 1 rev is equal to 1mm the encoder scaling factor [mm/inc] is 0.0000152588 (Figure 8). Encoder scaling factor formula: enc.scaling = (mm/rev)/encoder resolution

Figure 8: Encoder scaling

The velocity output scaling is calculated with the following formula: velo.scaling = (2^20 / encoder resolution) * (velo resolution / 139,81) The velocity resolution [inc/(1rev/min)] is the numerical increment if 1 rev/min is desired. In this case the ratio is 1 so the velocity scaling factor is 0.114441027(Figure 9).

Figure 9: Velocity scaling

II-14

Application Note EL9800

Known issues
Issue Possible workaround Software / Platform

Application Note EL9800

II-15

Appendix
Support and Service Beckhoff and their partners around the world offer comprehensive support and service, making available fast and competent assistance with all questions related to Beckhoff products and system solutions. Beckhoffs branch offices and representatives Please contact your Beckhoff branch office or representative for local support and service on Beckhoff products! The addresses of Beckhoff's branch offices and representatives round the world can be found on her internet pages: http://www.beckhoff.com You will also find further documentation for Beckhoff components there. Beckhoff Headquarters Beckhoff Automation GmbH Eiserstr. 5 33415 Verl Germany phone: + 49 (0) 5246/963-0 fax: + 49 (0) 5246/963-198 e-mail: info@beckhoff.com web: www.beckhoff.com Beckhoff Support Support offers you comprehensive technical assistance, helping you not only with the application of individual Beckhoff products, but also with other, wide-ranging services: world-wide support design, programming and commissioning of complex automation systems and extensive training program for Beckhoff system components hotline: + 49 (0) 5246/963-157 fax: + 49 (0) 5246/963-9157 e-mail: support@beckhoff.com Beckhoff Service The Beckhoff Service Center supports you in all matters of after-sales service: on-site service repair service spare parts service hotline service hotline: + 49 (0) 5246/963-460 fax: + 49 (0) 5246/963-479 e-mail: service@beckhoff.com EtherCAT Technology Group (ETG) Headquarters Phone: +49 (911) 540 5620 Fax: +49 (911) 540 5629 Email: info@ethercat.org Internet: www.ethercat.org

You might also like