Generating single timer interrupt

this is a one shot 20ms pulse example

code is for MEGA

void setup() {
DDRB |= _BV(PB5); //set digital pin11 to output
PORTB |= _BV(PB5); //set it high
TCCR1A=0;
TCCR1B= _BV(CS11)|_BV(CS10);  //use clock div 64 to get 4us per count
OCR1A=TCNT1+5000; //5000*4=20ms
TIMSK1 |= _BV(OCIE1A); //enable interrupt
}

void loop() {
}

ISR(TIMER1_COMPA_vect){
PORTB &= ~_BV(PB5); //set pin low
TIMSK1 &= ~_BV(OCIE1A);   //disable interrupt
}

this is the pulse, generated asyncrhronously (you can do other things in loop)

If I use 4998, I get a 20.0005ms pulse. I think that is as accurate as you can get.