CANopen Slave Documentation
Version 6.16.04
Loading...
Searching...
No Matches
cos404ai.h File Reference

Detailed Description

This module implements the variables and callback functions for the object dictionary from CiA 404 (analog inputs). The module adds the following objects to the object dictionary:

Index Description Function / Variable Configuration Symbol
6100h AI input FV (float) Cos404_AI_SetFV_Real32() COS_DS404_DT_FLOAT
6110h AI sensor type Cos404_AI_Init() -
6112h AI operating mode Cos404_AI_Init() -
6126h AI scaling factor - COS_DS404_AI_SCALING
6127h AI scaling offset - COS_DS404_AI_SCALING
6130h AI input PV (float) Cos404_AI_SetFV_Real32() COS_DS404_DT_FLOAT
6131h AI physical unit PV Cos404_AI_SetPhysicalUnitPV() -
6132h AI decimal digits PV Cos404_AI_SetDecimalDigitsPV() -
6150h AI status Cos404_AI_SetFV_Int16() -
61A0h AI filter type Cos404_AI_FilterParm_ts COS_DS404_AI_FILTER
61A1h AI filter constant Cos404_AI_FilterParm_ts COS_DS404_AI_FILTER
7100h AI input FV (int16_t) Cos404_AI_SetFV_Int16() COS_DS404_DT_INT16
7130h AI input PV (int16_t) Cos404_AI_SetFV_Int16() COS_DS404_DT_INT16
9100h AI input FV (int32_t) Cos404_AI_SetFV_Int32() COS_DS404_DT_INT32
9130h AI input PV (int32_t) Cos404_AI_SetFV_Int32() COS_DS404_DT_INT32

An example for the module is given inside the file cos404ai_app.c which is located inside the template-cos directory.

Module initialization

The analog input module is initialized for each individual analog input by calling by calling Cos404_AI_Init() prior to CosMgrStart(). The order of function calls is important because CosMgrStart() may overwrite parameters of the analog input module in case a values have been stored in non-volatile memory (refer to object 1010h).

void Cos404_AI_AppInit(void)
{
uint8_t ubChannelT;
uint32_t ulPhysicalUnitT;
Cos404_AI_Config_ts tsConfigurationT;
//---------------------------------------------------------------------------------------------------
// perform initial configuration for CiA 404 AI software module by user application
//
memset(&tsConfigurationT, 0, sizeof(Cos404_AI_Config_ts));
//---------------------------------------------------------------------------------------------------
// set sensor type and operation mode
//
tsConfigurationT.ubObj6112_OpMode = true;
//---------------------------------------------------------------------------------------------------
// if filter support is enabled: register function for filter parameter update
//
#if COS_DS404_AI_FILTER > 0
tsConfigurationT.pfnFilterChangeEvent = Cos404_AI_AppFilterParamEvent;
#endif
//---------------------------------------------------------------------------------------------------
// register function for sensor type update
//
tsConfigurationT.pfnSensorTypeHandler = Cos404_AI_AppSensorTypeHandler;
//---------------------------------------------------------------------------------------------------
// register function for operating mode update
//
tsConfigurationT.pfnOperatingModeEvent = Cos404_AI_AppOperatingModeEvent;
//---------------------------------------------------------------------------------------------------
// physical unit is degree celsius
//
0);
//---------------------------------------------------------------------------------------------------
// now provide the same configuration to all available channels
//
for (ubChannelT = eCOS404_CHANNEL_1; ubChannelT < COS_DS404_AI; ubChannelT++)
{
Cos404_AI_Init(ubChannelT, &tsConfigurationT);
Cos404_AI_SetPhysicalUnitPV(ubChannelT, ulPhysicalUnitT);
}
}
@ eCOS303_SI_UNIT_NONE
dimensionless
Definition cos303.h:65
@ eCOS303_SI_UNIT_DEGREE_CELSIUS
degree celsius [°C]
Definition cos303.h:90
#define COS303_PHYSICAL_UNIT(SiPrefix, SiNumerator, SiDenominator, Profile)
Definition cos303.h:152
@ eCOS303_SI_PREFIX_NONE
no prefix, 100
Definition cos303.h:53
@ eCOS404_CHANNEL_1
Definition cos404.h:148
@ eCOS404_AI_ST_THERMO_J
Definition cos404ai.h:250
uint8_t Cos404_AI_SetPhysicalUnitPV(uint8_t ubChannelV, uint32_t ulPhysicalUnitV)
void Cos404_AI_Init(uint8_t ubChannelV, Cos404_AI_Config_ts *ptsConfigurationV)
uint8_t Cos404_AI_SetDecimalDigitsPV(uint8_t ubChannelV, uint8_t ubDigitsV)
#define COS_DS404_AI
Support CiA 404, analog inputs.
Definition cos_conf.h:249
Definition cos404ai.h:559
Cos404AiEvent_fn pfnFilterChangeEvent
Definition cos404ai.h:631
Cos404AiEvent_fn pfnOperatingModeEvent
Definition cos404ai.h:615
Cos404AiHandler_fn pfnSensorTypeHandler
Definition cos404ai.h:599
uint16_t uwObj6110_SensorType
Definition cos404ai.h:570
uint8_t ubObj6112_OpMode
Definition cos404ai.h:580

