9 years, 6 months ago.

KL05 deep sleep mode with analog in pin

I have a circuit which uses an analog input pin but then during deep sleep that pin needs to be set as a digital output low to prevent leakage current into another device. I tried adding the following code

AnalogIn conn(PTA12);

  1. define setRegBits(reg, mask, bits) { reg &= mask; reg |= bits; }

PTA->PDDR |= 1<<12; output PTA->PCOR |= 1<<12; low setRegBits(PORTA->PCR[12],0x0700,0x0100); gpio

This method worked fine for converting serial port pins to output low, but for analog there is still an extra 100uA of current over the normal deepsleep current. Is there something I have to shut down in the analog configuration to get to the minimum current?

Thanks, Tom

Sorry, I forgot to put the code tags around the code.

#define setRegBits(reg, mask, bits) { reg &= ~mask; reg |= bits; }
AnalogIn int2(PTA12);

PTA->PDDR |= 1<<12;                        // output
PTA->PCOR |= 1<<12;                        // low
setRegBits(PORTA->PCR[12],0x0700,0x0100);  // gpio
posted by Tom Russell 15 May 2015

1 Answer

9 years, 6 months ago.

It should not be required to put it as GPIO: AnalogIn is high impedance, so it should not be able to create any current which can go into another device.

However your 100uA is familiar: The Freescale ADC consumes roughly that in deepsleep when it is set at its high speed mode. I consider this to be a bug, since it should be disabled in deepsleep, but I don't know if Freescale agrees with me. However something like 2 months ago I submitted pull request that fixes this (not that nicest code, but deepsleep code now checks if it is in this high speed mode, if yes, it disables it before entering deepsleep, and restores it afterwards).

In addition to this there is also that the ADC can make its own clock, even though it was not used this was still enabled in the code. That same pull request also fixed that.

So my guess is that you do not have the latest mbed lib (at least I am pretty sure that fix was rolled out to all KLXX and K20 devices): Can you right click your mbed lib, click update, and test again? (Unless you are sure you got the latest version).

Accepted Answer

I did use this on the KL05 and it did drop the 100uA in deep sleep, I think the Mbed libraries do have your changes Erik, when I last looked, but that may be for the KL25Z. I did mine manually when we were trying this out so can't remember.

posted by Paul Staron 15 May 2015

It turns out my mbed lib was from March. Seems to be fixed now. I would agree that it is a Freescale bug, not a feature.

posted by Tom Russell 21 May 2015