Hi Bruce, thanks for the reply. I think you may have misunderstood my question a bit. Basically, I need (or rather want, I could get away with fewer, and may have to, as my calculations show if they are correct) 256 "gradients" of delay. Each individual section of delay should be ~162.5 instruction cycles. If I could set the prescaler to 256 different values, I could do it your way. But I only have a few values that I can set the prescaler to, so I think that should remain a constant. Unfortunately, one of those values isn't 162, so I think I will have to compromise. FWIW, the way to get 1:1 prescaling is to assign the prescaler to the watchdog timer. Thanks, Josh -- A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. -Douglas Adams "Gennette, Bruce" wrote: > > 1 TMR0 counts UP to 255, then to 0 then to 1 .... then to 255, .... > 2 You can over write its current value at any time (2 instruction cycle > delay in being set). > 3 You can use the pre scaler to 'tick' TMR0 at a slower rate. > 4 You can feed the pre scaler from the internal OSC/4 or from a separate, > external source. > 5 Each time it hits 0 it tries to set an interrupt flag. The user must > clear this flag manually. > 6 You may choose not to use interrupts, just manually examine the current > value to find when it passes 0. > 7 You can manually count ticks until your desired delay has elapsed. > > For your delay use 256-162 = 94 as the value to start counting from. > Set the prescaler to use by TMR0 > Set pre scaler to x1 <--- damn, not allowed, minimum is x2 > Recalculate your delay to 256-(162/2)= 175 > Set the timer interrupt AND global interrupts on > > In your interrupt routine over write TMR0 with 175, reset the tmr0 flag & > global flag and return > > This should be enough to get you started ;) OR maybe not .... > > To handle interrupts you either start your handler routine at address -org > 4- or put a goto handler_address there (Note - this interrupt vector address > varies with different PICs, check your data sheet). > PICs turn off global interrupts when any valid, enabled interrupt occurs, it > is up to the user to check and set (or not) any other interrupt flags. The > return from interrupt should not reset globals (giving the programer full > control over how multiple interrupts are handled). > > Now this should be enough to get you started ;) > > Bye. > > -----Original Message----- > From: Josh Koffman [mailto:listsjosh@3MTMP.COM] > Sent: 13 November 2001 14:58 > To: PICLIST@MITVMA.MIT.EDU > Subject: [PIC]: Beginner TMR0 Questions > > Hi all. It's time for Josh's nightly "I'm trying to use parts of the PIC > I don't fully understand" question. Well, thanks to Bob, Tony, Wouter, > and I think Vasile, I now understand the PCLATH. Well, enough to get the > job done. Anyway, now I must calculate the values I will put in to that > jump table. Here is the situation: > > I am taking an 8 bit value, and using it to come up with 256 values of > delay. Just so you know, it's a 16f628. Each individual delay section > will be 162.5 instruction cycles. I'll round it up or down for the ones > that don't come out to whole values. > -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads