9 years, 5 months ago.

Can AnalogIn configure _any_ ADC pin on the KL25Z?

I have a FRDM-KL25Z on which I have wired the coin cell voltage (TP8) over to J1-3 (PTC0/ADC0_SE14) hoping to monitor the coin cell voltage with the ADC using AnalogIn. When I configure an AnalogIn object for PTC0, it compiles and seems to run just fine (i.e. no error messages to the USB serial port or blinking lights of death), but the output is always 1.0, no matter if the coin cell is present or not. I have verified the voltage the header pin comes and goes as expected when the battery is installed and removed, and I assume it's present at the KL25Z pin 55 also (small pins not easy to probe).

Are there some ADC input pins that AnalogIn will not configure, or am I doing something else wrong? Here is my code:

#include  "mbed.h"

Serial pc(USBTX, USBRX);  // Declare the serial port 

int main( void )
{
    AnalogIn Vbatt( PTC0 );
    
    while ( 1 )
    {
        pc.printf( "Vbatt = %f\n", 3.3 * Vbatt.read() );
        wait( 1 );
    }
}

It runs and behaves as expected, except Vbatt is always 3.3, even when I remove the battery. Perhaps there is a pullup on that input that needs to be turned off?

Thanks for your help.

Figured it out. Pin floats to Vdd if not pulled down, so removing the battery had no effect. Shorting the pin to ground the output went to 0, then removing the short it floated back up to Vdd over a period of about 20 seconds.

posted by Thomas Chamberlain 06 Nov 2014
Be the first to answer this question.

Assigned to Thomas Chamberlain 9 years, 5 months ago.

This means that the question has been accepted and is being worked on.