CANopen Slave Protocol Stack 
Version 7.08.00
Loading...
Searching...
No Matches
CANopen Device Profile CiA 402

The add-on module CANopen Device Profile CiA 402 allows the integration of drives and motion control as specified in CiA 402-1.

Module version

The module version is defined by COS_DS402_VERSION_MAJOR and COS_DS402_VERSION_MINOR. Please refer to the history for changes between different versions.

Configuration

The module is enabled by setting COS_DS402 > 0 inside the cos_conf.h file:

DefineDescription
COS_DS402enable CiA 402 device profile; set to 1 to include the profile

Interface to application

Use the header file cos402.h to get access to the CANopen Device Profile CiA 402 API.

#include "cos402.h"

Common parameters

The PDS FSA controlword, statusword, option codes, modes of operation, and profile position objects are accessed through the Cos402_Common_ts structure.

The application reads the current values by calling Cos402_GetCommon() and updates them by calling Cos402_SetCommon():

void MyDriveApplication(void)
{
Cos402_Common_ts tsCommonT;
// read current controlword written by the master
const Cos402_Common_ts * ptsCommonT = Cos402_GetCommon();
uint16_t uwControlT = ptsCommonT->uwIdx6040_Control;
// update statusword
tsCommonT = *ptsCommonT;
tsCommonT.uwIdx6041_Status = MY_STATUS_WORD;
Cos402_SetCommon(&tsCommonT);
}
void Cos402_SetCommon(const Cos402_Common_ts *ptsCommonV)
const Cos402_Common_ts * Cos402_GetCommon(void)
uint16_t uwIdx6041_Status
Definition cos402.h:148
uint16_t uwIdx6040_Control
Definition cos402.h:147

Velocity mode

Velocity mode (vl mode) parameters are accessed through the Cos402_Velocity_ts structure.

The application reads the current target velocity and updates the actual velocity by calling Cos402_GetVelocity() and Cos402_SetVelocity():

void MyDriveApplication(void)
{
Cos402_Velocity_ts tsVelocityT;
// read target velocity written by the master
const Cos402_Velocity_ts * ptsVelocityT = Cos402_GetVelocity();
int16_t swTargetT = ptsVelocityT->swIdx6042_VlTarget;
// update actual velocity
tsVelocityT = *ptsVelocityT;
tsVelocityT.swIdx6044_VlActual = MY_ACTUAL_VELOCITY;
Cos402_SetVelocity(&tsVelocityT);
}
void Cos402_SetVelocity(const Cos402_Velocity_ts *ptsVelocityV)
const Cos402_Velocity_ts * Cos402_GetVelocity(void)
int16_t swIdx6042_VlTarget
Definition cos402.h:187
int16_t swIdx6044_VlActual
Definition cos402.h:189

PDO mapping

If dynamic PDO mapping is supported (COS_PDO_MAPPING > 0), the default mapping per CiA 402-3 section 6.3 (frequency converter device) can be set inside the CosPdoComSetup() function:

void CosPdoComSetup(void)
{
uint8_t ubResultT;
//------------------------------------------------------------------------------------
// RPDO1: controlword (6040h) and vl target velocity (6042h)
//
ubResultT = CosPdoRcvMapEnable(0, 0);
ubResultT |= CosPdoRcvMapAdd( 0, 0, 0x60400010U);
ubResultT |= CosPdoRcvMapAdd( 0, 1, 0x60420010U);
ubResultT |= CosPdoRcvMapEnable(0, 2);
//------------------------------------------------------------------------------------
// TPDO1: statusword (6041h) and vl velocity actual value (6044h)
//
ubResultT = CosPdoTrmMapEnable(0, 0);
ubResultT |= CosPdoTrmMapAdd( 0, 0, 0x60410010U);
ubResultT |= CosPdoTrmMapAdd( 0, 1, 0x60440010U);
ubResultT |= CosPdoTrmMapEnable(0, 2);
(void) ubResultT;
}
uint8_t CosPdoRcvMapAdd(uint8_t ubPdoNumberV, uint8_t ubMapIdxV, uint32_t ulMapEntryV)
void CosPdoComSetup(void)
Setup application specific PDO communication parameter.
uint8_t CosPdoTrmMapEnable(uint8_t ubPdoNumberV, uint8_t ubMapNumberV)
uint8_t CosPdoTrmMapAdd(uint8_t ubPdoNumberV, uint8_t ubMapIdxV, uint32_t ulMapEntryV)
uint8_t CosPdoRcvMapEnable(uint8_t ubPdoNumberV, uint8_t ubMapNumberV)

CiA 402 files

FileDescription
cos402.hCiA 402 - API, structures, and public function prototypes
cos402.cCiA 402 - Object dictionary handler functions and PDO handlers
cos402.incCiA 402 - Object dictionary entries (included by cos_dict.c)
cos402_rpdo.incCiA 402 - Receive PDO mapping entries (included by cos_pdod.c)
cos402_tpdo.incCiA 402 - Transmit PDO mapping entries (included by cos_pdod.c)