problem with Timer 2 Output compare match interrupt

Hi,

Iam using TIMER2_COMPA_vect Interrupt in my arduino program.

Iam counting the number of pulses in INT0 pin using INT0 interrupt . Whenever count reaches a particular value, it resets the value and turn a boolean true.

In my loop program iam checking this boolean variable and want to produce pulses(4 or more) of some fixed pulse width. Iam calling the following function if the boolean variable is true.

void pulseGenerator()
{
  cli();
  TCNT2 = 0;
  TCCR2B |= 0x82;
  TIMSK2 |= (1 << 1);
  sei();
}

Iam also wrote the ISR for output compare match interrupt as follows.

ISR(TIMER2_COMPA_vect)
{
  
   if(checkAverage_ > average_)
   {
     TCCR0B = 0x80;
     checkAverage_ = 1;
   }
   else
   {
     checkAverage_++;
     digitalWrite(pwmPin, HIGH);
   }
}

But my problem is whenever i enable the output compare match interrupt the whole system hangs. If i disable the interrupt it will work fine. Only Output Compare match interrupt A is causing hanging problem while all other interrupts are working fine.

Can any one help me on this.

Regards,
Jerry

Hi,

I think the ISR clashing with the ISR defined in Tone library. I can see the statement

C:…Local\Temp\build7583537968361064640.tmp\Tone.cpp.o

while compiling. I assume that Tone library is using Timer2 and that’s why its hanging…
While iam compiling its linking with the Tone library but anyway iam not using it. How can i exclude this library from linking?
Or Is there any way to override the ISR with my custom ISR?

Jerry

Can any one help me on this.

Perhaps the fine folks at http://snippets-r-us.com could help you with your snippets.

You are configuring timer0 not timer2!