Continuous ADC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Continuous ADC

753 Views
alexit
Contributor I

I am using continuous conversion mode for ADC to convert one pin and the internal temperature sensor on a QD4. The PE bean is set for prescaler 8, long sample, with 10-bit right format. The code I am attempting within my Main loop is:

 

ReadADC(uint8_t channel)

{

TWREG tmpTwreg;

if(channel == 0) /* ADC Pin 3 */

{ADCSC1 = 0x03U;}

else if (channel == 1) /* Internal TempSensor */

{ADCSC1 = 0x1AU;}

 

if (ADCSC1_COCO == 1)

tmpTwreg.b.high = ADCRH;

tmpTwreg.b.low = ADCRL;

return (word)((tmpTwreg.w) << 5);

}
This gives me no results, why is continuous mode not providing data to ADCRH and ADCRL?

Thanks, D

Labels (1)
0 Kudos
3 Replies

451 Views
alexit
Contributor I


Ok, I found the first issue, typo in channel call:

ReadADC(uint8_t channel)

{

TWREG tmpTwreg;

if(channel == 0) /* ADC Pin 3 */

{ADCSC1_ADCH= 0x03U;}

else if (channel == 1) /* Internal TempSensor */

{ADCSC1_ADCH = 0x1AU;}

if (ADCSC1_COCO == 1)

tmpTwreg.b.high = ADCRH;

tmpTwreg.b.low = ADCRL;

return (word)((tmpTwreg.w) << 5);

}

Second issue is this returns a value that is offset from the GetChanValue(). Its providing a value almost 50% higher for a given input. Do I need to call a calibration before using this?

0 Kudos

451 Views
vicentegomez
NXP TechSupport
NXP TechSupport

Hi David

Please check the application note AN3031
Have a great day,
Vicente

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

451 Views
alexit
Contributor I

I am sorry I was not clear in my earlier post, all ADC channels are measuring with an offset (not just temp sensor) with the Init_ADC bean in continuous mode compared to the ADC_GetChanValue method.

i.e. with 0.393V appied to ADC Channel 3 and using the above code I receive 140 counts of 1023. Using the GetChanValue method i receive 93 counts of 1023. Does the ADC bean have something addtitional to correct for error? (I have both beans configured long sample 10-bit right justified results, in the ADC bean I am using 2 samples setting and in Init_ADC method I am software averaging later in the code like:

reading0 += ReadADC(0);

reading0 /= 2;

reading1 += ReadADC(1);

reading1 /= 2;

thanks,D

0 Kudos