Richard R. Pope wrote 2014-07-21 06:42: > Allen, > I understand that I am not resetting the timer and because of this > the first 100ms can actually be anywhere from 1ms to 99ms off. This can > cause anywhere from a 1 to 10% error rate. I thought of this while I was > half a sleep and half a wake yesterday. > I don't understand how to call the interrupt routine... *You* never do. It is "called" automaticly by the interrupt hardware logic whenever an interrupt condition occures. > and how to reset the timer. TMR1H =3D 0x0B; TMR1L =3D 0xDC; This can be done somewhere from your main() code (or in any function called from main() ). It makes the timer start on a new full 0.1 sec period. > I'm resetting the > count variable in the for loop. I am also checking for the counter > reaching 10 which is 1 second of time in the for loop. The incrementing > of count is taking place in the interrupt routine. So I guess my next > step is how do I actually use the interrupt routine? If you have setup the interrupt logic (GIE, TMR1IF and so on), the interrupt routine *will* be used whenever the timer1 rolls over (FFFF -> 0000). > This routine: > > Do I call Interrupt()? > No, never. See above. > void Interrupt() > { > if (TMR1IF_bit) > { > TMR1IF_bit =3D 0; > TMR1H =3D 0x0B; > TMR1L =3D 0xDC; > If so, what do I put here? > count++; //This increments the count variable > which was declared as global. > } > } > > Thanks, > rich! > > On 7/20/2014 4:14 PM, Allen Mulvey wrote: >> The for loop doesn't need to increment the counter. The ISR is doing tha= t in >> the background. I just think more conventional coding is easier to follo= w >> and most compilers will probably produce the same code for either. (I >> haven't tested this theory but past experience would cause me to be >> surprised if it didn't..) >> >> Allen >> >> > --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .