The reason I need this routine to be short is because I have to retfie in time for the next interrupt (24 instruction cycles per interrupt, 18 after you consider the 4 instructions it takes for the PIC to go to the interrupt vector, etc. and the 2 instructions it takes to retfie). Speaking of which, does anyone have any experience with this problem? If the interrupt takes exactly 24 cycles (counting the two issues above), will it always come through, or should I use a maximum of 23 to be on the safe side? (The code that executes in-between interrupts is just an infinite loop. This is running on a PIC16F872 @ 3.6864 MHz.) > -----Original Message----- > From: adam-request@viratech.com [mailto:adam-request@viratech.com] On > Behalf Of Barry Gershenfeld > Sent: Wednesday, August 07, 2002 2:15 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]: Four byte counter - best method? > > If you otherwise have the time, how about figuring out > beforehand that you will reach zero on the *next* > interrupt, and leave yourself a flag for that. > Check at the top of the i.s.r. and you know > after a single test. > > Barry > > At 01:55 PM 8/7/02 -0500, you wrote: > >Here's the setup: > > > >Four variables - T_FL0, T_FL1, T_FL2, T_FL3 - make up a four byte > >counter where T_FL0 is the least significant byte. The counter is > >loaded up with a number up to 00000001 00001000 00000000 00000000 > >(notice the 0x80000 precluding the elimination of the last byte), and > >then is decremented on each interrupt until it is zero, at which point a > >single instruction is executed. The code I have now is: > > > > decf T_FL0 > > btfsc STATUS, 0 ;test carry flag > > decf T_FL1 > > btfsc STATUS, 0 > > decf T_FL2 > > btfsc STATUS, 0 > > decf T_FL3 > > btfsc STATUS, 0 > > [single instruction to be executed when counter = 0] > > retfie > > > >Right now there are 9 instructions executed before the retfie. I need > >to get this down to 7 (preferably 6). > > > >Any suggestions? > > > >Thanks, > >Adam Smith > > > >-- > >http://www.piclist.com hint: The PICList is archived three different > >ways. See http://www.piclist.com/#archives for details. > > > > > > > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.