> > Hi: > > Forgive an inexperienced PIC programmer for asking, but how do you produce a > time delay in assembly? There are two universially used mechanisms: loops and timer/counters. Loops are used to execute instructions that individually take a certain amount of time. Timer/counters will count the number of instruction clocks (or external clock events) that occur. By monitoring the count, you can determine the amount of time elapsed. Timer/counters can be coupled with interrupts so that the processor can perform other tasks while the specified delay period elapses. > Does it depend on the clock oscillator? Usually unless some other external clock source is counted. > It if does, I'm using the RC Oscillator-2MHz. Well then you must be aware that anything you delay on using that oscillator will be an eastimate, because RC oscillators speed vary based on temp, precision of material, and other factors. It's going to be a difficult task if you require precise delays. Generally delays are computed in instruction cycles (IC). Simply multiply the number of instruction counts by the instruction cycle length (ICL) to get the length of the delay. And remember that for PIC 16/17 series that the oscillator is divided by 4 to get the instruction cycle length. So for example the IC for your part is 500 Khz, which computes to a ICL of 2uS. Lastly all branch instructions on a PIC take 2 IC. Putting all of this together, this segment of code: vdelay movwf c1 dloop decfsz c1 goto dloop return Each iteration of the loop takes 3IC (the decfsz is 1IC until it zeros c1, when it's then a 2IC instruction). The goto is always 2IC. The initial move is 1IC, the return is 2IC, and the presumed call into this subroutine is also 2IC, while finally the presumed move into W before the call is also 1IC. So the total delay is: 6IC+3IC*(initial value of W) So at your ICL (2uS) this routine would delay between 18uS and 1548uS with a grainularity of 6uS. Adding a second loop around the first adds significantly more range. Hope this helps, BAJ -- 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