Why is my ATmega32 timer interrupt not executing?
hello I am beginning interfacing on the atmega32 and I am getting started with the peripherals and now I am stuck with the timers, this code isnt executing the interrupt code for some reason
#include<avr/io.h>
#include<util/delay.h>
#include<avr/interrupt.h>
int main(void){
SREG=1<<7;//enable the I-bit
DDRC=0x01;//output
PORTC=0x00;//initializing not depending on default values in the datasheet
TCCR0=0x05;//setting the value of the prescaler
TIMSK=0x03;//enabling the interrupt of overflow and compare
for(;;){
}
}
ISR(TIMER0_OVF_vect){
PORTC^=0x01;
}
33 Replies
help would be appreciated
on overflow ISR you have to set timer value, that to be overflowed next time
that is the only thing missing?
I think I did that but it didnt do nth w8 I will try
Yes, is the register settings are correct
in this you haven't set TCNT0 register
In which mode you want to use timer??
* Overflow ?
* Compare ? etc?
still doesnt work
I only added the TCNT0 initial value to zero
and it still doesnt work
I am trying the overflow mode rn
I set the internal clock to 1 MHz
and reduced the prescaler value
and it still doesnt work
check timer register settings, is the settings correct for overflow enable?
looks like you set settings for capture mode
TIMSK0 register setting
the 0th bit is 1
and the first bit too but I got to the point that I wanted to try to see what would happen if I enabled both bits
the 0th bit enables the overflow interrupt
yes
there's different ISR routine for compare match
#include<avr/io.h>
#include<util/delay.h>
#include<avr/interrupt.h>
#define F_CPU 1000000UL
int main(void){
SREG=1<<7;//enable the I-bit
DDRC=0x01;//output
PORTC=0x00;//initializing not depending on default values in the datasheet
TCCR0=0x01;
TIMSK=0x01;//enabling the interrupt of overflow and compare
TCNT0=0x00;
for(;;){
}
}
ISR(TIMER0_OVF_vect){
PORTC^=0x01;
}
this should work right? ðŸ˜
connect reset pin to high
nope.... nth
I even changed the initial value of the counter to FA
to get the overflow faster if it was a clock problem
anyways thank you for your time I will try to figure it out myself
try this :
also when you put code on discord please use this :
Use whats inside the parenthesis