Hello All,
Just started with AVR microcontrollers a week of two ago and did some study of the datasheet , examples , reading books, tutorials etc.
The best way of learning it is playing with it.
However the first attempt to get timer 0 working in CTC mode with interrupts (no toggling mode )gives me already a lot of problems which I will hope that the more experienced people on this forum can help me out.
I'm using the STK600 development board for my experiments.
The ATTINY 85 is used in his default clock mode meaning 1 Mhz/ 1us clock rate
What I want to achieve is generation of an interrupt every 100 us.
I wrote a test program where I just toggled a port pin in the IRQ. But it seems that the IRQ is never invoked. It must be something simple for sure but can't find it. I searched on it for a day of two now
I measure the port pins with a scana plus . This is an USB logic analyzer. Which I believe is capable to measure the output of the toggled pin.
The clock of the device is measured on an external pin and looks OK.This is done by setting the CKOUT fuse.
Any help , feedback is welcome here
Regards,
#include <avr/io.h> #include <avr/interrupt.h> // initialize timer, interrupt and variable void timer0_init() { // set up timer with prescaler = 1 and CTC mode TCCR0A |= (1<<WGM01); TCCR0B |= (0<<CS02)|(0<<CS01)|(1<<CS00); // initialize counter TCNT0 = 0; // initialize compare value OCR0A = 99; //100us // clear interrupt flag as a precaution TIFR |= 0x01; // enable compare interrupt TIMSK |= (1 << OCIE0A); // enable global interrupts sei(); } int main(void) { DDRB = 0xFF; //all pins output PORTB &=~(1<<PB0); // PBO low timer0_init(); sei(); // enable global interrupts while(1) //loop forever return 0; } //TIMER 0 COMPARE match ISR (TIMER0_COMPA_vect) { PORTB |=(1<<PB0); PORTB &=~(1<<PB0); }