Analog value processing

The values for AI status, Ai field value and AI process value are provided to the module by calling Cos404_AI_SetFV_Int16() or the corresponding function for data type int32_t or float.

void Cos404_AI_AppProcess(void)
{
int32_t slFieldValueT = 10000;
float ftProcessValueT = 100.0f;
uint8_t ubChannelT;
//---------------------------------------------------------------------------------------------------
// Process all existing AI channels
//
ubChannelT = eCOS404_CHANNEL_1;
while (ubChannelT < COS_DS404_AI)
{
//-------------------------------------------------------------------------------------------
// read analog values from ADC, check status
//
// slFieldValueT = field value
//
// ftProcessValueT = process value
//
//-------------------------------------------------------------------------------------------
// provide values and their status to the CiA 404
//
Cos404_AI_SetFV_Real32(ubChannelT, eCOS404_AI_STATUS_OK, slFieldValueT, ftProcessValueT);
ubChannelT++;
}
}
@ eCOS404_AI_STATUS_OK
Definition cos404ai.h:446
void Cos404_AI_SetFV_Real32(uint8_t ubChannelV, uint8_t ubStatusV, int32_t slFieldValueV, float ftProcessValueV)
+ Include dependency graph for cos404ai.h:

Data Structures

struct  Cos404_AI_Config_s
 
struct  Cos404_AI_ProcessData_s
 

Typedefs

typedef void(* Cos404AiEvent_fn) (uint8_t ubChannelV)
 
typedef uint8_t(* Cos404AiHandler_fn) (uint8_t ubInputV, void *pvdDataV)
 

Enumerations

enum  Cos404_AI_OpMode_e {
  eCOS404_AI_OP_MODE_OFF = 0 ,
  eCOS404_AI_OP_MODE_ON
}
 
enum  Cos404_AI_SensorType_e {
  eCOS404_AI_ST_UNKNOWN = 0 ,
  eCOS404_AI_ST_THERMO_J = 1 ,
  eCOS404_AI_ST_THERMO_K ,
  eCOS404_AI_ST_THERMO_L ,
  eCOS404_AI_ST_THERMO_N ,
  eCOS404_AI_ST_THERMO_R ,
  eCOS404_AI_ST_THERMO_S ,
  eCOS404_AI_ST_THERMO_T ,
  eCOS404_AI_ST_PT100 = 30 ,
  eCOS404_AI_ST_PT200 ,
  eCOS404_AI_ST_PT500 ,
  eCOS404_AI_ST_PT1000 ,
  eCOS404_AI_ST_PT5000 ,
  eCOS404_AI_ST_INFRARED ,
  eCOS404_AI_ST_VOLT = 40 ,
  eCOS404_AI_ST_VOLT_10V_BIP ,
  eCOS404_AI_ST_VOLT_10V_UNI ,
  eCOS404_AI_ST_VOLT_1V_BIP ,
  eCOS404_AI_ST_VOLT_1V_UNI ,
  eCOS404_AI_ST_VOLT_100mV_BIP ,
  eCOS404_AI_ST_VOLT_100mV_UNI ,
  eCOS404_AI_ST_CURR = 50 ,
  eCOS404_AI_ST_CURR_4_20mA ,
  eCOS404_AI_ST_CURR_0_20mA ,
  eCOS404_AI_ST_FREQUENCY = 60 ,
  eCOS404_AI_ST_GAUGE = 70 ,
  eCOS404_AI_ST_GAUGE_FULL ,
  eCOS404_AI_ST_GAUGE_HALF ,
  eCOS404_AI_ST_GAUGE_QUARTER ,
  eCOS404_AI_ST_LVDT = 80 ,
  eCOS404_AI_ST_PRESSURE_TRANSDUCER = 90 ,
  eCOS404_AI_ST_TEMPERATURE_TRANSDUCER = 100 ,
  eCOS404_AI_ST_FORCE_TRANSDUCER = 110 ,
  eCOS404_AI_ST_POTENTIOMETER = 120 ,
  eCOS404_AI_ST_NTC = 140 ,
  eCOS404_AI_ST_MANUFACTURER_1 = 10000 ,
  eCOS404_AI_ST_MANUFACTURER_2 ,
  eCOS404_AI_ST_MANUFACTURER_3 ,
  eCOS404_AI_ST_MANUFACTURER_4 ,
  eCOS404_AI_ST_MANUFACTURER_5
}
 
