Wouter, I assume Timer1 causes an Interrupt when it rolls over from 0xFFFF to 0x0000. Why don't you use the timer, lets say you want to count 0x02FF cycles. Deduct that from 0xFFFF to get 0xFD00. Write that to Timer1, and wait for the interrupt to occur 0x02FF counts later? I have read the PIC16F62x's datasheet on Timer1, and even though you might be using a different chip, the operation should still be the same. So my first bet is to preset the TMR1H and TMR1L values and wait for the overflow Interrupt. An alternative, which I doubt will be suitable for your application, is to have a slower external clock pulsing Timer1. Run Timer1 in counter mode, and use a clock source of at least CPU-Freq / 20, then a looped test algorythm might work. Hope this helps somewhat. Cheers Werner ----- Original Message ----- From: "Wouter van Ooijen" To: Sent: Thursday, February 27, 2003 9:32 AM Subject: [PIC]: coding challenge: await > coding challenge: > > - 14-bit core PIC > - forget about paging and banking issues > - smallest possible code > - assembler > > TMR1 is a free-running 16-bit timer that can be read as two file > registers TMR1H and TMR1L. Note that there is no buffering in the > reading, so for 00FF you might read FF as low byte and then 01 as high > byte (just after the rollover). > > I have two file register bytes tH and tL that represent a TMR1 value > that lies in the future. I want to wait until this 'moment' has arrived > (or passed). Note that due to the above reading problem, the possibility > of interrupts and one more issue (think for yourself) it is no use to > loop and wait for a 'perfect match'. Looking for (tH,tL) >= > (TMR1H,TMR1L) won't do either, because the tH,tL 'moment' might be > beyond a roll-over from FFFF to 0000. > > Note that there are actually two challenges: first find a suitable > algorithm, then encode it in assembler. > > The application of such code is to create a timing loop with zero > cumulative error. > > Wouter van Ooijen > > -- ------------------------------------------- > Van Ooijen Technische Informatica: www.voti.nl > consultancy, development, PICmicro products > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics