ADC strange behaviour

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

ADC strange behaviour

1,068 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Genesy on Fri Nov 15 10:21:05 MST 2013
Hi,
as the title, I have a strange behaviour with ADC.
The program is this:
static uint32_t ADCChannelAcquisition(uint8_t channel){
ADCRead( channel );
while ( !ADCIntDone );
ADCIntDone = 0;
return ADCValue[channel];
}

int main(void) {

SystemInit();
ADCInit( ADC_CLK );

int i;
uint32_t val=0;
uint32_t acquisition[10];

uint32_t count=0;

//for (i=0; i<100000; i++){
//count++;
//}

for (i=0; i<10; i++){
acquisition = ADCChannelAcquisition(0);
}

for (i=0; i<10; i++){
val += acquisition;
}

uint32_t valRif = (uint32_t)(((float)val  / 10.0) + 0.5);


return 0 ;
}

The behaviour is different if I insert a breakpoint in the first acquisition as you can see in the attached images.
In the first case the values ​​are higher than in the second case. What is the reason?
What values ​​are reliable?

I tried to insert a delay before making ADC readings, but nothing has changed.

Thank you very much
Labels (1)
0 Kudos
Reply
4 Replies

1,044 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Genesy on Tue Nov 19 01:37:01 MST 2013
Ok, I will try with your suggestions.
The ADC input is a voltage divider from a hall effect sensor.

Thank you very much Marc.

0 Kudos
Reply

1,044 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MarcVonWindscooting on Mon Nov 18 12:11:47 MST 2013
Have you tried with a long delay in the seconds range (like your breakpoint does)?
100*1000 loops isn't that much nowadays ;-)

Also, are you sure, the loop is executes as expected? I believe so, too. But to be 100% sure, declare count 'volatile'.
What is the input circiut to your ADC? Voltage divider?
0 Kudos
Reply

1,044 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Genesy on Mon Nov 18 01:51:54 MST 2013
Yes, I also thought that it could be a matter of timing and I inserted a short delay but wasn't enough.
Than it should be this late?
0 Kudos
Reply

1,044 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MarcVonWindscooting on Sat Nov 16 06:26:50 MST 2013
Just a guess: before Init the port pin is GPIO with pullup.
The you switch to ADC input and start sampling within a few us. Pretty short time!
Can your excess reading be the removed pullup-current + low-pass behaviour?
0 Kudos
Reply