CANopen Slave Protocol Stack 
Version 7.08.00
Loading...
Searching...
No Matches
cos406.h File Reference

Detailed Description

The purpose of encoders is to detect positions of any kind of machine tools. Encoders detect positions and transmit the position values across the CANopen network. Optionally the encoder may provide speed, acceleration, and jerk values. The encoder may receive configuration information via SDO, e.g. conversion parameters for calculating an - to the application adapted - position value. In the NMT state operational, the position value may be transmitted by synchronous PDO. Additionally, the encoders may transmit asynchronously a PDO scheduled by the elapsing of the event timer.

The CANopen device profile defines two encoder classes, a standard device class 1 (C1) and an extended device class 2 (C2). The standard device C1 specifies basic functionality, which shall be provided by each device. The C2 extended device provides a variety of features with mandatory and optional functions. The mandatory functions of both, C1 and C2, are necessary to ensure non-manufacturer specific operations of a device.

By defining mandatory device characteristics in C1, basic network and encoder operation is guaranteed. By defining extended C2, a degree of defined flexibility may be built in. By leaving hooks for optional and manufacturer-specific functionality, the device developer will not be constrained to an out-of-date standard.

Object dictionary

The module adds the following objects to the object dictionary:

Index Description Function / Variable Configuration Symbol
6000h Operating parameters Cos406_Idx6000() -
6001h Measuring units per revolution Cos406_Idx6001() COS_DS406
6002h Total measuring range in measuring units Cos406_Idx6002() -
6003h Preset value Cos406_Idx6003() -
6004h Position value ulIdx6004_PosValueG -
6005h Linear encoder measuring step settings Cos406_Idx6005() -
6030h Speed value Cos406_Idx6030() -
6040h Acceleration value Cos406_Idx6040() -
6050h Jerk value Cos406_Idx6050() -
6200h Cyclic timer Cos406_Idx6200() -
6500h Operating status Cos406_Idx6500() -
6501h Single-turn resolution / measuring step Cos406_Idx6501() -
6502h Number of distinguishable revolutions Cos406_Idx6502() -
6503h Alarms Cos406_Idx6503() -
6504h Supported alarms Cos406_Idx6504() DS406_SUPPORTED_ALARMS
6505h Warnings Cos406_Idx6505() -
6506h Supported warnings Cos406_Idx6506() DS406_SUPPORTED_WARNINGS
6507h Profile and software version Cos406_Idx6507() DS406_PROFILE_VERSION
6508h Operating time Cos406_Idx6508() -
6509h Offset value Cos406_Idx6509() -
650Ah Module identification Cos406_Idx650A() -
650Bh Serial number Cos406_Idx650B() -

Configuration

The module is enabled by setting COS_DS406 in the application cos_conf.h:

Value Encoder class Effect
1 Single-turn Basic position, speed, acceleration, and status objects
2 Multi-turn Adds multi-turn position scaling

Optional tuneable constants:

Include dependency graph for cos406.h:

Macros

#define DS406_PROFILE_VERSION   0x0400U
#define DS406_SUPPORTED_ALARMS   0x0001U
#define DS406_SUPPORTED_WARNINGS   0x0002U
#define DS406_RESOLUTION_SINGLE_TURN   16384U
#define DS406_RESOLUTION_MULTI_TURN_32   0x01FFFFFFU
#define MAN_OFFSET_VALUE   0x00000000
#define MAN_MINPOS_VALUE   0x00000000
#define MAN_MAXPOS_VALUE   0x00003FFF
#define COS_DS406_VERSION_MAJOR   4
#define COS_DS406_VERSION_MINOR   2

Enumerations

enum  DS406_OPER_STATUS_e
enum  DS406_ALARM_e
enum  DS406_WARN_e

Functions

void Cos406_SetAlarms (uint16_t uwAlarmsV)
void Cos406_SetEncoderValue (uint32_t ulSgTurnV, uint32_t ulMtTurnV, uint32_t ulTimeDiffV)
void Cos406_SetOperatingStatus (uint16_t uwStatusV)
void Cos406_SetOperatingTime (uint32_t ulTimeV)
void Cos406_SetWarnings (uint16_t uwWarningsV)

Enumeration Type Documentation

◆ DS406_ALARM_e

Alarm bits for object 6503h (CiA 406 Table 144). An alarm indicates a malfunction that may lead to an incorrect position value; the bit stays set until the encoder can again provide a valid position. Bits 0 and 1 are mandatory for class C3 encoders. Use Cos406_SetAlarms() to update the active alarms.

Enumerator
eALARM_OK 

no active alarm

eALARM_PE 

Position error.

eALARM_CDE 

Commissioning diagnostic error.

eALARM_MSA1 

Manufacturer-specific alarm 1.

eALARM_MSA2 

Manufacturer-specific alarm 2.

eALARM_MSA3 

Manufacturer-specific alarm 3.

eALARM_MSA4 

Manufacturer-specific alarm 4.

◆ DS406_OPER_STATUS_e

Operating status bits for object 6500h (CiA 406 Table 137). This object reflects the active encoder configuration as set by object 6000h. Use Cos406_SetOperatingStatus() to update the operating status.

Enumerator
eOPER_STATUS_CS 

Code sequence: 0 = CW rotated, 1 = CCW rotated (rotary only)

eOPER_STATUS_CDC 

Commissioning diagnostic control enabled.

eOPER_STATUS_SFC 

Scaling function control enabled.

eOPER_STATUS_MD 

