Currently, I am using a uC (Atmel ATtiny85-PU20), which will eventually run battery powered, and I am trying to reduce power consumption of entire circuit to maximise time between battery changes. Apart from the uC this circuit has:

  1. SR HC-04 ultrasonic range sensor module
  2. This ISM band (433MHz) ASK/OOK transmitter module

While I understand how to put the uC into sleep mode, only to wake-up every 8 seconds using the watch-dog timer interrupt, I was wondering, what happens to the peripheral components/modules during this time ?

My initial thought was to put a NPN BJT as a switch, controlled by a GPIO pin, to switch the Vcc fed to the 2 modules, but is the behaviour of such a switch defined when uC goes to sleep state ?

  • \$\begingroup\$ Sufficient unto the morrow is the evil thereof. The uC will have defined pin conditions when in sleep mode (and for some the defined condition may be "float" or even possible "undefined") Each component will have defined behaviours under various drive conditions. Read all the data sheets, apply all the results and the answer is your answer. That may sound like a pedantic answer BUT it IS the answer, alas :-). ie see what they do, work out the result. \$\endgroup\$ – Russell McMahon Apr 22 '13 at 5:40
  • \$\begingroup\$ @RussellMcMahon, yes I see what you mean, and don't disagree a bit! Actually, I had read whatever is available about the sensors i.e. data-sheets (of course, they are small or hardly a data-sheet). I'll admit that I didn't read through the entire data-sheet of ATtiny, but used fair bit of search to read parts, and seem to have missed the part where pin-status/behaviour on power-state change is mentioned. \$\endgroup\$ – bdutta74 Apr 22 '13 at 5:55

Basically, the (internal) peripherals are shut off when the AVR goes to sleep. Which modules shut down depends on what sleep mode you enter into. The tinyx5 has three sleep modes: Idle, ADC Noice Reduction, and Power Down. Unless you need something to continue working while it sleeps, I would suggest the "Power Down Mode" which still allows the watch dog to function if that is what you will use to wake it up.

The internal modules are all driven by clocks scaled down from the CPU clock. If the clocks to any one module are turned off, then that module will stop functioning until the clock(s) turns back on. Theoretically, these modules will draw zero current when they are shut down, although there is always some level of leakage.

In addition to sleep modes, there are many steps you can take to ensure your circuit does not draw much power during operation, at least as far as the AVR is concerned. Here are a few ideas. All of these steps are outlined in the datasheet:

  1. Disable unused module clocks using the PRR register
  2. Shut off the analog comparator: ACSR |=_BV(ACD);
  3. Never leave floating pins - always use a pullup or pulldown resistor.
  4. Use a lower voltage power source (Vcc >= 2.7V for tinyx5, 1.8V for tinyx5V)
  5. Lower the CPU clock by changing the clock prescale values in CLKPR
  6. Disable the ADC when you are not using it: ADCSRA &= ~_BV(ADEN);
  7. Disable the digital input buffers you aren't using with DIDR0

As far as shutting down external peripherals, you could easily do that with a transistor as you have suggested. The I/O pins are static latches they retain their state when the AVR goes to sleep, so you could (in software) turn them off before you go to sleep and turn them on when you wake up. I would suggest you use a logic level N-channel MOSFET to connect/disconnect the devices from their ground supply (low-side switching), as long as the FET Gate threshold voltage is a bit lower than your AVR supply voltage so it fully turns ON from a high output. The MOSFET is not drawing any current through the gate when it is on (once the gate capacitor has been charged) unlike an NPN BJT which will continuously draw current while it is on. Either way, you should use an external pull down resistor (10k or so) to make sure the transistor stays off when it is supposed to be off. This will draw a bit of current, so a weak pull down is recommended (5V through 10k is only 0.5mA, 50uA through 100k).

You could also use this trick to turn off the external devices any other time you aren't using them; although they might need a bit of time to fully turn back on when you do need to use them or else they will give you strange results:

  1. Turn On Device
  2. Delay for a few milliseconds (whatever the recommended startup time is)
  3. Read sensor/ transmit data
  4. Delay for a few milliseconds
  5. Turn off device
  • \$\begingroup\$ Excellent answer there @Kurt. Very comprehensive and great that you shared the other possibilities of power reduction as well. As for the weak pull-down, I'm guessing that 100k would be better due to even lower current draw, right ? \$\endgroup\$ – bdutta74 Apr 22 '13 at 2:39
  • \$\begingroup\$ Another thing - given that the circuit needs to have a 5V rail anyhow, because the Ultra-sonic sensor, and also the ISM transmitter require it, does running CPU with a lower Vcc (say 2.7V) give me some power saving ? Wondering because, if I use a linear regulator to step-down 5V->2.7V, I'd be losing almost 50% energy there, so I'd have to go for a switching regulator, right (and still lose about 10-12%). \$\endgroup\$ – bdutta74 Apr 22 '13 at 2:42
  • 1
    \$\begingroup\$ Good point. If you need the 5V rail for the other sensors, then you might as well use that for the MCU. The savings in the MCU would probably be less than the waste from the regulator. As for the pull-down resistor, 100k should work since you are not switching very fast or very often (like in a PWM driver). \$\endgroup\$ – Kurt E. Clothier Apr 22 '13 at 3:07

Many microcontrollers retain their pin output state when they go into sleep mode. The ATtiny85 certainly does (as does every AVR I've ever heard of). Usually the data sheet will say in its description of the low power modes.

  • \$\begingroup\$ Thanks @vicatcu. While I had skimmed through the data-sheet, but didn't quite find (unless I didn't interpret the wording correctly), what happens to the GPIO pins in a power-down state. \$\endgroup\$ – bdutta74 Apr 22 '13 at 2:53

To switch something with a microcontroller such that it stays off when the microcontroller is off, one can use a "pull-down resistor", say 100 kOhms, on the MCU's output line. This line then drives the switching part, be it a BJT, MOSFET or something else.

If the microcontroller asserts a value on the output (GPIO) pin, that overcomes the ground-ward pull of the resistor, and the result is an on or off state as desired. If the microcontroller is powered off entirely or in some state where the output is "floating", the switch sees an input of low (0 volts) courtesy the pull-down, and remains off.

N.B. One can also use pull-up resistors instead, with some circuit and logic changes - my answer merely gives a simplified overview rather than a comprehensive list of possible approaches.

  • \$\begingroup\$ Thanks @Anindo, that's a pretty easy and I'd think, a guaranteed way to control the BJT. Like a dead-man's pedal ! It'd allow me to go down to the deepest sleep state, for maximum power saving. \$\endgroup\$ – bdutta74 Apr 22 '13 at 2:32

This is what I found from the Atmel ATtiny85-PU20 datasheetenter image description here

So this will not effect you I/O. It will only turn off the oscillator and PLL. BJT swich control is the best way for your battery operated system. Even you can cut the power to ultra sonic sensor and wireless transmitter when going in to sleep and only resume power to them on wakeup. This will increase your battery life.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.