i used interrupt add my adc program and some doubt the calculation.
my operating frequancy 20mhz. i want20us delay .how to calculate this?
please help me? iam waiting your valid replay
I guess that you are using a 16F series PIC. For those, the PIC takes 4 clock cycles to execute one instruction.
A 20 MHz clock has a cycle time of 50 ns so 4 cycles is 200 nS. A 20 µs delay is 100 instruction cycles.
A delay loop of 100 cycles would look something like this:-
Code:
movlw d'33'
movwf delay_reg ; You need to define a register for this
delay_loop
decfsz delay_reg, f
goto delay_loop
That just goes round the loop 33 times. The GOTO instruction takes 2 instruction times, so the loop takes 3 instruction times. Running it 33 times takes 100 cycles (might not be exact, but it is close) so just about 20 µs at 20 MHz