extremly unstable readout with internal ADC

23 Mar 2011

Hi,

I was testing the analog input. A few weeks ago i also tested is, and readout was fine. But now it is unstable. I give it 3.3Vin , and the readout varies between 2V and 5V.

code:

void MeasureBattery() {

        usCurrentValue =(Sense5.read_u16()&0xFFF);
        //pc.printf("batterij op: %d  \n\r", (usCurrentValue*5/4095));
         pc.printf("\n ADC Val : %f Volts = %d (Decimal Reading) \n\r",(usCurrentValue*5.0/4095),usCurrentValue);
        wait(5);
        // what do we if under 20% ?? do a warning and shutdown?
        // code comes heres

 // main();      
        }

Any thoughts about whats going on?

23 Mar 2011

Hi,

Did you ground any other ADC input or changed design?

23 Mar 2011

I got an external ADC hooked up to the Mbed. I will test it without it.

23 Mar 2011

No Difference.

Tested it with a potentiometer. At any given setting the output is stable ??

Strange.

24 Mar 2011

marcel van de Kamp wrote:

I give it 3.3Vin , and the readout varies between 2V and 5V.

   pc.printf("\n ADC Val : %f Volts = %d (Decimal Reading) \n\r", usCurrentValue*5.0/4095),usCurrentValue);

Your printf statement gives 5.0 volts for full scale, while the mbed ADC has a maximum input level of 3.3 volts (unless you have added an external voltage divider). So getting a readout of "5V" when 3.3V is applied would be the expected behavior.

On the other hand, getting a 2V readout with 3.3V applied is definitely not expected :-)

A floating input pin can cause this kind of behavior. Any chance the input lead has come adrift (or, equivalently, that the pin definition for Sense5 does not match the pin number actually in use)?

25 Mar 2011

Hexley,

I didn't think about the 3.3V input. So lets say i want to measure the status of an external battery, thats has an output of 5V, than i have use a divider first?

25 Mar 2011

Hello Marcel, I post a numerical filter on "AnalogIn problem" with a document in french. Maybe it can help you The document describe step by step with graphs the progress.

At this time, I'm working to make the same, with real number and http interface with 6 adc

Best Regards François Rigaud

25 Mar 2011

marcel van de Kamp wrote:

So lets say i want to measure the status of an external battery, thats has an output of 5V, than i have use a divider first?

Yes, you need a divider. Like this:

https://lh6.googleusercontent.com/_uPXih5V64C0/TY0Efhw26iI/AAAAAAAAAFg/DnBYqYUmxGg/s800/Voltage%20Divider.JPG

If you choose the bottom resistor as exactly twice the value of the top resistor, this will scale the battery voltage by 2/3. That gives 3.33 volts out for 5 volts in. But you might want to juggle values a bit so that you get a little less than 3.3 volts out for 5 volts in. That would help make sure that the ADC value doesn't max out due to tolerances in the resistor network and in the reference voltage.

For example, if you drop the bottom resistor to 2.7K, the output will be 3.0 volts for 5 volts in. You can work out other ratios using the rule that Vout = Vin * Rbottom / (Rtop + Rbottom).

28 Mar 2011

Thanks,

this is good info. I'll use it to get things done.

28 Mar 2011

Note that this divider will leak about 1mA out of your battery. Depending on your application, that might be a problem.

15 Apr 2011

Hi my adc is very unstable i only probe read a value from a potentiometer conected to 3.3v and gnd and one lcd to present the value in the lcd i can read the value between 0.0 to 1.0 and read well for example 0,5.... but it chages to 1,00 and return 0,5... and repeat and repeat, the same thing happen when i conecct the input to groun the value is 0,000 and change to 1,000 the code is

#include "mbed.h"
#include "TextLCD.h"
 TextLCD lcd(p5, p6, p7, p8, p9, p10); 

PwmOut out(p21);
AnalogIn vel(p16);
DigitalOut out1(p27);
DigitalOut out2(p28);

int main() {
   out1=1;
   out2=0;
    while(1) {
   
    out=vel.read();
    
    lcd.locate(0,1);
   lcd.printf("%0.3f   ",vel.read());
    wait(0.3);
       
    }
}

i also probe without lcd only with adc and pwm to LED1 and i have the same

please help me thanks