Other Parts Discussed in Thread: HALCOGEN
Tool/software:
Dear Community,
I have the following HALCoGen configuration for the Hercules ADC... and as expected, the selected pins from the image affect the value of s_adcSelect[2U][3U]:
Then, I am following the official example that suggests:
adcStartConversion(adcREG1, adcGROUP1); while(!adcIsConversionComplete(adcREG1, adcGROUP1)); adcGetData(adcREG1, adcGROUP1, &adc_data);
The generated code for adcStartConversion uses the 2D array (s_adcSelect), which makes me think that all of the configured channels could be processed in a single call. I imagine that this will make the ADC sequencer jump over all of the selected channels, and save the results to a some array in key-value pair style (PinID and converted value).
void adcStartConversion(adcBASE_t *adc, uint32 group)
{
uint32 index = (adc == adcREG1) ? 0U : 1U;
/* USER CODE BEGIN (7) */
/* USER CODE END */
/** - Setup FiFo size */
adc->GxINTCR[group] = s_adcFiFoSize[index][group];
/** - Start Conversion */
adc->GxSEL[group] = s_adcSelect[index][group];
/** @note The function adcInit has to be called before this function can be used. */
/* USER CODE BEGIN (8) */
/* USER CODE END */
}
However, inside the adcGetData implementation, I don't see any iteration over the channels (pins), only over the FIFO size (at least I observe that uint32 count variable gets set equal to the FIFO size configured in HALCoGen):
uint32 adcGetData(adcBASE_t *adc, uint32 group, adcData_t * data)
{
uint32 i;
uint32 buf;
uint32 mode;
uint32 index = (adc == adcREG1) ? 0U : 1U;
uint32 intcr_reg = adc->GxINTCR[group];
uint32 count = (intcr_reg >= 256U) ? s_adcFiFoSize[index][group] : (s_adcFiFoSize[index][group] - (uint32)(intcr_reg & 0xFFU));
adcData_t *ptr = data;
/* USER CODE BEGIN (16) */
/* USER CODE END */
mode = (adc->OPMODECR & ADC_12_BIT_MODE);
if(mode == ADC_12_BIT_MODE)
{
/** - Get conversion data and channel/pin id */
for (i = 0U; i < count; i++)
{
buf = adc->GxBUF[group].BUF0;
/*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
ptr->value = (uint16)(buf & 0xFFFU);
ptr->id = (uint32)((buf >> 16U) & 0x1FU);
/*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */
ptr++;
}
}
else
{
/** - Get conversion data and channel/pin id */
for (i = 0U; i < count; i++)
{
buf = adc->GxBUF[group].BUF0;
/*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
ptr->value = (uint16)(buf & 0x3FFU);
ptr->id = (uint32)((buf >> 10U) & 0x1FU);
/*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */
ptr++;
}
}
adc->GxINTFLG[group] = 9U;
/** @note The function adcInit has to be called before this function can be used.\n
* The user is responsible to initialize the message box.
*/
/* USER CODE BEGIN (17) */
/* USER CODE END */
return count;
}
Even when setting only channel 6 as an active one (where the phototransistor on the Launchpad is connected), I get zero for the adcData_t->id field:
adcStartConversion(adcREG1, adcGROUP1);
while(!adcIsConversionComplete(adcREG1, adcGROUP1));
adcGetData(adcREG1, adcGROUP1, &adc_data);
printf("Pin: %u ADC: %u\n", adc_data.id, adc_data.value);
And below is my printf log:
Pin: 0 ADC: 806
My question is: considering the architecture of the API, is there a way to send a single "call" to the ADC and ask the sequencer to jump over each of the selected channels and return the PinID-AdcValue for each channel (if possible, by using the actual pin IDs from the HALCoGen configuration)?
Thanks!



