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.

TM4C1294NCPDT ADC question

Other Parts Discussed in Thread: TM4C1294NCPDT

I have a TIVA TM4C1294NCPDT that uses ccs 6.1.2, TIRTOS 2.16.0.08, and compiler 5.2.7.

From the main before the RTOS starts, I call the function initAdc to init a ADC sequence that will read one sample from the ADC.  The sample is a voltage that is converted into temperature. 

 

void initAdc(void)

{

   uint32_t pui32ADC0Value[1];

 

   SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // enable the ADC device

   ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_HALF, 1); // set the clock.

   ADCSequenceDisable(ADC0_BASE, ADC_SEQUENCE_NUMBER3_TEMP);

   ADCSequenceConfigure(ADC0_BASE, ADC_SEQUENCE_NUMBER3_TEMP, ADC_TRIGGER_PROCESSOR, 0);

 

   ADCSequenceStepConfigure(ADC0_BASE, ADC_SEQUENCE_NUMBER3_TEMP, 0, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END );

 

   ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 64);

 

   ADCSequenceEnable(ADC0_BASE, ADC_SEQUENCE_NUMBER3_TEMP); //enable the sequence

 

   ADCIntClear(ADC0_BASE, ADC_SEQUENCE_NUMBER3_TEMP); //first clear the interrupt

 

   ROM_ADCSequenceDataGet(ADC0_BASE, ADC_SEQUENCE_NUMBER3_TEMP, pui32ADC0Value); // flush the ADC

   ROM_ADCSequenceDataGet(ADC0_BASE, ADC_SEQUENCE_NUMBER3_TEMP, pui32ADC0Value); // flush the ADC

   ROM_ADCSequenceDataGet(ADC0_BASE, ADC_SEQUENCE_NUMBER3_TEMP, pui32ADC0Value); // flush the ADC

 

}//end short initAdc(void)

Once the RTOS starts, I periodically call the function every few seconds so it’s a slow rate.

unsigned long readAdcTemp(void)

{

   unsigned long tempC;

   static unsigned long data = 0, counter = 0;

   float volts;

   uint32_t pui32ADC0Value[1];

   int32_t returnValue;

 

   ROM_ADCProcessorTrigger(ADC0_BASE, ADC_SEQUENCE_NUMBER3_TEMP); // trigger the ADC to start a conversion

   while(!ROM_ADCIntStatus(ADC0_BASE, ADC_SEQUENCE_NUMBER3_TEMP, false)) //poll till ADC is done converting

   {

   }

 

   returnValue = ROM_ADCSequenceDataGet(ADC0_BASE, ADC_SEQUENCE_NUMBER3_TEMP, pui32ADC0Value); //read the ADC value

 

   if(returnValue == 1)

   {

       data = pui32ADC0Value[0];

   }

   else

   {

       counter++;

       printf("ADC error = %d, counter = %d\n", returnValue, counter);

   }

 

   volts = ((3.3) * (data)/(0xFFF));

   tempC = (unsigned long) ( ( (volts / 2.0) - 0.424 ) * 160);

   return (unsigned long) tempC;

} //end unsigned long readAdcTemp(void)

 

The software is working as expected for the most part but sometimes I get an error where ROM_ADCSequenceDataGet() returns a value of zero. For some stress testing I sped up the reading of the ADC from the task to call readAdcTemp() every 200mS and I ran it overnight and I saw about 4 times the ROM_ADCSequenceDataGet() returned a value of 0.  I don’t know why this would sometimes fail to read the ADC.

 

Am I doing something wrong that would cause the ADC to sometimes not read?

Thanks,

Doug