I found out that the analog comparator interrupt doesn't work in deep sleep mode and it has to be in Idle mode. The current is about 7 mA so I'm trying to figure out how to reduce it. I'm only using buttons/switches and LEDs. This is my test program to better explain what I'm doing:
//interrupt test program for Attiny84A (LEDs turn on in response to interrupts)
//Yellow LED for button interrupt is on PB2
//Green LED for PB0 switch interrupt is on PA0
//Red LED for PB1 switch interrupt is on PA3
//Little Red LED for analog comparator interrupt is on PA5
//Pushbutton is on PB2 (using external INT0 interrupt)
//switch pins go to PB0 and PB1
#include <Interrupt.h>
#include <TinyWireM.h>
#include <Adafruit_MCP4725.h>
#include <avr/sleep.h>
Adafruit_MCP4725 dac;
int ledyellow = 8;
int ledgreen = 0;
int ledred = 3;
int ledredlittle = 5;
int button = 7;
int switch1 = 10;
int switch2 = 9;
int dac_in = 2;
int analog_in = 1;
//for setting register bits with AVR code
//cbi and sbi are standard (AVR) methods for setting, or clearing, bits in PORT (and other) variables.
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
volatile bool buttonpress, switchpress1,switchpress2,switchpress3, switch1_on, switch2_on, analogcomp;
void setup(void)
{
cli(); //disable global interrupts
dac.begin(0x62); //set DAC address
//set LEDs as outputs
pinMode(ledyellow, OUTPUT);
pinMode(ledgreen, OUTPUT);
pinMode(ledred, OUTPUT);
pinMode(ledredlittle, OUTPUT);
//set button and switches as inputs with pull-up resistors on
pinMode(button,INPUT_PULLUP);
pinMode(switch1,INPUT_PULLUP);
pinMode(switch2,INPUT_PULLUP);
//set analog comparator pins as inputs
pinMode(dac_in,INPUT);
pinMode(analog_in,INPUT);
//enable pin change interrupt 1 (for PCINT[11:8])
sbi(GIMSK,PCIE1);
sbi(PCMSK1,PCINT8); //enable PCINT8 pin change interrupt (for SP3T switch)
sbi(PCMSK1,PCINT9); //enable PCINT9 pin change interrupt (for SP3T switch)
//enable pin change interrupt 0 (for PCINT[7:0])
sbi(GIMSK,PCIE0);
sbi(PCMSK0,PCINT7); //enable PCINT7 pin change interrupt (for button)
//temporarily disable analog comparator interrupt (before configuring)
cbi(ACSR,ACIE);
//set comparator interrupt on rising output edge
sbi(ACSR,ACIS1);
sbi(ACSR,ACIS0);
//enable analog comparator interrupt
sbi(ACSR,ACIE);
dac.setVoltage(2048, false); //initialize DAC output to half VCC
sei(); //enable global interrupts
}
void loop(void)
{
if (analogcomp)
{
digitalWrite(ledyellow, HIGH);
digitalWrite(ledgreen, HIGH);
digitalWrite(ledred, HIGH);
delay(500);
digitalWrite(ledyellow, LOW);
digitalWrite(ledgreen, LOW);
digitalWrite(ledred, LOW);
analogcomp = false;
sleep_function(); //go to sleep
}
else if (buttonpress)
{
digitalWrite(ledyellow, HIGH);
delay(500);
digitalWrite(ledyellow, LOW);
buttonpress = false;
sleep_function(); //go to sleep
}
else if(switchpress1)
{
digitalWrite(ledgreen, HIGH);
delay(500);
digitalWrite(ledgreen, LOW);
switchpress1 = false;
sleep_function(); //go to sleep
}
else if (switchpress2)
{
digitalWrite(ledred, HIGH);
delay(500);
digitalWrite(ledred, LOW);
switchpress2 = false;
sleep_function(); //go to sleep
}
else if (switchpress3)
{
digitalWrite(ledredlittle, HIGH);
delay(500);
digitalWrite(ledredlittle, LOW);
switchpress3 = false;
sleep_function(); //go to sleep
}
}
//analog comparator interrupt
ISR(ANA_COMP_vect)
{
analogcomp= true;
}
//for switches
ISR(PCINT1_vect)
{
//read switch values
switch1_on = digitalRead(switch1);
switch2_on = digitalRead(switch2);
if (switch1_on == 0) //switch 1 is on
{
switchpress1 = true;
}
else if (switch2_on == 0) //switch 2 is on
{
switchpress2 = true;
}
else //neither switch is on
{
switchpress3 = true;
}
}
//for button
ISR(PCINT0_vect)
{
buttonpress = true;
}
void sleep_function(void)
{
cbi(ADCSRA,ADEN); //disable ADC
set_sleep_mode(SLEEP_MODE_IDLE); //sleep mode idle
sleep_mode(); //implement sleep
//PROGRAM STARTS HERE AFTER WAKING FROM SLEEP
sbi(ADCSRA,ADEN); //enable ADC
}