enum  Cos404_AI_Status_e {
  eCOS404_AI_STATUS_OK = 0x00 ,
  eCOS404_AI_STATUS_NOT_VALID = 0x01 ,
  eCOS404_AI_STATUS_POS_OVERLOAD = 0x02 ,
  eCOS404_AI_STATUS_NEG_OVERLOAD = 0x04 ,
  eCOS404_AI_STATUS_SYNC_LOST = 0x08 ,
  eCOS404_AI_STATUS_TEDS_ERROR = 0x10 ,
  eCOS404_AI_STATUS_TEDS_PRESENT = 0x20 ,
  eCOS404_AI_STATUS_DICT_CHANGED = 0x40
}
 

Functions

uint8_t Cos404_AI_GetOperatingMode (uint8_t ubChannelV)
 
uint16_t Cos404_AI_GetSensorType (uint8_t ubChannelV)
 
void Cos404_AI_Init (uint8_t ubChannelV, Cos404_AI_Config_ts *ptsConfigurationV)
 
uint8_t Cos404_AI_SetDecimalDigitsPV (uint8_t ubChannelV, uint8_t ubDigitsV)
 
uint8_t Cos404_AI_SetPhysicalUnitPV (uint8_t ubChannelV, uint32_t ulPhysicalUnitV)
 
void Cos404_AI_SetFV_Int16 (uint8_t ubChannelV, uint8_t ubStatusV, int16_t swFieldValueV, int16_t swProcessValueV)
 
void Cos404_AI_SetFV_Int32 (uint8_t ubChannelV, uint8_t ubStatusV, int32_t slFieldValueV, int32_t slProcessValueV)
 
void Cos404_AI_SetFV_Real32 (uint8_t ubChannelV, uint8_t ubStatusV, int32_t slFieldValueV, float ftProcessValueV)
 

Variables

Cos404_AI_ProcessData_ts atsCos404_AI_ProcessDataG []
 

Typedef Documentation

◆ Cos404AiEvent_fn

Cos404AiEvent_fn
Parameters
[in]ubChannelVAnalog input channel

An event handler can be registered during initialization by Cos404_AI_Init() for each channel. Supported events are:

The parameter ubChannelV defines the channel number, the first channel starts at eCOS404_CHANNEL_1.

◆ Cos404AiHandler_fn

Cos404AiHandler_fn
Parameters
[in]ubChannelVAnalog input channel
[in]pvdDataVPointer to handler specific data
Returns
eCosSdo_WRITE_OK on success or any other value from CosSdo_e in case of an error

A data handler can be registered during initialization by Cos404_AI_Init() for each channel. Supported handlers are:

The parameter ubChannelV defines the channel number, the first channel starts at eCOS404_CHANNEL_1. The data contents of pointer pvdDataV is specific for every handler.

Enumeration Type Documentation

◆ Cos404_AI_OpMode_e

Values for AI operating mode object at index 6112h.

Enumerator
eCOS404_AI_OP_MODE_OFF 

channel is switched off

eCOS404_AI_OP_MODE_ON 

channel is switched on

◆ Cos404_AI_SensorType_e

Values for AI Sensor Types corresponding to CiA 404, object 6110

Enumerator
eCOS404_AI_ST_UNKNOWN 

Sensor type is unknown

eCOS404_AI_ST_THERMO_J 

Thermocouple type J

eCOS404_AI_ST_THERMO_K 

Thermocouple type K

