Electronic – Minimising current consumption in a PIC

low-powerpic

I'm using a PIC16LF1554 with a simple soil moisture sensor to remotely monitor houseplants. The sensor circuit will be powered by a coin cell and will spend most of its time asleep. It will wake periodically (maybe three times daily) to take a reading via ADC, transmit to an always-on master via nRF24l01+ and then go back to sleep. This is a hobby/learning project, not a commercial enterprise.

My question is about minimising current consumption in sleep mode, about which the datasheet says:

To minimize current consumption, the following conditions should be
considered:

  • I/O pins should not be floating
  • External circuitry sinking current from I/O pins
  • External circuitry sourcing current from I/O pins
  • Current draw from pins with internal weak pull-ups
  • Modules using 31 kHz LFINTOSC

I'm comfortable with all but the first item, but I have a number of I/O pins that I'm not using, so I've not connected them to anything in the PCB I've designed (maybe that was stupid). The datasheet goes on to say:

I/O pins that are high-impedance inputs should be pulled to
VDD or VSS externally to avoid switching
currents used by floating inputs.

So, my question. Is it ok to configure my unconnected I/O pins as outputs and set them LOW (or HIGH)? Would that result in any unnecessary current draw?

Best Answer

Digital inputs are designed to be either high or low. If they are left to float in the middle, they will draw larger amounts of current on the input part of the circuit. This is what you want to avoid for best power savings.

If you want a better understanding of this put a ammeter on your PIC and connect a potentiometer to vary an input pin. As you vary the voltage into the middle of the range, you will see an increase in current. If you were to do this for all the pins, it would add up to quite a bit of current.

Fortunately, driving an output with no external load (i.e. an unconnected pin) requires no current at all. CMOS circuits only consume significant power when switched or directly loaded.

Therefore, you should set all unconnected I/O pins as outputs. It generally doesn't matter whether you drive them high or low. In some microcontrollers, one direction will give a slightly better power savings, so perhaps some testing is would be useful. (I don't recall this being an issue with the PIC family though).

Note also, that in some PIC devices, you have registers that control outputs that don't actually exist on the chip. In reality, they exist on the silicon die, but are not bonded out to the package. For the best power savings, you should drive those out as well, since leaving them floating will increase power.

As an aside, the typical way to do this is to put an ammeter in line with your power and see how low you can get it. Microcontrollers tend to have a lot of options that draw power, and it is easy to miss a couple. You should be able to get very close to the datasheet numbers.