You are on page 1of 51

Application Note EL9800

Application Note EL9800 Section I Getting started Section II Slave Sample Code Version 1.0 Date: 2010-01-05
Application Note EL9800 Section I Getting started Section II Slave Sample Code Version 1.0 Date: 2010-01-05

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

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.

DOCUMENT HISTORY Version Comment 0.1 Documentation based on EL9800_2 (PIC18) 0.2 Add EtherCAT piggyback

DOCUMENT HISTORY

Version

Comment

0.1

Documentation based on EL9800_2 (PIC18)

0.2

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

1.0

Add Section II Chapter 2 “Slave Sample Code”

Application Note EL9800

Application Note EL9800 Section I – Getting Started Version 0.2 Date: 2009-07-31
Application Note EL9800 Section I – Getting Started Version 0.2 Date: 2009-07-31

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

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.

DOCUMENT HISTORY Version Comment 0.1 Documentation based on EL9800_2 (PIC18) 0.2 Add EtherCAT piggyback

DOCUMENT HISTORY

Version

Comment

0.1

Documentation based on EL9800_2 (PIC18)

0.2

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

CONTENTS 1 GENERAL NOTES 6 2 Software installation 7 2.1 MPLAB IDE 7 2.2 HI-TECH

CONTENTS

1 GENERAL NOTES

6

2 Software installation

7

2.1 MPLAB IDE

7

2.2 HI-TECH PICC-18 STD

7

2.3 Microchip C30 compiler

8

2.4 HI-TECH Universal Toolsuite plugin for MPLAB (optional)

9

2.5 MPLAB ICD2 driver

9

2.6 TwinCAT installation

9

3 EtherCAT setup

10

3.1 Master

10

3.1.1

Install Ethernet real-time driver

10

3.1.2

Setup an EtherCAT network

11

3.1.3

Distributed Clocks

12

3.2 Slave

15

3.2.1

Recommend EL9800 / FB1111-014x setup

15

3.2.2

EEPROM

15

4 Slave Sample Code

17

4.1 Create Project

17

4.2 Project settings

19

4.2.1

Compiler/PIC specific settings

20

4.3 Download binary

22

4.3.1

Debugger

22

5 Known issues

28

FIGURES Figure 1: Execute Installation file 7 Figure 2: Select setup type 7 Figure 3:

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

Table Table 1: Used Software 6 Table 2: Used Hardware 6 Table 3: EL9800 /

Table

Table 1: Used Software

6

Table 2: Used Hardware

6

Table 3: EL9800 / piggyback setup

15

DC EEPROM ABBREVIATIONS Distributed clocks Electrically erasable programmable read only memory I/O Input/Output

DC

EEPROM

ABBREVIATIONS

Distributed clocks

Electrically erasable programmable read only memory

I/O

Input/Output

ICD

In circuit debugger

IDE

Integrated development environment

NIC

Network interface card

OS

Operating system

PDI

Process data interface

PIC

Peripheral interface controller

PICC

PIC compiler

PDO

Process Data Object

RT

Real Time

SDO

Service data object

SM

Sync Manager

SPI

Serial peripheral interface

SSC

Slave sample code

1 GENERAL NOTES This document helps to start working with t he Slave Sample Code

1 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

Version(2009.03.06)

Comment

Code

Beckhoff EtherCAT Slave Sample Code

4.10

Beckhoff ftp server (please see SSC Update mail)

Compiler

HI-TECH PICC-18 STD

9.51PL2

Compiler

Microchip C30

3.02

http://www.microchip.com

Compiler

HI-TECH Universal Toolsuite plugin for MPLAB

1.31

IDE

MPLAB IDE

8.20

OS

Microsoft Windows TwinCAT

XP SP3 2.10 Build 1334

 

EtherCAT

Master

   

Table 2: Used Hardware

Hardware

Name

Version(2009.03.06)

Comment

Evaluation board

EL9800

2 (PIC18)

Evauation board

EL9800

4A (PIC24)

EtherCAT piggyback controller

FB1111-

-

0142

EtherCAT piggyback adapter

EL9803

-

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

