oop, made a little mistake in do_low. This fixes it and gives a cosistent 18-cycle overhead: bsf PORTA,0 ;set pin high do_high: ;high byte sets the number of 256 cycle delays movf countHI,f btfsc 3,2 ;test for zero goto do_low movlw 0x53 ;this constant makes it 256 cycle delay movwf temp decfsz temp goto $-1 decf countHI goto do_high do_low: ;finish up with the low byte bcf 3,0 ;clear carry rrf countLO ;rotate right btfss 3,0 ;test LSB, take long way if set goto $+3 nop nop bcf 3,0 ;same thing again rrf countLO btfss 3,0 ;except long way is even longer goto $+4 nop nop nop decfsz countLO ;4-cycle loop the rest goto $-2 bcf PORTA,0 ;clear the pin Cheerful regards, Bob Blick On Wed, 24 Apr 2002, Bob Blick wrote: > This is what I came up with for a 16 bit pulse on RA0. It has 1 execution > cycle resolution and simulates OK, I haven't calculated the overhead but > it seems to be the same regardless of what number is fed to it: > > bsf PORTA,0 ;set pin high > do_high: ;high byte sets the number of 256 cycle delays > movf countHI,f > btfsc 3,2 ;test for zero > goto do_low > movlw 0x53 ;this constant makes it 256 cycle delay > movwf temp > decfsz temp > goto $-1 > decf countHI > goto do_high > do_low: ;finish up with the low byte > bcf 3,0 ;clear carry > rrf countLO ;rotate right > btfss 3,0 ;test LSB, take long way if set > goto $+2 > nop > bcf 3,0 ;same thing again > rrf countLO > btfss 3,0 ;except long way is even longer > goto $+4 > nop > nop > nop > decfsz countLO ;4-cycle loop the rest > goto $-2 > bcf PORTA,0 ;clear the pin > Cheerful regards, > > Bob > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. > > -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.