Hi,
I am using S32k146, and I want to use 15 pins as an ADC.(most of them to monitor the temperature data)
ADC0: 10channels, ADC1: 5channels
Here I know that I can use HW or SW trigger in the ADC.
But according to the S32K reference manual, if I use HW trigger, I can only use a maximum of 8 channels from each ADC module.
So I want to use the SW trigger to overcome this issue. But here, only the SC1A register is available for SW trigger.
1. I want to know how to trigger 15 ADC channels by this single SC1A register.
Can anyone provide an example for this?
2. Is there any other way to use 10 ADC channels in the HW trigger mode?
Thank you
@mariuslucianand, @adriantudor Can you help me with this?
Hello, I hope it is still useful to you. Here you have the most relevant part of code:
typedef struct {
uint8_t chan;
uint8_t mod;
} TCA_ADCCFG_TYPE;
typedef struct {
TCA_ADCCFG_TYPE var[TCA_NUMBER_OF_SWITCHES];
} TCA_ADCCFG_ARRAY;
void ConvertADCChan(ADC_MOD_TYPE adcMod, uint16_t adcChan) {
ADC_Type* ADC;
switch (adcMod) {
case MODULE_0:
ADC = ADC0;
break;
case MODULE_1:
ADC = ADC1;
break;
default:
ADC = ADC0;
break;
}
/* For SW trigger mode, SC1[0] is used */
ADC->aSC1[0] = ADC_aSC1_ADCH(adcChan); // Initiate Conversion
}
uint8_t ADCComplete(ADC_MOD_TYPE adcMod) {
ADC_Type* ADC;
switch (adcMod) {
case MODULE_0:
ADC = ADC0;
break;
case MODULE_1:
ADC = ADC1;
break;
default:
ADC = ADC0;
break;
}
return ((ADC->aSC1[0] & ADC_aSC1_COCO_MASK)>>ADC_aSC1_COCO_SHIFT);
}
uint32_t ReadADCChx(ADC_MOD_TYPE adcMod) {
uint16_t adc_result=0;
ADC_Type* ADC;
switch (adcMod) {
case MODULE_0:
ADC = ADC0;
break;
case MODULE_1:
ADC = ADC1;
break;
default:
ADC = ADC0;
break;
}
/* For SW trigger mode, R[0] is used */
adc_result = ADC->aR[0];
adc_result &= 0x00000FFF;
return (uint32_t) adc_result;
}
for (i=0;i<NUMBER_OF_CHANNELS;i++) {
ConvertADCChan(MON_ADC.var[i].mod, MON_ADC.var[i].chan);
while(ADCComplete(MON_ADC.var[i].mod)==0){}
MON_value[i] = ReadADCChx(MON_ADC.var[i].mod);
}