9 years, 11 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

9 years, 11 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.

Accepted Answer

This comment was very helpful. We connected the sensor and the board to a common ground and then we got stable results. Thanks a lot!

posted by K H 14 May 2014