Hi, some comments: obviously, if the highest time you can reach with one rollover is 65536 usec, then it is NOT possible to reach a quarter second in one pass. Do the following: Preload TMR with 0x0C, which is, in turn 256 - 244. Then overflow will occur in every 62464 usec. If you count it, the every 16th event has nearby 1 seconds between them (999424 usec). 2nd remark: the BSF INTCON,GIE in the ISR is completely superfluous, because of RETFIE exactly does it. 3rd remark: you must re-set INTCON.T0IF otherwise ISR will immediately re-entered. Context saving is necessary, I do not want to repeat comments already done. Regards, Imre On Wed, 8 Nov 2000, Hardware Engineering wrote: > Never used interupts...but its time. Similar to another post of using TMR0, > where he wants to use a 4MHz clock (giving a 1MHz or 1uS state time) and time > for 1 second, I need to do a similar thing. But I think the math is off, > because if you use a /256 on the prescaler thats 256uS per tic for TMR0, and > you can only have a max of 256 tic for TMR0 before it rolls over thats > 65,536us (a bit short of 1000000us for 1 second). Now the purpose of my > application is to generate a 1 second rate for several timers. I could do a > simple loop where I just delay and the decrement the count for the other > timers, but I need to have several timers running in parallel. > > Since I can't generate a 1 second interupt (could change the clock but then we > get into custom crystals as well) I figure that I set TMR0 to a value of 159 > (decimal) and the prescale to 256. This would give me pretty close to a > quarter second for the interupt. Thus when vectoring to the interupt, it > would reload the value to TMR0, decrement a QTRCNT value, check for zero. If > zero, that means 4 quarter seconds passed and thus one second....THEN....I can > decrement all my other timers...sounds simple? Not sure..how the interupts > need to be set up and all that. My init code has this: > > ; set up TIMER0 for interupt vector for every quarter second > movlw 0x07 > movwf OPTION_REG > > movlw 0xA0 > movwf INTCON ; set interupt for TMR0 > > movlw 0x9E ; intial set for overflow value > movwf TMR0 ; to be reloaded on each interupt > movlw 0x04 ; for 4 quarter seconds > movwf QTRCNT > > Then...for the interupt.... > > org 0x004 ; interupt vector > movlw 0x9E ; intial set for overflow value > movwf TMR0 ; to be reloaded on each interupt > decfsz QTRCNT,1 > goto NOTZ > movlw 0x04 > movwf QTRCNT ; we reached the count so reload > < decrement all the counters etc> > bsf INTCON, GIE ; enable interupts again > retfie > NOTZ: > ; bsf PORTC,0 > bsf INTCON, GIE ; enable interupts again > retfie > > Comments? > > Again, thanks for all the help on this list. > > ____________________________________________________________________ > Get free email and a permanent address at http://www.netaddress.com/?N=1 > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > "[PIC]:","[SX]:","[AVR]:" > > > > > -- 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