XMC1300 set gain of ADCCH001 APP

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Arno
Employee
Employee
25 replies posted 10 replies posted 5 replies posted
The ADCCH001 APP does not yet support the integrated gain of XMC1000 products so far. In order to set the gain with respect to the ADCCH001_Handle, you can use the following function:

/**
* This function sets the gain of the assigned channel
*/
status_t ADCCH001_SetGain(const ADCCH001_HandleType* HandlePtr, uint8_t GainConfig)
{
__IO uint32_t* GNCTRPtr;
uint8_t ChannelNo;

status_t Status = (uint32_t)ADCCH001_OPERATION_NOT_ALLOWED;
// DBG002_FUNCTION_ENTRY(DBG002_GID_ADCCH001, (uint32_t)ADCCH001_FUN_ENTRY);

if((GainConfig > (uint8_t)3))
{
Status = (uint32_t)ADCCH001_INVALID_PARAM;
// DBG002_ERROR(DBG002_GID_ADCCH001, (uint8_t)Status, 0, (uint8_t*) NULL);
}
else
{
if(HandlePtr->ADCGrPtr == 0)
GNCTRPtr = &(SHS0->GNCTR00);
else
GNCTRPtr = &(SHS0->GNCTR10);

if((HandlePtr->DynamicHandlePtr->State != ADCCH001_UNINITIALIZED))
{
if((HandlePtr->kChannelNo == (uint8_t)0) || (HandlePtr->kChannelNo == (uint8_t)1))
{
ChannelNo = HandlePtr->ADCGrPtr->ALIAS >> (HandlePtr->kChannelNo * (uint8_t)8);
}
else
{
ChannelNo = HandlePtr->kChannelNo;
}
*GNCTRPtr &= ~((uint32_t)0x03 << (ChannelNo * (uint8_t)4));
*GNCTRPtr |= ((uint32_t)GainConfig << (ChannelNo * (uint8_t)4));
Status = (uint32_t)DAVEApp_SUCCESS;
}
else
{
// DBG002_ERROR(DBG002_GID_ADCCH001, (uint8_t)Status, 0, (uint8_t*) NULL);
}

}

// DBG002_FUNCTION_EXIT(DBG002_GID_ADCCH001, (uint32_t)ADCCH001_FUN_EXIT);
return Status;
}


The function is called as follows (e.g for channel instance 0 with a gain of 12):
       
ADCCH001_SetGain( &ADCCH001_Handle0, 0x03 ); // 0x00: Gain 1 | 0x01: Gain 3 | 0x02: Gain6 | 0x03: Gain 12
0 Likes
0 Replies