Hello I have started programming a 20 MHz 16f877 chip (using Hi-Tech C). I wish to have an interrupt formed every 1ms. So I have Timer 1 generating an interrupt. However the by preloading the timer I can get an interrupt happening every 985s, if I the loading value. The next step I get is a period of 1037us. Surely I should be able to get closer to 1ms than this? Initially I tried using a sample routine that came with the complier, and while this worked, I was not entirely happy with it so I have built my own. But I can't get accuracy high enough, at the moment I am still 2% out? The following is my interrupt routine. if(TMR1IF){ Count++; Scratch = TMR1H; // Getting timer1 value. Scratch<<=8; // Shifting to most sig half. Scratch = TMR1L + Scratch; Scratch = Scratch + (-2587); // Adding timer 1 to the scratch // pad and then adding the preload value. // Vary this number to change interrupt length Scratch2 = Scratch; // Take a copy, one copy will be // used to generate the new TMR1L and the other TMR1H. TMR1H = Scratch>>8; Scratch2<<8; TMR1L = Scratch2>>8; // Cleared top 8 bits and added // the remainder in the TMR1L TMR1IF = 0; // clear flag and start again } and the settings I have used. TRISB = 0; /* all bits output */ PORTB = 0; // to start with anyway T1CKPS1 = 0; // T1CKPS0 = 0; // prescale by 1 TMR1CS = 0; // use internal clk T1OSCEN = 0; // Need C0 & C1 for other stuff PEIE = 1; // enable peripheral interrupts TMR1IE = 1; // interrupt on overflow TMR1IF = 0; // clear flag to start with TMR1ON = 1; // Start timer GIE = 1; // away we go Any suggestions on where I might be able to improve the code to get a 1ms interrupt happening that I can rely on? I am relatively new to C and brand new to PICs so all comments are apprieciated. Thanks Bryce. Bryce Reeve Electronics Designer DEC International 558 Te Rapa Rd PO Box 20055 Hamilton New Zealand Phone +64 7 849 8755 Fax +64 7 849 0164 -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu