At 05:19 PM 8/5/02 -0400, Michael A. Powers wrote: > bsf PORTB, 4 > bsf PORTB, 1 ;--------------------- > ; delay for at least 2ms > movlw 0x95 > movwf Dlay > movlw 0x02 > movwf Dlay + 1 > decfsz Dlay > goto $ - 1 > decfsz Dlay + 1 > goto $ - 3 > > bcf PORTB, 4 ; -------------------- > >When I measured this on an oscilloscope, the actual delay came to be 1.2 ms. >If anything, it should be greater than 2 ms because I did not take the extra >cycles that occur each borrow. Does each subtraction that does not borrow >take 3us to complete? (1us for decfsz, 2us for goto) The problem is your last 'goto' - you jump back to 'decfsz Dlay', you should be jumping back to 'movlw 0x02'. But - you should be using labels in your code! This business of 'goto $-3' is BAD PROGRAMMING! What happens when you add 1 extra line of code? I cheat too - I will sometimes use 'goto $-1'. But NO more than 1! Here is how I think the code should be written: movlw 0x95 movwf Dlay Delay_loop movlw 0x02 movwf Dlay + 1 decfsz Dlay goto $ - 1 decfsz Dlay + 1 goto Delay_loop dwayne -- Dwayne Reid Trinity Electronics Systems Ltd Edmonton, AB, CANADA (780) 489-3199 voice (780) 487-6397 fax Celebrating 18 years of Engineering Innovation (1984 - 2002) .-. .-. .-. .-. .-. .-. .-. .-. .-. .- `-' `-' `-' `-' `-' `-' `-' `-' `-' Do NOT send unsolicited commercial email to this email address. This message neither grants consent to receive unsolicited commercial email nor is intended to solicit commercial email. -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads