TOV2 interrupt not firing in debug mode.

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


I think that this should be toggling PORTB's first pin, however when I debug it the event is never fired.  It seems that the program hangs at sei().   If I manually set TOV2 in TIFR2 then the event fires and the breakpoint set in ISR is reached.

 

#include <avr/io.h>
#include <avr/interrupt.h>

int main(void) {
    DDRD = 0b00000001;
    cli();

    TCCR2A |= (1 << CS20);
    TIMSK2 |= (1 << TOIE2);

    sei();
    while (1) {
    }
}

 

The I/O window had the correct bit set.

 

I thought that it might be that the while loop was getting optimised away by the compiler so I tried adding a write to the PORTB register so that it was doing something important

 

while (1) {
    PORTD++;
}

That seems to be preventing the while loop from vanishing but the interrupt at TOV2 still isn't firing.

This topic has a solution.
Last Edited: Tue. Dec 28, 2021 - 01:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It always helps if you tell which processor you are using.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

 By register addresses, it corresponds to ATmega328.
 

Try this:
   TCCR2B = (1 << CS20);
 

 

Edit: remove TCCR2A line, it will activate PWM.

Last Edited: Tue. Dec 28, 2021 - 06:19 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's it.  A b***dy typo.  Grrr.

 

Thanks.

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

js wrote:

It always helps if you tell which processor you are using.

 

Yes, I keep forgetting that I'm not in a cosy .NET/JavaScript world now.