Go Down

Topic: ATTiny85v and Sleep Functions (Read 5 times) previous topic - next topic

jrburke99

I will be programming an ATTiny85v using an Arduino as the programmer. My end project will be the ATTiny with 2xAA's (~3.2V), one analog temperature sensor, and one IR LED for output. The program will basically take 50 (or whatever) readings, throw out the lowest 10 and highest 10, then average the remaining readings to get a solid temperature reading. It will then blink the IR LED slowly for 2 seconds if the temperature is below a range, leave it off if within the acceptable range, and blink fast for 2 seconds if above that range. Then it will wait for 30 seconds and do it all again.

I have this running well on the Arduino itself, and will transfer it to the ATTiny85v.

But I need some help for figuring out how to maximize battery life. This will be a constant ON device (to monitor temperatures in babies' rooms and show me via the night vision cameras if it is too cold or hot). I found the code to use the power down sleep mode, and I found somebody who modified it to work on the ATTiny85, so I should be able to get that to work. I am wondering if I can use that to put it to sleep/wake up during the light blinking process. Basically, would there be any issues using the system_sleep() function in place of ALL delay() calls? The examples set the watchdog timer duration during the setup, so it would have to use the same sleep time each time it is called, but it would be nicer if a different time could be used (for example: half second in between LED blinks, and 8 seconds inside of a loop 5 times for a 30 second delay). Is that possible?

I was also wondering about any/all other tips for maximizing battery life. I see I can call power_adc_disable(), power_timer0_disable(), power_timer1_disable(), and power_usi_disable(). I can disable ADC during sleep and re-enable after. What about the timers and the USI? Can I disable the USI completely in the setup, or would that prevent me from flashing another program onto it??? I'm worried about that! And do I need timer0 and timer1? It is unclear to me exactly what those are needed for. If I disable them before a sleep call, would it turn off the watchdog timer and not wakeup?

So many questions, but I am learning quickly. Thank you all for your help!

fungus


Basically, would there be any issues using the system_sleep() function in place of ALL delay() calls?


No.


The examples set the watchdog timer duration during the setup, so it would have to use the same sleep time each time it is called, but it would be nicer if a different time could be used (for example: half second in between LED blinks, and 8 seconds inside of a loop 5 times for a 30 second delay). Is that possible?


The watchdog time can be changed as often as you like.


I was also wondering about any/all other tips for maximizing battery life. I see I can call power_adc_disable(), power_timer0_disable(), power_timer1_disable(), and power_usi_disable(). I can disable ADC during sleep and re-enable after. What about the timers and the USI? Can I disable the USI completely in the setup, or would that prevent me from flashing another program onto it??? I'm worried about that! And do I need timer0 and timer1? It is unclear to me exactly what those are needed for. If I disable them before a sleep call, would it turn off the watchdog timer and not wakeup?


Timer0 generates the interrupt which increments millis(), you might need that. Timer1 normally isn't needed (it's used for PWM generation if you do analogWrite()).

Disabling USI won't affect programming (the first thing a programmer does is RESET the chip).

The power consumption of all those modules is listed in the datasheet (in "Power Management" and "Typical Characteristics" sections). The worst offenders are Timer1 and the ADC.


So many questions, but I am learning quickly. Thank you all for your help!


This is quite advanced stuff... :)
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

dc42

I suggest you program the fuses to use the 128kHz internal oscillator instead of the 8MHz one, and program the clock prescaler register to run the processor at the lowest clock frequency that you can manage with. This way, you can get the current consumption of the chip down to a fraction of a millamp while it is awake.

If you do this, then I doubt that it's worth having the device sleep while blinking the IR LED, since the ATtiny current consumption will be tiny compared to the IR LED.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Erni

Quote

Timer0 generates the interrupt which increments millis(),


Are you sure ?

From the core_build_options.h

Quote

/*
 For various reasons, Timer 1 is a better choice for the millis timer on the
 '85 processor.
*/
#define TIMER_TO_USE_FOR_MILLIS                   1


fungus


Quote

Timer0 generates the interrupt which increments millis(),


Are you sure ?

From the core_build_options.h

Quote

/*
 For various reasons, Timer 1 is a better choice for the millis timer on the
 '85 processor.
*/
#define TIMER_TO_USE_FOR_MILLIS                   1




You must have a different core than me. Mine uses timer0.

If you're worried about power, Timer1 uses 10 times as much power as Timer0. :)

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Go Up