I want to wake up my AtTiny45, but it looks like it needs a few nudges sometimes.

I have a pull down button connected to INT0. I made sure INT0 wakes up when the button is pressed, and as soon as the deed is done, a bedTime() saves power by stopping timers etc.

(Program updated to include more information)

const byte
  mcucr     = (1<<SE)     | (1<<BODS)   | (1<<BODSE),
  prr       = (1<<PRTIM0) | (1<<PRTIM1);
void setup(){
  GIMSK |= (1<<INT0); //Wake up with the INT0 (When Rising)
  MCUCR |=  (1<< SM1)  | (1<<ISC01) | (1<<ISC00); //Sleep Mode
  OCR0A  = 255;
  TCCR0A = (1<< WGM00) | (1<< WGM01); //Fast PWM
  TCCR0B = (1<< WGM02) | (1<<  CS01); //8 Prescaler
  TIMSK  = (1<<OCIE0A); //Interrupt
  OCR1C  = 255; //PWM, no prescaler
  TCCR1  = (1<< COM1A1)| (1<< CTC1) | (1<< PWM1A) | (1<<  CS10);
ISR(INT0_vect){        MCUCR &= ~mcucr;PRR &= ~prr;OCR1A=255;}
void bedTime(){        MCUCR |=  mcucr;PRR |=  prr;}
ISR(TIMER0_COMPA_vect){OCR1A = (OCR1A - 1) * (OCR1A > 4);}
void loop(){          if(!OCR1A){bedTime();}}

This wakes the program only 3/4 of the time, and I tried to find the reason why but I'm hitting a twig.

How can I ensure INT0 sparks an interrupt from sleep every time?

  • sleepTime doesn't seem to be declared anywhere. – Nick Gammon Oct 19 '20 at 9:40
  • How do you know it doesn't wake up? From you code, you can't even tell that the MCU has woken up, as it will go back to sleep immediately. – Gerben Oct 19 '20 at 14:35
  • 1
    All I was saying is that your snippet of code is incomplete, in that it doesn't compile, clearly, so debugging something that doesn't compile is fairly hard. Amend the code so it compiles. Maybe you have a debounce issue. If I try to compile your code I get the error "'sleepTime' was not declared in this scope". – Nick Gammon Oct 20 '20 at 5:08
  • 1
    What we want is a Minimal, Reproducible Example. In other words, code that demonstrates the issue, in a minimal way. – Nick Gammon Oct 20 '20 at 5:09
  • 2
    Note that this program never sleeps. – Edgar Bonet Oct 20 '20 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.