Hello,
I want to achieve that after every 11minutes the Attiny wakes up, puts LED on and then repeat the same procedure after 11minutes. I want to save power, turning off all the other appliences as it is running on CR2032. Processor clock is running on 1Mhz.
Is the code snippet working?
type or paste code here
/*
/* * Program ATTiny85 to blink LED connected to PB1 at 1s interval.
* Assumes ATTiny85 is running at 1MHz internal clock speed.
*/
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
bool timer1 = false, led = true;
// Interrupt service routine for timer1
ISR(TIMER1_COMPA_vect)
{
timer1 = true;
}
void setup() {
// Setup output pins
pinMode(1, OUTPUT);
digitalWrite(1, led);
set_sleep_mode(SLEEP_MODE_IDLE);
// Setup timer1 to interrupt every second
TCCR1 = 0; // Stop timer
TCNT1 = 0; // Zero timer
GTCCR = _BV(PSR1); // Reset prescaler
OCR1A = 660000000; // T = prescaler / 1MHz = 0.004096s; OCR1A = (1s/T) - 1 = 243 //1min @1Mhz
OCR1C = 660000000; // Set to same value to reset timer1 to 0 after a compare match
TIMSK = _BV(OCIE1A); // Interrupt on compare match with OCR1A
// Start timer in CTC mode; prescaler = 4096;
TCCR1 = _BV(CTC1) | _BV(CS13) | _BV(CS12) | _BV(CS10);
sei();
}
void loop() {
if (timer1) {
timer1 = false;
led = !led;
digitalWrite(1, led);
}
sleep_enable();
sleep_cpu(); // CPU goes to sleep here; will be woken up by timer1 interrupt
}
That won't work. OCR1A and OCR1C are 8bit registers, a value 660 Mio. won't fit into one byte.