Reputation: 21
I have used a full working day with ATTINY85 datasheet, google and different forums but the sleep stuff makes only partial sense to me.
Project goal: I am building a disco ball speed controller to power and pwm-control the tiny dc motor in cheap chinese battery operated disco ball rotator.
Hardware: cheap powerbank (5V usb port output) -> the common ATTINY85 digispark clone board from ebay -> pwm with n-FET -> motor. One button to switch speeds settings.
After boot I run settings loop that listens for a key press (actually quik flick of power switch in the final form) and changes between few preconfigured pwm settings. When ~2min has elapsed since last key press, the setting in use is saved to EEPROM for next boot. This all is working.
After updating EEPROM I'd like to minimize the power consumption because disco must never stop. From reading all kinds of tutorials and the datasheet it seems that only SLEEP_MODE_IDLE is possible when pwm is used.
I want to zombify the board as far as I can just keeping the pwm as it is set. No need to wake up ever.
What other stuff actually can be turned off and howto do it correctly? Tips and recommendations?
This is my feeble attempt so far. it somewhat works, the debugging led I set stays on at pwm=30 (in main loop it pulses) but the system wakes up on button press (goes to main loop – led starts pulsing) so I suspect there is more to do.
void timeout() { // this happens when settings loop has run long enough and its time for eternal sleep
analogWrite(PINLED, 30); //debug
countsmall = 0; //DEBUG, in case we wake up be ready for main loop
countbig = 0; //DEBUG, in case we wake up be ready for main loop
// save the setting
EEPROM.update(0, savedlevel);
// conserve power -- go zombie state for eternity
noInterrupts();
ACSR |= _BV(ACD); //disable the analog comparator?
ADCSRA &= ~_BV(ADEN); //disable ADC?
mcucr1 = MCUCR | _BV(BODS) | _BV(BODSE); //turn off the brown-out detector?
mcucr2 = mcucr1 & ~_BV(BODSE);
MCUCR = mcucr1;
MCUCR = mcucr2;
set_sleep_mode(SLEEP_MODE_IDLE);
//sleep_enable(); //redudant
sleep_bod_disable();
sleep_mode();
}
The whole program: http://uvkk.kirah.fi/jotainmuutarandomia/randomfiles/liskodiskoboltsi.cpp
Addition 1 11.2.2019:
Current situation, power on led removed, the debug led turned off while sleeping (2ms flash once a second when looping), nothing but power connected to the board, measured from ground lead:
1 MHz: 13,8 ma looping, 12,9 ma idling
8 MHz: 19,0 ma looping, 15,1 ma idling
16,5 MHz: 24,7 ma looping, 17,9 ma idling
I think this makes it run at 500kHz:
1MHz setup but clock_prescale_set(clock_div_32);
in the setup(). At least one second flashes are now 2 second long and current draw looping is 13,2 ma and idling 12,6 ma.
But these are too high numbers... Wtf am I doing wrong here? Can the onboard regulator bleed current away although I feed the 5V pin directly?
Upvotes: 0
Views: 2077
Reputation: 1393
You are correct that Idle mode is as deep sleep as you can go for and still have the timer running.
At 1Mhz at 5V, you would expect this chip to use about 1mA in active mode...
At Idle you would expect that to drop to about 0.2mA....
My guess is that the vast, vast majority of the power draw you are seeing is due to the LED.
If you need to have some visual feedback and still want to be low power, consider maybe periodically flashing the LED rather than having it always on. A 10ms flash once per second could be visible and use 1/100th the power.
Once you do then then you can start doing marginal power savings like turning off peripherals, blocking the Arduino ISRs form running to get the ATINY power user closer to the 0.2mA down from the full active 1mA.
If you have disabled the LED and are still seeing high current draw, then my guess here is that your dev board has a linear regulator on it which basically burns power. The ATTINY85 can directly accept up to 5.5V power, so as long as your input voltage is less than this you would be able to completely remove the regulator and then get your power usage down to the expected values.
Looking at the schematic for you board, I think you can provide power though pin 3 (VIN
) of JP2 and skip the regulator. Have you tried that?
Upvotes: 0