# Assembly instruction cycle for 3 counters delay loops

1. ## Assembly instruction cycle for 3 counters delay loops

Hello forum members,

I need to know formula of this loop.

Code:
```DELAY
MOVLW H’FF’(M)				1
MOVWF SAYAC1				1
Loop1
MOVLW H’90’(N)				1XM
MOVWF SAYAC2				1XM
Loop2
MOVLW H’50’(D)				1xNXM
MOVWF SAYAC3				1XNXM
Loop3
DECFSZ SAYAC3,F			(D+1) .N.M
GOTO	Loop3					(2.D-2) .N .M
DECFSZ SAYAC2,F			(N+1) .M
GOTO	Loop2					(2.N-2) . M
DECFSZ SAYAC1,F			M+1
GOTO	Loop1					2M-2

RETURN							2```
Formula = 3+4.N+3.M.N ?

why the formula is not true ?

•

2. ## Re: Assembly instruction cycle for 3 counters delay loops

Hi,

A software delay loop is based on the number of instruction to complete that loop.

Does your formula account for the fact that not all of those instruction are completed in one machine cycle, some like the goto and decf may need 2 machine cycles. ( see the chips data sheet - section Instruction Set Summary.)

The loop as it stands in just short of 9 million instructions on a Pic16F.

3. ## Re: Assembly instruction cycle for 3 counters delay loops

Thanks for helping,

I used pic16f887.

I need formula cause of I would like to flexibly projects.

•

4. ## Re: Assembly instruction cycle for 3 counters delay loops

hello,

your formula is wrong.. because you are using external loop
and reinitiate value inside the loop..
so global is more than M*N*D ..etc ..

if preferre to use this, from Myke Predo 1997 !
very universal

at 4MHz FOSC , cycle=1µS
mini is with values count1=1,count2=1,count3=1 => 6µS
maxima is with values 255 ,255,255 => 83.559 secondes !!!
Formula inside the picture...

1 members found this post helpful.

5. ## Re: Assembly instruction cycle for 3 counters delay loops

Hi,

Think that chart paulfjujo shows does just about everything, but for basic delays I find this calculator as easy as it gets.

http://www.golovchenko.org/cgi-bin/delay

2 members found this post helpful.

6. ## Re: Assembly instruction cycle for 3 counters delay loops

@wp100

http://waihung.net/microchip-delay-calculator/

Please forget easy delay generators .

I've tried a lot of generator. all generators are different . I am annoyed about this situation.

So. I need more maths operation for truely delay loops.

@paulfjujo

Let me match our math operation .

Let's write the number of the instruction against the code

Code:
```                DELAY
MOVLW H’50’				1
MOVWF Count1				1
Loop1
DECFSZ Count1,F			        2+Count1-1  =1+count1
GOTO	Loop1					2x(count1-1)= 2xcount1  -2

RETURN							2```
total = 2 + 1+count1+2count1 -2 +2
total = 3+3count1
total = 153instruction cycle .

please do math operation by same way.

•

7. ## Re: Assembly instruction cycle for 3 counters delay loops

Originally Posted by BLaacK89
@wp100

http://waihung.net/microchip-delay-calculator/

Please forget easy delay generators .

I've tried a lot of generator. all generators are different . I am annoyed about this situation.

So. I need more maths operation for truely delay loops.

@paulfjujo

Let me match our math operation .

Let's write the number of the instruction against the code

Code:
```                DELAY
MOVLW H’50’				1
MOVWF Count1				1
Loop1
DECFSZ Count1,F			        2+Count1-1  =1+count1
GOTO	Loop1					2x(count1-1)= 2xcount1  -2

RETURN							2```
total = 2 + 1+count1+2count1 -2 +2
total = 3+3count1
total = 153instruction cycle .

please do math operation by same way.

Hi,

The Decfsz is only 1 cycle when used in that mode .

H'50' = decimal 80

Have you tried using MPlabs SIMulator and Stopwatch, you can Single Step though each instruction or use breakpoints to start and stop code between certain points.
The Stopwatch increments with each instruction.

1 members found this post helpful.

--[[ ]]--