Polling an external interrupt does it affect the timer0

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

I want to implement the behaviour of the Input Capture Unit by implementing it by software using the Timer0 in normal mode , and timer1 to generate a PWM , and using an External interrupt 0 for example , the question is if i polled the external interrupt and waiting its flag to be set to does it affect the timer0 "TCNT0" from counting up??? or the timer will work even if the CPU of the AVR is polled to the ext. interrupt flag???
and there is something else what will happen if there is an interrupt occured from timer0 while the cpu of avr is freezed"polling"??

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

Polling the external interrupt flag in your main code will not affect the counter of timer0.  The prescaler of timer0 counts up one with each system clock pulse.  If the prescaler is set to 1, then the timer0 counter increments with every system clock.  If the prescaler is set to 64, then the prescaler increments with each system count up until 64.  Then the prescaler goes to 0 and the timer0 count increments by 1. The highest timer0 count is 255.  At count 255 and the prescaler at its max count, then the timer0 goes to 0, the prescaler goes to 0, and the timer0 overflow flag is set.

 

Polling the external interrupt flag is rarely done.  Usually an interrupt happens when an external source changes the voltage level on the external interrupt pin.  This interrupt can be programmed for either a rising edge, a falling edge, or a low level held for several several system clock cycles.  The external interrupt has a higher priority than the other interrupts, if they happen at the same time.

 

If the main code is "frozen" in a polling loop, then a timer0 interrupt will jump to the interrupt code.  It will run this code until it gets a RETI (return from interrupt) instruction.   Then it goes back to its previous place in the polling loop.