Part Number: EK-TM4C1294XL
Hi all,
I'm facing a strange issue regarding the ADC. I would like to convert X times the temperature sensor as fast as possible (in the future it will be an analog signal). So I enable the ADC, use the ADC handler and interrupt to put the result in a global variable and I want to wait for having my X samples. However even if the samples are done I m not able to use a loop for waiting for the end of the X samples. I don't understand why the code is stuck after the end of the sampling.
Actually if I put the line while(adc_seq < 1000{} in end of my main to wait for end of sampling then the code is stuck. If I don't use that line then it works. I must be sure that the X samples are done before starting the remaining code so I have to wait. Has someone an idea ?
thanks in advance
static int adc_seq = 0;
static uint32_t adc_data[1000];
void ADC0seq3_Handler(void){
uint32_t ADC0Value[1];
ADCSequenceDataGet(ADC0_BASE, 3, ADC0Value); // Retrieve value.
adc_data[adc_seq] = (1475 - ((2475 * ADC0Value[0]))/4096)/10; // Formula in data sheet VNREF 0 and VREFP 3.3 all *10 to avoid fraction.
if(adc_seq < 1000){ // ADC must still work
adc_seq++;
ADCIntClear(ADC0_BASE, 3);
}
else{ //Disable ADC after 1000 samples
ADCSequenceDisable(ADC0_BASE, 3);
}
}
void InitConvertADC(void){
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // Enable the ADC0.
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0)){} // Wait till ADC0 is ready.
ADCSequenceDisable(ADC0_BASE, 3); // Sequencer must be disabled before config : SS3 of ADC0
ADCIntDisable(ADC0_BASE, 3); // Disable interruption for ADC0
IntDisable(INT_ADC0SS3_TM4C129); // Disable interruption feature for the sequence 3 of ADC0
ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_FULL, 1);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_ALWAYS, 0); // Use ADC0, sample sequencer 3 with always trigger
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);
ADCIntClear(ADC0_BASE, 3); // Clear interrupt flag.
IntEnable(INT_ADC0SS3_TM4C129); // Enable interrupt feature.
ADCIntEnable(ADC0_BASE, 3); // Enable sequencer interrupt.
ADCSequenceEnable(ADC0_BASE, 3); // Enable sequencer ADC0 seq3.
}
int main(void)
{
while(adc_seq < 1000){
adc_data[adc_seq] = 0;
adc_seq++;
}
adc_seq = 0; // Reset adc_seq
BoardInit(); // Initialize the board.
ConsComInit(); // Initialize the communication with the computer via UART0.
UARTprintf("\033[2J\033[H");
UARTprintf("TEST\n\n"); // Print banner
InitConvertADC(); // Start convertion
while(adc_seq < 1000{} // If this line is used then the code is stuck and I never get farther. If not used then it works.
UARTprintf("\nAnalog to digital conversion is now over\n");
}