2 Software installation 2.1 MPLAB IDE • Unzip “MPLAB_v8.20.zip” • Execute “Install_MPLAB_v820.exe”
2 Software installation 2.1 MPLAB IDE • Unzip “MPLAB_v8.20.zip” • Execute “Install_MPLAB_v820.exe”
2
Software installation
2.1
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 it’s recommend to install the complete package.)

move it’s recommend to install the complete package.) Figure 2: Select setup type • Don’t install

Figure 2: Select setup type

• Don’t install the “HCPIC18-pro-960PL5” compiler Figure 3: Compiler installation 2.2 HI-TECH PICC-18 STD
Don’t 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”

Figure 4: Installation type • If the terms of license agreement are accepted the “Activation
Figure 4: Installation type • If the terms of license agreement are accepted the “Activation

Figure 4: Installation type

• If the terms of license agreement are accepted the “Activation successful” message box appears
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)

2.4 HI-TECH Universal Toolsuite plugin for MPLAB (optional) The Toolsuite is recommended if the MPLAB

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 “HCPIC18- pro-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

device is detected on the PC Select automatic installation 2.6 • • Figure 7: Driver installation

2.6

Figure 7: Driver installation

TwinCAT installation

A 30 days trail version is available on evaluation Kit CD or can be downloaded from

Run the setup and select “TwinCAT PLC” installation level.

the setup and select “TwinCAT PLC” installation level. Figure 8: TwinCAT installation level • Include the

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

3 EtherCAT setup 3.1 Master 3.1.1 Install Ethernet real-time driver • Start TwinCAT System Manager

3

EtherCAT setup

3.1

Master

3.1.1

Install Ethernet real-time driver

Start TwinCAT System Manager

Open [Options] [Show Real Time Ethernet Compatible Devices…]

[Options] [Show Real Time Ethernet Compatible Devices…] Figure 9: Real time driver • All available network

Figure 9: Real time driver

All available network cards are listed

Real time driver • All available network cards are listed Figure 10: Real time driver installation

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

“Incompatible devices” NICs which are not installed yet and accessible by the “TwinCAT RT-Ethernet intermediate

“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

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 applicatiSome applications/services (e.g. firewalls) ma ons/services which access the selected network card ons/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…]

ri ght mouse click on [I/O Devices] [Scan Devices…] Figure 11: Perform device scan • A

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”

Figure 12: Successful device scan • In this configuration the evaluation board operat es in
Figure 12: Successful device scan • In this configuration the evaluation board operat es in

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.

3.1.3 Distributed Clocks

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…]

xx (EtherCAT)] tab [EtherCAT] [Advanced Settings…] Figure 13: Master startup behaviour 3.1.3.1 Additional task

Figure 13: Master startup behaviour

3.1.3.1 Additional task

Expand [System – configuration] right mouse click on [Additional Task] [Append Task]

Figure 14: Append task • Insert a output variable to the ta sk: right mouse
Figure 14: Append task • Insert a output variable to the ta sk: right mouse

Figure 14: Append task

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

ta sk: right mouse click on [outputs] [Insert Variable] Figure 15: Insert variable • Select variable

Figure 15: Insert variable

Select variable type “BIT” and click [OK]

variable • Select variable type “BIT” and click [OK] Figure 16: Variable type • Create a

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)

Figure 17: Link new variable • Select the new task and check “Auto start” Figure
Figure 17: Link new variable • Select the new task and check “Auto start” Figure

Figure 17: Link new variable

Select the new task and check “Auto start”

variable • Select the new task and check “Auto start” Figure 18: Enable Auto start •

Figure 18: Enable Auto start

Reload device to apply changes: [Actions] [Reload Devices]

Figure 19: Reload Devices 3.2 Slave 3.2.1 Recommend EL9800 / FB1111-014x setup In this case
Figure 19: Reload Devices 3.2 Slave 3.2.1 Recommend EL9800 / FB1111-014x setup In this case

Figure 19: Reload Devices

3.2

Slave

3.2.1

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

 

FB1111-0141

FB1111-0142

 

< = EL9800_2

valid

Only with EL9803

 

>= EL9800_4A

NOT valid

valid

3.2.2

EEPROM

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]

right mouse click on the listed device [EEPROM Update] Figure 20: Select EEPROM update • In

Figure 20: Select EEPROM update

In the following window all available device descriptions are listed

Figure 21: device descriptions • “Eva Board (Sample Source Demos)” Select “EL9800(Vx.xx)(PICxx, SPI,ET1100)
Figure 21: device descriptions • “Eva Board (Sample Source Demos)” Select “EL9800(Vx.xx)(PICxx, SPI,ET1100)

Figure 21: device descriptions

“Eva Board (Sample Source Demos)” Select “EL9800(Vx.xx)(PICxx, SPI,ET1100) (EL9800- 0100-0001)” and click OK

SPI,ET1100) (EL9800- 0100-0001)” and click OK If the device is not listed include the device description

If the device is not listed include the device description (chapter 2.6 TwinCAT installation)

Don’t power down the evaluation board while updating the EEPROM!

After successful update the TwinCAT status is set to ready

After successful update the Twin CAT status is set to ready Figure 22: TwinCAT status 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

an EtherCAT network • Set the PDI selector (S200) to 5 Confirm that the used EtherCAT

Confirm that the used EtherCAT piggyback is compatible to the selected PDI.

For more information see FB11xx datasheets on the Beckhoff download website!

4 4.1 • • Slave Sample Code Create Project Copy the source files from the

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.

Open the MPLAB and click [Project] [New…] in menu bar. • Figure 23: Create a new

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.

and all other created files. Then press the [OK] button. • • Figure 24: Project Details

Figure 24: Project Details

If the project manager is not already displayed in MPLAB choose [View] [Project] in menu bar.

displayed in MPLAB choose [View] [Project] in menu bar. Figure 25: Activate Project Manager To add

Figure 25: Activate Project Manager

To add the SSC source files select [Project] [Add Files to Project…] in menu bar.

Figure 26: Add source files • Select all *.c and *.h files except of mcihw.c
Figure 26: Add source files • Select all *.c and *.h files except of mcihw.c

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.

the two mcihw.* files afterwards from project manager. Figure 27: Select source files I-18 Application Note

Figure 27: Select source files

4.2 Project settings • To select the compiler, linker and assembler choose [Project] [Select Language

4.2 Project settings

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

[Project] [Select Language Toolsuite…] in menu bar. Figure 28: Select tools • Select the corresponding PIC

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

boards from version EL9800_4A select “ PIC24HJ128GP306 ” Figure 29: Selection of the controller • Choose

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.

Figure 30: HI-TECH Toolsuite 4.2.1 Compiler/PIC specific settings • Microchip C30 compiler (PIC24): Define a
Figure 30: HI-TECH Toolsuite 4.2.1 Compiler/PIC specific settings • Microchip C30 compiler (PIC24): Define a

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”)!

Opti ons”->Project-> tab “MPLAB LINK30”)! Figure 31: Heap setting for Microchip C30 compiler I-20

Figure 31: Heap setting for Microchip C30 compiler

• HI-TECH PICC-18 STD compiler (PIC18): Increment the “identifier length” > 60 and disable code

HI-TECH PICC-18 STD compiler (PIC18):

Increment the “identifier length” > 60 and disable code optimization ([Project] [Build Options] [Project] [Compiler] tab).

[Build Options] [Project] [Compiler] tab). Figure 32: Compiler Settings • Confirm that the correct

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. It’s not possible to get full feature setup for the PIC18 in addition to other reasons caused by limited program memory. So it’s 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

For EL9800 hardware from version 4 select _PIC24 Figure 33: PIC define • To compile the

Figure 33: PIC define

To compile the SSC select [Project] [Rebuild] in menu bar.

Figure 34: Rebuild Project • An output window with further information appears. The *.hex and
Figure 34: Rebuild Project • An output window with further information appears. The *.hex and

Figure 34: Rebuild Project

• An output window with further information appears. The *.hex and *.cof (for debugging) files
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
Download binary

4.3.1 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.

• Enable the on board debugger interface. Set dipswitch SW600 (>= EL9800.4) or SW800 (<=EL9800.2)

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”.

ICD 2 onboard debugger. So select the "MPLAB ICD 2”. Figure 36: Select "MPLAB ICD 2"

Figure 36: Select "MPLAB ICD 2"

The MPLAB ICD2 setup wizard start up

ICD 2" • The MPLAB ICD2 setup wizard start up Figure 37: ICD 2 setup wizard

Figure 37: ICD 2 setup wizard

Select “USB”

start up Figure 37: ICD 2 setup wizard • Select “USB” Figure 38: Communication interface selection

Figure 38: Communication interface selection

Select „Target has own power supply“

Figure 39: Power supply selection • Don’t check automatic connection Figure 40: Auto connect •
Figure 39: Power supply selection • Don’t check automatic connection Figure 40: Auto connect •

Figure 39: Power supply selection

Don’t check automatic connection

supply selection • Don’t check automatic connection Figure 40: Auto connect • Check automatic download

Figure 40: Auto connect

Check automatic download operating system

Auto connect • Check automatic download operating system • Connect to debugger Figure 41: Download OS

Connect to debugger

Figure 41: Download OS

Figure 42: Connect to debugger • Acknowledge the download warning with [OK] Figure 43: Download
Figure 42: Connect to debugger • Acknowledge the download warning with [OK] Figure 43: Download

Figure 42: Connect to debugger

Acknowledge the download warning with [OK]

to debugger • Acknowledge the download warning with [OK] Figure 43: Download warning • Output if

Figure 43: Download warning

Output if connection succeeds

43: Download warning • Output if connection succeeds Figure 44: Output window: connection successful Application

Figure 44: Output window: connection successful

• Download the binary file Figure 45: Program PIC memory • Output if programming succeeds

Download the binary file

• Download the binary file Figure 45: Program PIC memory • Output if programming succeeds Figure

Figure 45: Program PIC memory

Output if programming succeeds

45: Program PIC memory • Output if programming succeeds Figure 46: Output window: Programming successful •

Figure 46: Output window: Programming successful

Select [Debugger] [Run]

Figure 47: Run binary Application Note EL9800 I-27
Figure 47: Run binary Application Note EL9800 I-27

Figure 47: Run binary

5 Known issues     Software / Issue Possible workaround Platform   Compiler / Code

5 Known issues

   

Software /

Issue

Possible workaround

Platform

 

Compiler / Code Editor

 

could be caused by trimming defines to 31 chars (default identifier length) => increase the maximal identifier length ([Project] [Build Options] [Project] tab”compiler”)

-HI-TECH

Compiler warning:

“… redefining preprocessor macro…”

PICC18 STD

(9.51PL2)

Set SDO to online update causes EtherCAT error:

disable code optimization ([Project] [Build Options] [Project] tab”compiler”)

-HI-TECH

“… abnormal state change (from ‘OP’ to ‘Invalid(xx)’).Go to “’INIT’ and try get back to ‘OP’…”

PICC18 STD

(9.51PL2)

Compiler error:

Required Program memory exceeds available memory Undefined (exclude) Code modules

-HI-TECH

can't find 0xxxx words (0xxxx withtotal) for psect "text" in segment "CODE"

PICC18 STD

(9.51PL2)

“unable to connect to debugger” or general debugger connection problems

use older debugger driver or an old eg. 8.20 MPLAB IDE version

MPLAB IDE

8.40

 

Running Code

The EtherCAT slave remains in INIT- state

Confirm the slave sample code is running (if the binary was downloaded with the debugger the program needs a run trigger to start)

 

The EtherCAT slave supports DC an don’t get to OP – state

The master needs a sync task (chapter 3.1.3 Distributed Clocks)

 

The downloaded release binary don’t starts up

Disable the debugger interface.

 

Application Note EL9800

Application Note EL9800 Section II – Slave Sample Code Version 1.0 Date: 2010-01-05
Application Note EL9800 Section II – Slave Sample Code Version 1.0 Date: 2010-01-05

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

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.

