For all short delays there will be some "overhead". For microsecond delays this can be quite significant adding 4 to 5 us to each delay (count the number of clock cycles in the routine).
It would be nice if the overhead is constant however it is not. Every time the high byte loop is executed it adds to the overhead in the delay. Now I have cobbled together the following ASM for microsecond delay delays that does not have this problem.
Delay_US
incf SysWaitTempUS_H, F
incf SysWaitTempUS, F
DUS_START
nop
nop
decfsz SysWaitTempUS, F
goto DUS_START
nop
nop
decf SysWaitTempUS, F
decfsz SysWaitTempUS_H, F
goto DUS_START
return
Maybe somebody can do better!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Perhaps I should have been clearer in what I was doing...
if I put in wait of 255 us then a wait of 256 us I would like the second delay to be exactly 1 us longer than the first.
Going to the oscilloscope wait for 255 us gives 255 us + 15 cycles so about 3 us too long
for 256 us I get 256 us +19 cycles nearly 4 us too long.
The extra cycles are unavoidable and could be compensated for if required, but the variation is a bit more difficult to deal with and needs a change in the compiler code.
What I suggested gives a overhead of about 21 cycles, but it remains constant for 255, 256 and even 4096 us.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For all short delays there will be some "overhead". For microsecond delays this can be quite significant adding 4 to 5 us to each delay (count the number of clock cycles in the routine).
It would be nice if the overhead is constant however it is not. Every time the high byte loop is executed it adds to the overhead in the delay. Now I have cobbled together the following ASM for microsecond delay delays that does not have this problem.
Delay_US
incf SysWaitTempUS_H, F
incf SysWaitTempUS, F
DUS_START
nop
nop
decfsz SysWaitTempUS, F
goto DUS_START
nop
nop
decf SysWaitTempUS, F
decfsz SysWaitTempUS_H, F
goto DUS_START
return
Maybe somebody can do better!
Perhaps this? :
Delay_US
incf SysWaitTempUS_H, F
incf SysWaitTempUS, F
DUS_START
nop
nop
decfsz SysWaitTempUS, F
goto DUS_START
nop
nop
nop
decf SysWaitTempUS, F
decfsz SysWaitTempUS_H, F
goto DUS_START
return
... The "long" loop has now 10 cycles (i think)... we are talking about long delays... isn't it?
Perhaps I should have been clearer in what I was doing...
if I put in wait of 255 us then a wait of 256 us I would like the second delay to be exactly 1 us longer than the first.
Going to the oscilloscope wait for 255 us gives 255 us + 15 cycles so about 3 us too long
for 256 us I get 256 us +19 cycles nearly 4 us too long.
The extra cycles are unavoidable and could be compensated for if required, but the variation is a bit more difficult to deal with and needs a change in the compiler code.
What I suggested gives a overhead of about 21 cycles, but it remains constant for 255, 256 and even 4096 us.