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.
11 years, 7 months ago.
FRDM-KL25Z AnalogIn wrong Values
Hi team,
I'm just starting and wanted to do a very simple test and read the voltage from an analog input pin (PTB2). Therefore I have a power-source with 3V directly connected to it. So I would expect a value around 0.9 or so (as 3.3V is maximum = 1).
Unfortunately the value I read is fluctuating basically between 0 and 1 and is never static. Even when nothing is connected to the board this program is reading random values around 0.1 - 0.2V Is there a simple mistake I do?
My code:
Example
#include "mbed.h"
Serial pc(USBTX, USBRX); // tx, rx
PwmOut led(LED_RED);
AnalogIn voltage(PTB2);
int main() {
pc.printf("Meassuring the input voltage");
while(true) {
printf("Voltage (%f)\n", voltage.read());
wait(0.2);
}
}
Best Regards Kilian
1 Answer
11 years, 7 months ago.
please use <<code>> <</code>> tags around your code when posting to keep it readable.
Do you have a common ground pin? Seems that 0.1V is way off the expected value, but maybe there is a lot of noise on the analog power source, have you checked with a scope.