iLLD_TC27xC  1.0
How to use the DSADC Interface driver?
Collaboration diagram for How to use the DSADC Interface driver?:

The DSADC interface driver provides a default DSADC configuration for converting analog data streams inputs from external modulators via digital input channels, into digital values by using the on-chip demodulator channels.

In the following sections it will be described, how to integrate the driver into the application framework.

Preparation

Include Files

Include following header file into your C code:

#include <dsadc_commands.h>

Variables

Declare the DSADC channel handle and available channels as global variables in your C code:

static IfxDsadc_Dsadc dsadc;
#if defined(DERIVATIVE_TC22x) || defined(DERIVATIVE_TC23x) || defined(DERIVATIVE_TC24x)
uint8 dsadcChannelAvailable[IFXDSADC_NUM_CHANNELS] = { 1, 0, 0, 1 };
#elif defined(DERIVATIVE_TC27x) || defined(DERIVATIVE_TC27xB) || defined(DERIVATIVE_TC27xC) || defined(DERIVATIVE_TC27xD)
uint8 dsadcChannelAvailable[IFXDSADC_NUM_CHANNELS] = { 1, 1, 1, 1, 1, 1 };
#elif defined(DERIVATIVE_TC26x) || defined(DERIVATIVE_TC26xB)
uint8 dsadcChannelAvailable[IFXDSADC_NUM_CHANNELS] = { 1, 0, 1, 1 };
#elif defined(DERIVATIVE_TC29x) || defined(DERIVATIVE_TC29xB)
uint8 dsadcChannelAvailable[IFXDSADC_NUM_CHANNELS] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
#else
# error "Testcase not prepared for this derivative!"
#endif

Module Initialisation

The module initialisation can be done in the same function. Here an example:

// disable pull-up devices for analog pads of P00 (assigned to some analog pins)
P00_IOCR0.U = 0x00000000;
P00_IOCR4.U = 0x00000000;
P00_IOCR8.U = 0x00000000;
P00_IOCR12.U = 0x00000000;
// create module config
IfxDsadc_Dsadc_initModuleConfig(&dsadcConfig, &MODULE_DSADC);
// initialize module
IfxDsadc_Dsadc_initModule(&dsadc, &dsadcConfig);
// create channel config
IfxDsadc_Dsadc_ChannelConfig dsadcChannelConfig;
IfxDsadc_Dsadc_initChannelConfig(&dsadcChannelConfig, &dsadc);
// modify default configuration
dsadcChannelConfig.modulator.inputPin = IfxDsadc_InputPin_a;
dsadcChannelConfig.modulator.modulatorClockFreq = 10.0e6;
dsadcChannelConfig.combFilter.bypassed = FALSE;
dsadcChannelConfig.combFilter.decimationFactor = 32;
dsadcChannelConfig.combFilter.startValue = 32;
dsadcChannelConfig.firFilter.fir0Enabled = TRUE;
dsadcChannelConfig.firFilter.fir1Enabled = TRUE;
dsadcChannelConfig.firFilter.offsetCompensation = FALSE;
// initialize channels
for(int chn=0; chn<IFXDSADC_NUM_CHANNELS; ++chn) {
if( dsadcChannelAvailable[chn] ) {
dsadcChannelConfig.channelId = (IfxDsadc_ChannelId)chn;
IfxDsadc_Dsadc_initChannel(&dsadcChannel[chn], &dsadcChannelConfig);
}
}

The DSADC is ready for use now!

Conversions

The DSADC driver provides simple to use Conversion function,

// start conversions
IfxDsadc_Dsadc_startScan(&dsadc, 0x3f, 0x3f);
// results are now available in IFXDSADC(ds).CH[x].RESM.B.RESULT (x=0..5)

The converted data can be collected using the following function

// declared globally
// sint16 result[];
result = IfxDsadc_Dsadc_getMainResult(&dsadcChannel[chn]));