auto reload of timer1 in Mega16

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

Is there an auto-reload command for timer 1 in interrupt mode? here is my timer function:

void timer_init()

   {
   
           TIMSK |= (1 << OCIE1A); //enable channel 1A interrupt
            sei(); //enable global interrupts
            TCCR1B |= (1 << CS10) | ( 1 << CS11); //start timer at Fcpu/64
            TCCR1B |= (1 << WGM12);//set up for CTC mode
             OCR1A = 65000; //Value that the micro will compare with current count
   
   }
ISR(TIMER1_COMPA_vect)

   { 
      
      // would like to autoreload OCR1A with 65000 here
   }

Any help appreciated.

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

OCR1A defines the TOP value in that mode. You don't need to reload as the register doesn't change. The hardware will automagically restart counting at zero when it has counted up to the point where it compares as equal to OCR1A.

If you contemplate changing the TOP value, then by all means enable the interrupt so you can modify OCR1A. Oh, and call sei() after all initializations are complete. Preferably in main().

"It's easier to ask forgiveness than it is to get permission" - Admiral "Amazing" Grace Hopper.