How to set the timer1 to produce interrupt once every 200us?

I want the timer 1 to produce a interrupt on match, that too continuously every 200us. And I want a interrupt handler too. Can anyone explain what are register we need to set and in which order.(a avr-gcc code format will be very usefull). :)

Download TimerOne and look inside

a tick rate of 200uS will be very tight, the ISR routine and the context switch in and out of the interrupt will eat away at any background time to process the main loop.

This code is fairly generic to get a timer working , it depends on which Arduino as to which timer to use this is code for a Mega

/// macro to calculate count based on a frequency
#define CountValue(freq)  65536- ((16000000/256)/freq)
void RTCInit(int freq)  // frequency is rate so 50Hz ) 20mS
{
  set4Int(freq); // Tick Interrupt interrupt
}
void set4Int(int freq) //Interrupt  On Timer 3
{
  noInterrupts();	
  timer4_counter = CountValue(freq);	 //  set a variable with calculated value..
  // disable all interrupts
  TCCR4A = 0;
  TCCR4B = 0;
  // set up interrupt on overflow.. 
  TCNT4 = timer4_counter;   // preload timer
  TCCR4B |= (1 << CS12);    // 256 prescaler      
  TIMSK4 |= (1 << TOIE1);   // enable timer overflow interrupt
  interrupts();             // enable all interrupts
}
// interrupt service routine ISR for 20mS Timer on timer 4
//////////////////////////////////////////////////////////////
ISR(TIMER4_OVF_vect)        // interrupt service routine 
{    
  TCNT4 = timer4_counter;  // relaod the counter from a variable

}
// interrupt service routine ISR for 20mS Timer
//////////////////////////////////////////////////////////////

hope this helps and good luck at that speed.

Thanks for all of your replies :slight_smile:
I got what I wanted from this link : http://maxembedded.com/2011/06/28/avr-timers-timer1/