On Sat, Jun 29, 2013 at 06:43:54PM +0800, Electronic Consultation wrote: > Is my counter will give me the right 10ms ? I think we may want to step back a bit and examine what it is that you are really trying to get done. Some questions: 1) What chip are you using? 2) What speed are you running the chip? 3) What other activities need to be done by the chip? Also do any of those other activities need to be done while this delay is going on? For virtually any modern PIC, this is best done using one of the hardware timers. It's pretty much set and forget. The timer will independently track elapsed time and raise a flag when it rolls over. You code will only need to track the flag, and reset it when it rolls over. Just as an aside, this is one of the problems with the absolute tons of material out on the Internet about software timers. Most of this was written years ago when the PIC 16F84 was the hot chip. It only had one 8 bit hardware timer, so it was a precious and not very useful resource. Modern PICs have between 3 and 5 timers. Timers 2,4,6 in many updated chips are designed to autorollover. With this feature not only will they raise a flag (or generate an interrupt) at a precise time, but will also automatically start the next precise cycle without software intervention. These timers are designed for use with PWM and the CCP. However, they can be used standalone in the same manner. But without answers for the questions above, it's tough to know if you have the resources to use the hardware timers, or if the timing is correct on the software timers. BAJ >=20 > ;********************************************************************** > ; 10ms timer function calls > ;********************************************************************** > ;....... 10ms timer counter here..... > timer10ms > movf 0x0A > btfsc STATUS,Z > goto timer10ms >=20 >=20 > ;.................................... >=20 > incf COUNT1, f > movlw .10 ;Compare count to 100 decimal > subwf COUNT1, W ;Store the result back in > btfss STATUS, C ;Is the result 0, skip if no > goto exittimer > clrf COUNT1 > On 29/06/2013 1:45 PM, eCHIP wrote: > > If you need a 100 mS delay with a 4 MHz PICmicro, below is the code. > > > > delay1mS movlw .250 > > movwf temp1 > > clrwdt > > decfsz temp1,f > > goto $-2 > > retlw 00 > > > > > > delay100ms movlw .100 > > movwf temp > > call delay1ms > > decfsz temp,f > > goto $-2 > > retlw 00 > > > > Cheers > > > > Ravi > > > > > >> Hi, when you post to the Piclist you need to put an appropriate topic > >> tag in the subject line. This time I have added one to your message. B= ob > >> > >> On Fri, Jun 28, 2013, at 10:04 PM, Electronic Consultation wrote: > >>> Guys, > >>> > >>> Am I creating a right counter for PIC ? > >>> > >>> timer100ms > >>> movlw 0x64 > >>> movwf COUNT1 > >>> decfsz COUNT1 > >>> return > >>> > >>> thanks >=20 > --=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 --=20 Byron A. Jeff Chair: Department of Computer Science and Information Technology College of Information and Mathematical Sciences Clayton State University http://faculty.clayton.edu/bjeff --=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 .