Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY

 

Using CANopen EMCY

The following guide describes how to use CANopen EMCY (Emergency) protocol using CANopen V4 library and MultiTool Creator code template.

EMCY is a CANopen protocol for sending device's internal errors to CAN bus.

 

The following is required to use EMCY protocol

  • MultiTool 6.2 or newer, or MultiTool Creator

  • CODESYS 3.5 CANopen library 4.0.2.4 or newer

 

It is recommended to use a different application and CODESYS node-ID in a control unit when using CANopen EMCY protocol. CODESYS 3.5 CAN communication sends EMCY messages using CODESYS node-ID which interferes with the application's EMCY consumer implementation.

A CANopen device can be used as an EMCY consumer and producer. A network can have multiple EMCY consumers.

In MultiTool Creator, select the EMCY consumer and/or producer to initialize the protocol.

For more details, see Epec MultiTool Creator manual.

 

EMCY producer

EMCY protocol is automatically initialized and updated by MultiTool Creator code template.

 

The application's responsibility is to create a list of EMCY alarm objects.

An EMCY alarm is activated and deactivated by application using CANopenEMCY (FB) function block's Activate and Deactivate methods.

 

The following example define several application EMCY objects (EPEC_CANopen.EMCYListObject)

 

The CANopen library includes constants for error register bitmasks defined in CiA 301. Also, EMCY error code classes are defined in CiA 301.

 

Definitions:

 

VAR

 

EMCY_Objects: ARRAY [1..4] OF EPEC_CANopen.EMCYListObject := [

(Error := (Code := WORD#16#2000, Field := [16#11, 16#12, 16#13, 16#14, 16#15],

RegisterMask := G_CANOPEN_ERR_REG_BITMASK_CURRENT)),

(Error := (Code := WORD#16#3001, Field := [16#21, 16#22, 16#23, 16#24, 16#25],

RegisterMask := G_CANOPEN_ERR_REG_BITMASK_VOLTAGE)),

(Error := (Code := WORD#16#4000, Field := [16#31, 16#32, 16#33, 16#34, 16#35],

RegisterMask := G_CANOPEN_ERR_REG_BITMASK_TEMPERATURE)),

(Error := (Code := WORD#16#1000, Field := [16#41, 16#42, 16#43, 16#44, 16#45],

RegisterMask := G_CANOPEN_ERR_REG_BITMASK_MANUFACTURER))

];

 

END_VAR

 

 

Activation

The following example activates a single EMCY alarm.

 

When EMCY is activated by the application:

 

EMCY inhibit time limits how often an EMCY CAN message can be sent. The inhibit time is set in MultiTool Creator.

 

It is recommended to execute Activate method only on the alarm's rising edge.

 

Code:

 

G_CANopen_CAN1.EMCY_Handler.Activate(i_pEMCYObject:=ADR(EMCY_Objects[1]));

 

 

Deactivation

The following example deactivates an EMCY alarm.

 

When EMCY is deactivated by the application:

 

It is recommended to execute Deactivate method only on the alarm's falling edge.

 

Code:

 

G_CANopen_CAN1.EMCY_Handler.Deactivate(i_pEMCYObject:=ADR(EMCY_Objects[1]));

 

 

All the sub-indexes in the predefined error field (1003h) include the following data:

 

The latest EMCY alarm is always located in sub-index 1.

 

EMCY consumer

EMCY protocol is automatically initialized and updated by MultiTool Creator code template.

 

When a CANopen device is initialized as an EMCY consumer, the code template includes callbacks for monitored EMCY messages.

The callback is added for each node-ID which is defined as a monitored node in MultiTool Creator.

 

The following code template array includes the latest EMCY error code for each monitored node.

 

G_CANopen_CANx definitions:

 

///EMCY consumer data

MonitoredEMCYs: ARRAY[1..2] OF EMCYObject;

 

 

If EMCY code is not zero, then there is an active EMCY alarm in the monitored control unit.

Code

 

// Check if error is active

IF G_CANopen_CAN1.MonitoredEMCYs[1].Code <> 0 THEN

  ; // error handling is application specific

END_IF

 

 

The application can read EMCY history from the contol unit's OD index 1003h (pre-defined error field).

First it is recommended to read 1003h sub-index 0 for the amount of active EMCYs. The latest EMCY alarm is always located in sub-index 1.

 

See also

 

 

Source file topic100583.htm

Last updated 19-Dec-2024