Measuring direction: 0 = forward, 1 = backwards (linear only)

eOPER_STATUS_HSFC 

High resolution scaling function control enabled.

eOPER_STATUS_MSP1 

Manufacturer-specific operating status 1.

eOPER_STATUS_MSP2 

Manufacturer-specific operating status 2.

eOPER_STATUS_MSP3 

Manufacturer-specific operating status 3.

eOPER_STATUS_MSP4 

Manufacturer-specific operating status 4.

◆ DS406_WARN_e

Warning bits for object 6505h (CiA 406 Table 150). Warnings indicate that tolerances for internal encoder parameters have been exceeded, but do not imply an incorrect position value. All warning bits clear automatically when the parameter returns to its nominal range, except eWARN_OTLW which is latched until the next power-on. Bits are mandatory for C3, optional for C1 and C2. Use Cos406_SetWarnings() to update active warnings.

Enumerator
eWARN_OK 

no active warning

eWARN_FE 

Frequency exceeded.

eWARN_LCR 

Light control reserve reached.

eWARN_CPU_WS 

CPU watchdog status reset generated.

eWARN_OTLW 

Operating time limit exceeded (latched until power-on)

eWARN_BC 

Battery charge too low.

eWARN_RP 

Reference point not reached.

eWARN_SR 

Speed range exceeded.

eWARN_AR 

Acceleration range exceeded.

eWARN_JR 

Jerk range exceeded.

eWARN_MSW1 

Manufacturer-specific warning 1.

eWARN_MSW2 

Manufacturer-specific warning 2.

eWARN_MSW3 

Manufacturer-specific warning 3.

eWARN_MSW4 

Manufacturer-specific warning 4.

Function Documentation

◆ Cos406_SetAlarms()

void Cos406_SetAlarms ( uint16_t uwAlarmsV)
Parameters
[in]uwAlarmsVOR-combination of DS406_ALARM_e bits
See also
Cos406_SetWarnings

Sets the encoder alarm word returned by SDO read of object 6503h. Call this function whenever an alarm condition is detected or cleared.

◆ Cos406_SetEncoderValue()

void Cos406_SetEncoderValue ( uint32_t ulSgTurnV,
uint32_t ulMtTurnV,
uint32_t ulTimeDiffV )
Parameters
[in]ulSgTurnVcurrent single-turn encoder count
[in]ulMtTurnVcurrent multi-turn revolution count (ignored for single-turn configuration)
[in]ulTimeDiffVelapsed time since the previous call, in multiples of 1 ns; pass 0 to update the position without recalculating the speed

Updates the scaled position value (object 6004h) from the raw encoder counts on every call. The speed value (object 6030h) is recalculated only when ulTimeDiffV > 0; if 0 is passed the speed retains its value from the previous call.

Call this function from the encoder hardware ISR or a periodic task whenever new encoder values are available from the hardware.

void MyEncoderApplication()
{
uint32_t ulSingleTurnValueT;
uint32_t ulMultiTurnValueT;
uint32_t ulTimeDifferenceT;
uint16_t uwSensorWarningsT;
uint16_t uwSensorAlarmsT;
//---------------------------------------------------------------------------------
// read values from sensor
//
ulSingleTurnValueT = MySensorReadSingleTurn();
ulMultiTurnValueT = MySensorReadMultiTurn();
ulTimeDifferenceT = MySensorTimeSinceLastRead();
//---------------------------------------------------------------------------------
// process values by device profile
//
Cos406_SetEncoderValue(ulSingleTurnValueT, ulMultiTurnValueT, ulTimeDifferenceT);
//---------------------------------------------------------------------------------
// check sensor warnings
//
uwSensorWarningsT = MySensorWarnings();
switch (uwSensorWarningsT)
{
case MY_SENSOR_NO_WARNING:
break;
// evaluate other warnings ..
}
//---------------------------------------------------------------------------------
// check sensor alarms
//
uwSensorAlarmsT = MySensorAlarms();
switch (uwSensorAlarmsT)
{
case MY_SENSOR_NO_ALARMS:
break;
// evaluate other alarms ..
}
}
void Cos406_SetWarnings(uint16_t uwWarningsV)
@ eALARM_OK
no active alarm
Definition cos406.h:140
void Cos406_SetEncoderValue(uint32_t ulSgTurnV, uint32_t ulMtTurnV, uint32_t ulTimeDiffV)
void Cos406_SetAlarms(uint16_t uwAlarmsV)
@ eWARN_OK
no active warning
Definition cos406.h:162

◆ Cos406_SetOperatingStatus()

void Cos406_SetOperatingStatus ( uint16_t uwStatusV)
Parameters
[in]uwStatusVOR-combination of DS406_OPER_STATUS_e bits

Sets the encoder operating status word returned by SDO read of object 6500h.

◆ Cos406_SetOperatingTime()

void Cos406_SetOperatingTime ( uint32_t ulTimeV)
Parameters
[in]ulTimeVaccumulated operating time in multiples of 0.1 h; pass 0xFFFFFFFFU if the function is not available

Sets the encoder operating time counter returned by SDO read of object 6508h. Update this value periodically from a real-time clock or an elapsed-time counter.

◆ Cos406_SetWarnings()

void Cos406_SetWarnings ( uint16_t uwWarningsV)
Parameters
[in]uwWarningsVOR-combination of DS406_WARN_e bits
See also
Cos406_SetAlarms

Sets the encoder warning word returned by SDO read of object 6505h. Call this function whenever a warning condition is detected or cleared.