eCOS404_AI_ST_THERMO_L 

Thermocouple type L

eCOS404_AI_ST_THERMO_N 

Thermocouple type N

eCOS404_AI_ST_THERMO_R 

Thermocouple type R

eCOS404_AI_ST_THERMO_S 

Thermocouple type S

eCOS404_AI_ST_THERMO_T 

Thermocouple type T

eCOS404_AI_ST_PT100 

PT100

eCOS404_AI_ST_PT200 

PT200

eCOS404_AI_ST_PT500 

PT500

eCOS404_AI_ST_PT1000 

PT1000

eCOS404_AI_ST_PT5000 

PT5000

eCOS404_AI_ST_INFRARED 

IR-sensor

eCOS404_AI_ST_VOLT 

Voltage

eCOS404_AI_ST_VOLT_10V_BIP 

± 10 V

eCOS404_AI_ST_VOLT_10V_UNI 

0 to 10 V

eCOS404_AI_ST_VOLT_1V_BIP 

± 1 V

eCOS404_AI_ST_VOLT_1V_UNI 

0 to 1 V

eCOS404_AI_ST_VOLT_100mV_BIP 

± 100 mV

eCOS404_AI_ST_VOLT_100mV_UNI 

0 to 100 mV

eCOS404_AI_ST_CURR 

Current

eCOS404_AI_ST_CURR_4_20mA 

4 to 20 mA

eCOS404_AI_ST_CURR_0_20mA 

0 to 20 mA

eCOS404_AI_ST_FREQUENCY 

Frequency

eCOS404_AI_ST_GAUGE 

Strain gauge

eCOS404_AI_ST_GAUGE_FULL 

Strain gauge full bridge

eCOS404_AI_ST_GAUGE_HALF 

Strain gauge half bridge

eCOS404_AI_ST_GAUGE_QUARTER 

Strain gauge quarter bridge

eCOS404_AI_ST_LVDT 

Inductive sensors

eCOS404_AI_ST_PRESSURE_TRANSDUCER 

Pressure transducer

eCOS404_AI_ST_TEMPERATURE_TRANSDUCER 

Temperature transducer

eCOS404_AI_ST_FORCE_TRANSDUCER 

Sensors for vibration measurement

eCOS404_AI_ST_POTENTIOMETER 

Potentiometer

eCOS404_AI_ST_NTC 

NTC

eCOS404_AI_ST_MANUFACTURER_1 

Manufacturer-specific senor type 1

eCOS404_AI_ST_MANUFACTURER_2 

Manufacturer-specific senor type 2

eCOS404_AI_ST_MANUFACTURER_3 

Manufacturer-specific senor type 3

eCOS404_AI_ST_MANUFACTURER_4 

Manufacturer-specific senor type 4

eCOS404_AI_ST_MANUFACTURER_5 

Manufacturer-specific senor type 5

◆ Cos404_AI_Status_e

Values for AI Status from CiA 404, object 6150h

Enumerator
eCOS404_AI_STATUS_OK 

All OK

eCOS404_AI_STATUS_NOT_VALID 

Not valid

eCOS404_AI_STATUS_POS_OVERLOAD 

Positive overload

eCOS404_AI_STATUS_NEG_OVERLOAD 

Negative overload

eCOS404_AI_STATUS_SYNC_LOST 

Synchronization of the signal lost

eCOS404_AI_STATUS_TEDS_ERROR 

TEDS error warning

eCOS404_AI_STATUS_TEDS_PRESENT 

TEDS sensor present

eCOS404_AI_STATUS_DICT_CHANGED 

Object dictionary changed

Function Documentation

◆ Cos404_AI_GetOperatingMode()

uint8_t Cos404_AI_GetOperatingMode ( uint8_t  ubChannelV)

Get pending operating mode of a channel.

Parameters
[in]ubChannelVAnalog input channel
Returns
Value from Cos404_AI_OpMode_e enumeration. In case of wrong channel parameter or not fully initialised channel the return value is eCOS404_AI_OP_MODE_OFF .

◆ Cos404_AI_GetSensorType()

uint16_t Cos404_AI_GetSensorType ( uint8_t  ubChannelV)

Get pending sensor type of a channel.

Parameters
[in]ubChannelVAnalog input channel
Returns
Value from Cos404_AI_SensorType_e enumeration. In case of wrong channel parameter or not fully initialised channel the return value is eCOS404_AI_ST_UNKNOWN .

