[SOLVED] precisely all 20 ms an interrupt - is this possible?


in thread http://arduino.cc/forum/index.php/topic,97610.msg732311.html generel solution getting timer based interrupt given:

code: [select]

volatile boolean fired = false;

void setup()
{
 // ctc mode clk/8 prescaler
 tccr1a = 0;
 tccr1b = 1<<wgm12 | 1<<cs11;
 
 tcnt1 = 0;         // reset counter
 ocr1a =  39999;       // compare register value
 tifr1 |= _bv (ocf1a);    // clear interrupt flag
 timsk1 = _bv (ocie1a);   // interrupt on compare match  
}

isr (timer1_compa_vect)
{
   fired = true;
   tifr1 = 1<<ocf1a;     // clear output compare match flag
}

void loop()
{
       while (! fired) { }  // waits next timer interrupt
       fired=false;         // clears timer interrupt marker
       // ... stuff here
}


this code indeed gives precisely 20000 * 16 ticks goo. ticks not 1/16 us, mentioned @ other occassions already. stated, millis() call has code compensate that.

so question is, how 1 can achieve real 20 ms goo. if lucky, have change 39999 "something", maybe solution set 43123 in general, each seventh time 43128, give example.

so if 1 has figured out thing already, please let me know!

the timer driven system clock in cases accurate. people mean code micros() have take account clock cycles needed add 2 (long) integers. code approximatively exact clock source is.


Arduino Forum > Using Arduino > Programming Questions > [SOLVED] precisely all 20 ms an interrupt - is this possible?


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial