Digistump Forums
The Digispark => Digispark (Original) Support => Topic started by: r4z0r7o3 on March 19, 2013, 07:23:25 am
-
I've got an existing project with a button on pin 3 utilizing the internal pull-up (i.e. pressing button, grounds pin 3). I'm researching the possibility of adding a low-power sleep-mode to my project. In order to wake up, I would need to attach a pin-change interrupt to pin 3 before going to sleep.
I read in the attiny 85 datasheet, (section 9.3.4) that bit 3 of PCMSK selects this pin for the pin-change interrupt. I looked through arduino-1.0.3/hardware/tiny-digispark/cores/tiny/* but couldn't figure out if/how it was supported in the arduino/tiny arduino core.
Does anyone know if it's feasible to setup a pin change ISR on pin 3 (with internal pull-up enabled) and use it to wake up from sleep mode?
Also, since timing isn't critical in my sleep mode, I was wondering if I could scale the MCU's frequency down on sleep, then back to 16mhz when waking up, anyone tried this?
-
You can connect an interrupt handler to any pin via Pin Change Interrupt 0, using the TinyPinChange library. Currently this library doesn't work if you are also using any of the USB libraries in your sketch, but I guess you aren't since you're using pin 3 for general IO.
You don't need to turn the frequency down - when the chip is asleep the frequency is 0Hz. But aside from sleeping if you do want to adjust the CPU speed on the fly, you can use this function: http://digistump.com/wiki/digispark/tricks#underclock_the_cpu_to_save_power note it does not fix delay, delayMicroseconds, millis, or micros, so all of these will be wrong as well as any timing sensitive libraries you have used. The next version of the Digispark Arduino app includes options for 16.5MHz, 16.0MHz, 8MHz, and 1MHz as clock speeds in the Boards menu. These speeds can save a bit of power, make your sketch more compatible with libraries which haven't yet been optimised for the Digispark, and these board settings do support delay, delayMicroseconds, millis, micros, and all the other stuff correctly.
-
You can connect an interrupt handler to any pin via Pin Change Interrupt 0, using the TinyPinChange library. Currently this library doesn't work if you are also using any of the USB libraries in your sketch, but I guess you aren't since you're using pin 3 for general IO.
Nope, don't care about USB. Cool! I'll check out the library.
You don't need to turn the frequency down - when the chip is asleep the frequency is 0Hz.
Ahh, right, okay then, perfect!
But aside from sleeping if you do want to adjust the CPU speed on the fly, you can use this function: http://digistump.com/wiki/digispark/tricks#underclock_the_cpu_to_save_power (http://digistump.com/wiki/digispark/tricks#underclock_the_cpu_to_save_power) note it does not fix delay, delayMicroseconds, millis, or micros, so all of these will be wrong as well as any timing
Yeah, unf. I've got a very timing-sensitive ISR running off of timer0, so can't switch CPU speed while awake.
sensitive libraries you have used. The next version of the Digispark Arduino app includes options for 16.5MHz, 16.0MHz, 8MHz, and 1MHz as clock speeds in the Boards menu. These speeds can save a bit of power, make your sketch more compatible with libraries which haven't yet been optimised for the Digispark, and these board settings do support delay, delayMicroseconds, millis, micros, and all the other stuff correctly.
Cool! Yeah I read that it was "coming soon". I'll keep that in mind for my next project!
Thanks a ton for your help and all your work with Tiny & Digispark :)