Hi nre,
If you just want to measure 3 ADC channels by SW trigger, let the Conversion control group to be 0 for all channels (Conversion control groups are useful in case of HW trigger, please see the tool tip for the Conversion control group item in component, to see it you have to move mouse over values in the table not the name of the item).
ADC0_channelsConfig[] is the array generated by component with measured channel settings.
There are two options:
1) polling mode:
/* for cycle through selected channels see ADC0_channelsConfig[] array */
for(int i=0; i<3; i++) {
/* Initialize channel - in case of SW trigger start measure immediatelly */
ADC16_SetChannelConfig(ADC0_PERIPHERAL, ADC0_CH0_CONTROL_GROUP, &ADC0_channelsConfig[i]);
while (ADC16_GetChannelStatusFlags(ADC0_PERIPHERAL, ADC0_CH0_CONTROL_GROUP) != kADC16_ChannelConversionDoneFlag) {}
result_values[i] = ADC16_GetChannelConversionValue(ADC0_PERIPHERAL, ADC0_CH0_CONTROL_GROUP);
}
2) interrupt mode:
step 1) create global or static variable uint8_t i = 0; // hold the index to the ADC0_channelsConfig[] array
step 2) In ADC component please select Conversion complete interrupt for all channels and Initialize channel in the first channel, it leads to start measurement right at the end of initialization, then the rest of code is in the interrupt subroutine:
{
result_values[i] = ADC16_GetChannelConversionValue(ADC0_PERIPHERAL, ADC0_CH0_CONTROL_GROUP);
i++;
i = i % 3;
ADC16_SetChannelConfig(ADC0_PERIPHERAL, ADC0_CH0_CONTROL_GROUP, &ADC0_channelsConfig[i]);
}
this code will run through the all 3 channels endlessly.
If you want to run only one loop:
{
result_values[i] = ADC16_GetChannelConversionValue(ADC0_PERIPHERAL, ADC0_CH0_CONTROL_GROUP);
i++;
if (i < 3) {
ADC16_SetChannelConfig(ADC0_PERIPHERAL, ADC0_CH0_CONTROL_GROUP, &ADC0_channelsConfig[i]);
}
}