Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 1 month ago.
weird problem with voltage divider to get analog signal
I am having problem getting the correct voltage value using AnalogIn function. I'm trying to get 2.6V based on the voltage divider circuit from a 12V source. Everything is connected to common ground.
I got incorrect value of around 0.01V using the analogIn pin.
With mbed connected to the circuit, i got 11.99V and 0.01V on the 4.7K and 1.3K resistor respectively using multi-meter.
With mbed removed, i got the correct value of 9.4V and 2.6V on the 4.7K and 1.3K resistor respectively using multi-meter.
#include "mbed.h" AnalogIn VOLTAGE(p20); float value; int main() { while (1) { value = 3.3 * VOLTAGE.read(); printf("%.4f value\n", value); wait(1); } }
1 Answer
8 years ago.
If this reading only happens when you go to do the AD conversion it could be your input impedance is too high. You could try putting a cap across the 1.3k resistor to ground. You have to charge up a little cap inside the micro when it goes to do the AD reading and if the external resistance is too high you won't be able to charge up that cap fast enough. Adding a parallel cap, say 1 to 10uF, buffers it.
But if your multimeter measures 0V across the 1.3k when p20 is connected, the implication here is that p20 is pulled low and pulling down the voltage on that node. This could happen if p20 were configured as a digital output, which seems unlikely, unless there is some sort of bug in the library. Or it could happen if the pin is damaged. If you happened to exceed 5V on that pin you could damage it. Maybe try connecting to a different analog in pin?
Graham