Hello,
We are noticing that the ADC driver may get locked up and start returning the same value once it does. Is there a suggested way to prevent the adc from getting into this state?
Thanks.
Ubaid
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello,
We are noticing that the ADC driver may get locked up and start returning the same value once it does. Is there a suggested way to prevent the adc from getting into this state?
Thanks.
Ubaid
Hello Jean-Marc,
We are using Halcogen 4.0.3 and have the following driver logic (we had to modify auto-generated driver :
We are a few tasks that are polling the ADC values manually. Each invokes the following routine to get the value from the adc_data_ptr struct:
uint16 bsp_ADC1_GET (uint8 terminal)
{
adcData_t adc_data;
adcData_t *adc_data_ptr = &adc_data;
/** - Start Group ADC Conversion
*/
adcStartConversion_SelChn(adcREG1, terminal, ADC_FIFO_SIZE, ADC_SUBGROUP_01);
/** - Wait for ADC Group conversion to complete */
while(!adcIsConversionComplete(adcREG1, ADC_SUBGROUP_01));
/** - Read the conversion result
*/
adcGetSingleData(adcREG1, ADC_SUBGROUP_01, adc_data_ptr);
return(adc_data_ptr->value);
}
We were advised when we were using Halcogen 4.0.1 to use the following routines: adcStartConversion_SelChn, adcGetSingleData. Now that we are on Halcogen 4.0.3, do the routines need updating?
The defines/routines are :
#define ADC_FIFO_SIZE 1
/** @fn void adcGetSingleData(adcBASE_t *adc, unsigned group, adcData_t *data)
* @brief Get single converted ADC value
* @param[in] adc Pointer to ADC module:
* - adcREG1: ADC1 module pointer
* - adcREG2: ADC2 module pointer
* - adcREG3: ADC3 module pointer
* @param[in] group Hardware group of ADC module:
* - adcGROUP0: ADC event group
* - adcGROUP1: ADC group 1
* - adcGROUP2: ADC group 2
* @param[out] data Pointer to store ADC converted data
*
*/
void adcGetSingleData(adcBASE_t *adc, unsigned group, adcData_t *data)
{
unsigned buf;
adcData_t *ptr = data;
/** - Get conversion data and channel/pin id */
buf = adc->GxBUF[group].BUF0;
ptr->value = (unsigned short)(buf & 0xFFFU);
ptr->id = (unsigned short)((buf >> 16U) & 0x1FU); //!< int to unsigned short
adc->GxINTFLG[group] = 9U;
/** @note The function canInit has to be called before this function can be used.\n
* The user is responsible to initialize the message box.
*/
}
/** @fn void adcStartConversion_SelChn(adcBASE_t *adc, unsigned channel, unsigned fifo_size, unsigned group)
* @brief Starts an ADC conversion
* @param[in] adc Pointer to ADC module:
* - adcREG1: ADC1 module pointer
* - adcREG2: ADC2 module pointer
* @param[in] channel ADC channel to be selected for conversion
* @param[in] fifo_size ADC fifo size to be configured.
* @param[in] group Hardware group of ADC module:
* - adcGROUP0: ADC event group
* - adcGROUP1: ADC group 1
* - adcGROUP2: ADC group 2
*
* This function Starts the convesion of the ADC selected group for the selected channel
*
*/
void adcStartConversion_SelChn(adcBASE_t *adc, unsigned channel, unsigned fifo_size, unsigned group)
{
/** - Setup FiFo size */
adc->GxINTCR[group] = fifo_size;
/** - Start Conversion */
adc->GxSEL[group] = 1 << channel;
}
5282.HalCoGen.zipHere you go. Please keep in mind the additional adc routines that were defined earlier that do not exist in halcogen
Thanks.
Ubaid,
In Halcogen, you are selecting for Group1 18 channel to be converted.
In your code, you are selecting 1 channel at the time when you call adcStartConversion_SelCh.
With the actual data, I can't really help you.
I need to have a high level picture of what you are trying to achieve.
Please provide some kind of flow chart or algorithm.
Also, are you using interrupt or polling mode?