Timer/Counter0 Output Compare Match A ISR is not getting executed

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Everyone,

                I have written a C code for toggling PB2 and OC0A for every 200 micro seconds. But the code didn't worked as expected.

I did appropriate registery setting. The didn't see any activity on OC0A and PB2. Please assist me.

 

 

#define F_CPU 8000000UL

#include <avr/io.h>

#include <avr/interrupt.h>

int main(void)

{

             DDRB |= (1<<DDRB3)|(1<<DDRB2); // set pin 3 as output

             OCR0A = 0x19; // count value for 200us

            TCCR0A |= (1<<WGM01)|(1<<COM0A0); //CTC mode,Toggle OC0A on Compare Match

            TCCR0B |= (1<CS00)|(1<CS01); //64 prescaler

            TIMSK0 |=(1<<OCIE0A); //Interrupt Enable for Timer/Counter0 Output Compare Match A

            sei();

           while(1)

          {}

}

ISR(TIMER0_COMPA_vect)

{

             PORTB ^= (1<<PORTB2); //Toggles PB2

}

This topic has a solution.
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The didn't see any activity on OC0A and PB2.

Just checking but what are you using to monitor the output signal? Even with /64 at 8MHz the signal will switch so fast it would be impossible to see with anything but a device such as scope or logic analyser. If it was an LED, for example, then if you slowly varied OCR0A in the while(1) loop you would see its brightness change.

 

Which model of AVR by the way?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

             I am using digital oscilloscope for monitoring  PB2 and OC0A.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The mistake is that you use < instead of << in the following line

TCCR0B |= (1<CS00)|(1<CS01); //64 prescaler

 

Also make sure that you set OC0A pin as output (I'm not sure which device you use)

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

Last Edited: Tue. Mar 10, 2015 - 09:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oops...  Thats the mistake.

I am Using ATmega 324P and i declared OC0A as output pin.

 

Thank You.