DOCUMENT HISTORY Version Comment 1.0 Description of the CiA402 implementation (based on Slave Sample Code

DOCUMENT HISTORY

Version

Comment

1.0

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.

CONTENTS 1 References 6 2 CiA402 drive profile 7 2.1 Objects 7 2.2 State machine

CONTENTS

1 References

6

2 CiA402 drive profile

7

2.1 Objects

7

2.2 State machine

9

2.3 Operation modes

10

2.4 TwinCAT setup

11

2.4.1 Automatic network setup

12

2.4.2 Manual network setup

12

2.4.3 NC parameter setup

14

3 Known issues

15

FIGURES Figure 1: CiA402 state tran sitions and op tion codes 9 Figure 2: Axis

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

TABLES Table 1: Object definitions in file cia402appl.h 8 Table 2: Stat e machine 10

TABLES

Table 1: Object definitions in file cia402appl.h

8

Table 2: State machine

10

Table 3: Linking of device and NC variables

13

ABBREVIATIONS CiA CAN in Automation csp cycle synchronous position csv cycle synchronous velocity DC

ABBREVIATIONS

CiA

CAN in Automation

csp

cycle synchronous position

csv

cycle synchronous velocity

DC

Distributed Clocks

NC

Numeric Control

PDO

Process Data Object

PLC

Programmable Logic Controller

SM

Sync Manager

1 References [1] ETG Implementation Guideline fo r the CiA402 Drive Profile (V0.2.0) II-6 Application

1

References

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

2 CiA402 drive profile Since version 4.30 the slave sample code contains a sample implementation

2 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.

Table 1: Object definitions in file cia402appl.h Index Object name Variable in source code Comment/Description

Table 1: Object definitions in file cia402appl.h

Index

Object name

Variable in source code

Comment/Description

0x1600

Rx PDOs

sRxPDOMap0

includes all objects required for dynamic change between csv/csp

0x1601

Rx PDOs

sRxPDOMap1

includes objects required for csp mode of operation

0x1602

Rx PDOs

sRxPDOMap2

includes objects required for csv mode of operation

0x1A00

Tx PDOs

sTxPDOMap0

includes all objects required for dynamic change between csv/csp

0x1A01

Tx PDOs

sTxPDOMap1

includes objects required for csp mode of operation

0x1A02

Tx PDOs

sTxPDOMap2

includes objects required for csv mode of operation

 

SyncManger 2

 

this object is written in change state from PREOP to SAFEOP; the configuration depends on the number of axes (not include in

0x1C12

PDO assign

sRxPDOassign

(Rx PDOs)

CiA402Objects)

 

SyncManger 3

 

equal to 0x1C12 (not include in

CiA402Objects)

0x1C13

PDO assign

(Tx PDOs)

sTxPDOassign

0x603F

Error Code

objErrorCode

this value shall be set if an error in the PDS occurs

0x6040

Controlword

objControlWord

object for the output commands from the master

0x6041

Status word

objStatusWord

current axis status

0x605A

Quick stop

objQuickStopOptionCode

predefined ramp if an quick stop shall be performed

option code

 

Shutdown

 

predefined action in state transition 8

0x605B

option code

objShutdownOptionCode

 

Disable

   

0x605C

operation

objDisableOperationOptionCode

predefined action in state transition 5

option code

 

Fault reaction

 

predefined action in state “Fault reaction active”

0x605E

option code

objFaultReactionCode

 

Modes of

   

0x6060

operation

objModesOfOperation

requested operation mode

 

Modes of

   

0x6061

operation

objModesOfOperationDisplay

current operation mode

display

 

Position actual

 

current position value (delivered by encoder)

0x6064

value

objPositionActualValue

0x606C

Velocity actual

objVelocityActualValue

velocity feedback

value

0x6077

Torque actual

objTorqueActualValue

currently not used (only for completion)

value

0x607A

Target position

objTargetPosition

requested Postion value (set in csp mode)

 

Software

 

includes the minimum and maximum actual position limit

0x607D

position limit

objSoftwarePositionLimit

0x6085

Quick stop

objQuickStopDeclaration

predefined action in state “Quick stop active”

declaration

0x60C2

Interpolation

objInterpolationTimePeriod

 

time period

0x60FF

Target velocity

objTargetVelocity

target velocity requested by the master

0x6502

Supported

objSupportedDriveModes

list of all supported operation modes

drive modes

The objects from 0x6000 to 0x67FF are incr emented with 0x800 for each axis (Index

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.

sample these functions are handled by Boolean variables. Figure 1: CiA402 state transitions and option codes

Figure 1: CiA402 state transitions and option codes

Table 2: State machine     Control word bits       Variable (Function)  

Table 2: State machine

   

Control word bits

     

Variable (Function)

 

Transition

Bit 7 (fault reset)

Bit 3 (enable operation)

Bit 2 (quick stop)

 

Bit 1 (enable voltage)

Bit 0 (switch on)

Resulting state

bBrakeApplied

Applied

bLowLevelPower

Applied

bHighLevelPower

Enabled

bAxisFunction

Allowed

bConfiguration

3

0

x

1

 

1

1

Switched on

true

true

true

false

true

4

0

1

1

 

1

1

Operation

false

true

true

true

false

enabled

5

0

0

1

 

1

1

Switch on

true

true

true

false

true

6

0

x

1

 

1

0

Ready to switch on

true

true

false

false

true

7

0

x

x

 

0

x

Switch on

true

true

false

false

true

0

x

0

 

1

x

disabled

8

0

x

1

 

1

0

Ready to switch on

true

true

false

false

true

           

Switch on

         

9

0

x

x

 

0

x

disabled

true

true

false

false

true

 

0

x

x

 

0

x

Switch on

         

10

 

disabled

true

true

false

false

true

0

x

0

 

1

x

11

0

x

0

 

1

x

Quick stop active

false

true

true

true

false

           

Switch on

         

12

0

x

x

 

0

x

disbaled

true

true

false

false

true

   

Fault reaction

         

13

Triggered by application

active

false

true

true

true

false

14

Transition if option code 0x605E is finished

Fault

true

true

false

false

true

           

Switch on

         

15

1

x

x

x

x

disabled

true

true

false

false

true

16

After quick stop always goto “Switch on disabled”

(Operation

false

true

true

true

false

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 doesn’t 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.

Figure 2: Axis configuration NOTE: This sample doesn’t provide a target value overflow control! 2.4
Figure 2: Axis configuration NOTE: This sample doesn’t provide a target value overflow control! 2.4

Figure 2: Axis configuration

NOTE: This sample doesn’t provide a target value overflow control!Figure 2: Axis configuration 2.4 TwinCAT setup This chapter describes the setup of motion cont rol

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.

could be set manually at each EtherCAT master restart. Figure 3: Set device variable without PLC

Figure 3: Set device variable without PLC link

2.4.1 Automatic network setup The TwinCAT System Manger provides a comfort able master setup. Open

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).

and scan the network for new devices ( Figure 4 ). Figure 4: Scan for new

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).

set Axis type to “CANopen DS402” (see Figure 5 ). Figure 5: CiA402 axis setup Add

Figure 5: CiA402 axis setup

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

Figure 6: Add CiA402 device Now the device variables (objects) need to be linked to
Figure 6: Add CiA402 device Now the device variables (objects) need to be linked to

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

object index

type

 

variable name

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.

byte and “nStatus2” to the high byte of the Statusword. Figure 7: Link multiple variables Application

Figure 7: Link multiple variables

2.4.3 NC parameter setup It is required to setup the encoder and velocity output scaling

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

factor formula: enc.scaling = (mm/rev)/encoder resolution Figure 8: Encoder scaling The velocity output scaling is

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).

1 so the velocity scaling factor is 0.114441027( Figure 9 ). Figure 9: Velocity scaling II-14

Figure 9: Velocity scaling

3 Known issues S o f t w a r e / Platform Issue Possible

3 Known issues

Software /

Platform

Issue

Possible workaround

Appendix Support and Service Beckhoff and their partners around the world offe r comprehensive support

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.

Beckhoff’s 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