Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY
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
|
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. |
In MultiTool Creator, select the EMCY consumer and/or producer to initialize the protocol.
For more details, see Epec MultiTool Creator manual.
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)
Code is the EMCY error code
Field is the 5 byte manufacturer specific error code information
RegisterMask is bitmask for EMCY error register index (1001h)
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 |
|
|
The following example activates a single EMCY alarm.
When EMCY is activated by the application:
CANopen EMCY protocol automatically updates the error register (1001h) and predefined error field (1003h) indexes
An EMCY message is sent to the CAN bus using the application's EMCY object's data
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])); |
|
|
The following example deactivates an EMCY alarm.
When EMCY is deactivated by the application:
CANopen EMCY protocol automatically updates the error register (1001h) and predefined error field (1003h) indexes
A null EMCY message is sent to the CAN bus if there are no more active EMCY alarms
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:
EMCY code (byte 1-2)
Additional information (byte 3-4): First two bytes from the EMCY object's Field variable
The latest EMCY alarm is always located in sub-index 1.
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.
Source file topic100583.htm
Last updated 19-Dec-2024