I want to build small RF remote that works off 3V coin cell. ATTiny84 seems like a good candidate. To save battery power, IC will be sleeping, only being awakened by external interrupt (button). Problem is I want to use several buttons. From pinout it looks like ATTiny84 has at least 10 usable hardware interrupts (wow that a lot more than ATMega328p) if I'm reading it correctly. Would I be able to wake chip if by several buttons that attached to those pins? Also how do you debounce those buttons, since millis is not working in ISR function?
bratan:
I want to build small RF remote that works off 3V coin cell. ATTiny84 seems like a good candidate. To save battery power, IC will be sleeping, only being awakened by external interrupt (button). Problem is I want to use several buttons. From pinout it looks like ATTiny84 has at least 10 usable hardware interrupts (wow that a lot more than ATMega328p) if I'm reading it correctly. Would I be able to wake chip if by several buttons that attached to those pins? Also how do you debounce those buttons, since millis is not working in ISR function?
ATMega328 can interrupt on any pin but 2 pins are special because they have their onw interrupt vector.
The Tiny84 is similar, it can interrupt on any pin but pin 5 (PB2) is special, it has its own interrupt vector (INT0). Unfortunately, this is the only pin that can wake up the chip when it's sleeping.
millis() should work in an interrupt (it just reads the value) but if millis isn't working for some reason then you need another time source for debounce. Use whatever is available...
Can you use double pole/double terminal switch so one terminal goes to the hardware interrupt pin and the other to the normal pin for button reading.
You might also be able to use single terminal switches connected to both the button pin and the hardware interrupt pin via diodes to stop volts going back to other switches.
Riva:
You might also be able to use single terminal switches connected to both the button pin and the hardware interrupt pin via diodes to stop volts going back to other switches.
Yep, diodes should work ... connect every switch to its input pin then connect each pin to the wake up pin via a diode (one per pin).
fungus:
The Tiny84 is similar, it can interrupt on any pin but pin 5 (PB2) is special, it has its own interrupt vector (INT0). Unfortunately, this is the only pin that can wake up the chip when it's sleeping.
Are you sure about this? From the datasheet.
Pin change interrupts on PCINT11..0 are detected asynchronously.
This implies that these interrupts can be used for waking the part also from sleep
modes other than Idle mode.
Pin change interrupts do wake a sleeping AVR processor. Even a t84.
I have code for an Attiny85 waking from a pin change interrupt:
// ATtiny85 sleep mode, wake on pin change interrupt demo
// Author: Nick Gammon
// Date: 12 October 2013
// ATMEL ATTINY 25/45/85 / ARDUINO
//
// +-\/-+
// Ain0 (D 5) PB5 1| |8 Vcc
// Ain3 (D 3) PB3 2| |7 PB2 (D 2) Ain1
// Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1
// GND 4| |5 PB0 (D 0) pwm0
// +----+
#include <avr/sleep.h> // Sleep Modes
#include <avr/power.h> // Power management
const byte LED = 3; // pin 2
const byte SWITCH = 4; // pin 3 / PCINT4
ISR (PCINT0_vect)
{
// do something interesting here
}
void setup ()
{
pinMode (LED, OUTPUT);
pinMode (SWITCH, INPUT);
digitalWrite (SWITCH, HIGH); // internal pull-up
// pin change interrupt (example for D4)
PCMSK |= bit (PCINT4); // want pin D4 / pin 3
GIFR |= bit (PCIF); // clear any outstanding interrupts
GIMSK |= bit (PCIE); // enable pin change interrupts
} // end of setup
void loop ()
{
digitalWrite (LED, HIGH);
delay (500);
digitalWrite (LED, LOW);
delay (500);
goToSleep ();
} // end of loop
void goToSleep ()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
ADCSRA = 0; // turn off ADC
power_all_disable (); // power off ADC, Timer 0 and 1, serial interface
sleep_enable();
sleep_cpu();
sleep_disable();
power_all_enable(); // power everything back on
} // end of goToSleep
The Attiny84 can't be that much different.
Thanks guys! Didn't realize there were replies, something strange going on with notifications on this forum
That's good idea about using all buttons to trigger INT pin (if indeed there's only one that can wake chip up).
Most PCB tact switches have extra pin on each side so i can wire it accordingly without diode...
Nick, I used that code actually with ATtiny85, just on INT1. But how can I use both interrupts? Is it possible? There's only one ISR function...
I just realized that connecting all buttons to same INT pin will tie them together and there's absolute no way to tell which button was actually pressed
bratan:
I just realized that connecting all buttons to same INT pin will tie them together and there's absolute no way to tell which button was actually pressed
That's why you need the diodes.
Riva:
That's why you need the diodes.
Ah, I haven't thought of that!
I actually found that PinChangeInt library works great for my purpose!