Power management

Hello all,
I am creating a battery powered autonomous robot that is going to run for a very brief period of time and then be inactive for 12 hours before repeating its main function. I have the bulk of the code written and programmed onto my baby-0 328p. Since I am in the phase of dialing in motor position movement I have it looping on a simple “delay_ms(10000);”. I realize when I want to eventually connect the battery and put the robot in the field, I want to use some sort of sleep function to conserve as much battery life as possible.

This is my issue. I have glanced through the ATMEL website and tried to make sense of the pdf. Documents they have on sleep functions, but as this is my first programming/robotic project ever I find it confusing. I am using AVR Studio and utilizing the polou avr library. Does anyone have some code examples or able to help me understand what is required to accomplish this?

Any and all help is appreciated,
-Tyler

Is there a way to set the board to sleep for 12 hrs before repeating the main loop?

The lack of help is discouraging

The Baby Orangutan uses the same processor as modern Arduino boards, so if you search the web for things like “Arduino sleep” there is a good chance you will find someone’s complete code for putting the Atmega328p to sleep for extended periods of time. Here is a page I found:

arduino.cc/playground/Learni … oSleepCode

I think your basic strategy should be to put the AVR to sleep and have a timer interrupt set to wake it up periodically. Whenever it wakes up, it should just run a very quick check to see whether it is time to do the desired action, and if it is not time yet then go back to sleep. Here is pseudo code:

void sleep_12_hours()
{
    unsigned long count;
    enable_timer_interrupt_that_wakes_mcu();
    for (count = 0; count < MAX_COUNT; count++)
    {
        put_avr_to_sleep();
    }
}

Here is what you need to figure out:

  • What timer will you use to wake the AVR? The AVR has three timers: 0, 1, and 2. You should read about them in the datasheet, and pick a timer that is not being used by any of the other libraries your application is using. What libraries are you using? If you want to use a timer that one of those libraries is using, just be sure to restore it to its original state after you are done sleeping.
  • How will you configure the timer and enable its interrupt? Read the datasheet for the timer module.
  • How often will the timer wake up the AVR? You want it to be infrequent to save power.[/li]
  • How many times will the timer wake up the AVR in 12 hours?
  • What sleep mode of the AVR do you want to use? You need to choose a sleep mode that allows a timer interrupt to wake up the AVR while minimizing current draw. See chapter 9 of the data sheet.
  • Learn about the TB6612FNG’s STBY pin (which is connected to PC6) and make sure it is in the right state to save power while the AVR sleeps.

(You can save power by running at a lower speed, but that will make a lot of our libraries run slowly, and it could ruin the AVR if you do it wrong.)

-David