◆ Cos404_AI_Init()

void Cos404_AI_Init ( uint8_t  ubChannelV,
Cos404_AI_Config_ts ptsConfigurationV 
)
Parameters
[in]ubChannelVAnalog input channel
[in]ptsConfigurationVPointer to memory with configuration data of struct Cos404_AI_Config_ts

This function performs an initialization of the analog input channel defined by ubChannelV, the value for the parameter starts at eCOS404_CHANNEL_1 and is limited by the definition of COS_DS404_AI. The parameter ptsConfigurationV is a pointer to the configuration structure Cos404_AI_Config_ts.

Please refer to the section Module Initialization for an example.

Note
This function shall be called by the application prior to the CosMgrStart() function.

◆ Cos404_AI_SetDecimalDigitsPV()

uint8_t Cos404_AI_SetDecimalDigitsPV ( uint8_t  ubChannelV,
uint8_t  ubDigitsV 
)
Parameters
[in]ubChannelVAnalog input channel
[in]ubDigitsVNumber of decimal digits
Returns
eCosSdo_WRITE_OK on success or any other value from CosSdo_e in case of an error

This function should be called by application at change of sensor type to define number of decimal digits of provided process value.

◆ Cos404_AI_SetFV_Int16()

void Cos404_AI_SetFV_Int16 ( uint8_t  ubChannelV,
uint8_t  ubStatusV,
int16_t  swFieldValueV,
int16_t  swProcessValueV 
)
Parameters
[in]ubChannelVAnalog input channel
[in]ubStatusVStatus of analog input values, provided by Cos404_AI_Status_e
[in]swFieldValueV16-bit field value
[in]swProcessValueV16-bit process value
See also
Cos404_AI_SetFV_Real32()

This function converts the field value swFieldValueV and process value swProcessValueV to a float representation and calls Cos404_AI_SetFV_Real32().

◆ Cos404_AI_SetFV_Int32()

void Cos404_AI_SetFV_Int32 ( uint8_t  ubChannelV,
uint8_t  ubStatusV,
int32_t  slFieldValueV,
int32_t  slProcessValueV 
)
Parameters
[in]ubChannelVAnalog input channel
[in]ubStatusVStatus of analog input values, provided by Cos404_AI_Status_e
[in]slFieldValueV32-bit field value
[in]slProcessValueV32-bit process value
See also
Cos404_AI_SetFV_Real32()

This function converts the field value slFieldValueV and process value slProcessValueV to a float representation and calls Cos404_AI_SetFV_Real32().

◆ Cos404_AI_SetFV_Real32()

void Cos404_AI_SetFV_Real32 ( uint8_t  ubChannelV,
uint8_t  ubStatusV,
int32_t  slFieldValueV,
float  ftProcessValueV 
)
Parameters
[in]ubChannelVAnalog input channel
[in]ubStatusVStatus of analog input values, provided by Cos404_AI_Status_e
[in]slFieldValueV32 bit value, that represent RAW value for example of an ADC
[in]ftProcessValueVfloat process value, scaled value representing a physical quantity

This function sets the field value (index x100h) slFieldValueV, the process value (index x130h) ftProcessValueV and the input status (index 6150h) ubStatusV for the analog input channel defined by ubChannelV.

The function updates the objects for all supported data types (refer to COS_DS404_DT_INT16, COS_DS404_DT_INT32 and COS_DS404_DT_FLOAT).

Please refer to the section Analog value processing for an example.

◆ Cos404_AI_SetPhysicalUnitPV()

uint8_t Cos404_AI_SetPhysicalUnitPV ( uint8_t  ubChannelV,
uint32_t  ulPhysicalUnitV 
)
Parameters
[in]ubChannelVAnalog input channel
[in]ulPhysicalUnitVPhysical unit of the process value
Returns
eCosSdo_WRITE_OK on success or any other value from CosSdo_e in case of an error

This function should be called by application at change of sensor type to define corresponding physical unit of provided process value.

The cos303.h contains the COS303_PHYSICAL_UNIT() macro and Cos303_SI_Unit_e to setup this value.

Variable Documentation

◆ atsCos404_AI_ProcessDataG

atsCos404_AI_ProcessDataG
extern

This array holds processing values that can are accessed SDO and PDO. The access via PDO and possibility to map values is the reason why it is declared as a global variable.