janetsmith2000@yahoo.com
New Member
how to calculate the delay for each instruction?
The above listing is taken from the MPLAB (compiled with CCS compiler).
I am using 8Mhz resonator.
Each instruction clock takes 4 clock cycles = 1 /(8 MHz / 4 ) = 0.5 us
GOTO takes 2 instruction clocks
DECFSZ + GOTO loop for 119 times (0x77 = 119) = (1 + 2) x 119 x 0.5 us = 178.5 us
MOVLW + MOVWF + NOP + NOP = 4 x 0.5us = 2 us
The total time spent = 178.5us + 2us = 180.5 us
Is the calculation correct?
I am expecting 90 us, the calculation give me 180.5 us.
Code:
57: delay_us(90);
00002F 303B MOVLW 0x3b
000030 0F7 MOVWF 0x77
000031 BF7 DECFSZ 0x77, F
000032 2831 GOTO 0x31
000033 000 NOP
000034 000 NOP
The above listing is taken from the MPLAB (compiled with CCS compiler).
I am using 8Mhz resonator.
Each instruction clock takes 4 clock cycles = 1 /(8 MHz / 4 ) = 0.5 us
GOTO takes 2 instruction clocks
DECFSZ + GOTO loop for 119 times (0x77 = 119) = (1 + 2) x 119 x 0.5 us = 178.5 us
MOVLW + MOVWF + NOP + NOP = 4 x 0.5us = 2 us
The total time spent = 178.5us + 2us = 180.5 us
Is the calculation correct?
I am expecting 90 us, the calculation give me 180.5 us.