+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Newbie level 4
    Points: 52, Level: 1

    Join Date
    Oct 2014
    Posts
    7
    Helped
    0 / 0
    Points
    52
    Level
    1

    Assembly instruction cycle for 3 counters delay loops

    Hello forum members,

    I need to know formula of this loop.

    Code:
    DELAY					
    		MOVLW HFF(M)				1
    		MOVWF SAYAC1				1
    Loop1					
    		MOVLW H90(N)				1XM
    		MOVWF SAYAC2				1XM
    Loop2					
    		MOVLW H50(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 ?

    •   AltAdvertisment

        
       

  2. #2
    Advanced Member level 5
    Points: 20,490, Level: 34
    Achievements:
    7 years registered

    Join Date
    May 2009
    Location
    Prime Meridian
    Posts
    3,056
    Helped
    892 / 892
    Points
    20,490
    Level
    34

    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. #3
    Newbie level 4
    Points: 52, Level: 1

    Join Date
    Oct 2014
    Posts
    7
    Helped
    0 / 0
    Points
    52
    Level
    1

    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.



    •   AltAdvertisment

        
       

  4. #4
    Advanced Member level 4
    Points: 7,806, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,289
    Helped
    261 / 261
    Points
    7,806
    Level
    21

    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

    Click image for larger version. 

Name:	Delay_asm.jpg 
Views:	7 
Size:	175.0 KB 
ID:	110808

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


    1 members found this post helpful.

  5. #5
    Advanced Member level 5
    Points: 20,490, Level: 34
    Achievements:
    7 years registered

    Join Date
    May 2009
    Location
    Prime Meridian
    Posts
    3,056
    Helped
    892 / 892
    Points
    20,490
    Level
    34

    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. #6
    Newbie level 4
    Points: 52, Level: 1

    Join Date
    Oct 2014
    Posts
    7
    Helped
    0 / 0
    Points
    52
    Level
    1

    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 H50				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.
    Last edited by BLaacK89; 29th October 2014 at 21:06.



    •   AltAdvertisment

        
       

  7. #7
    Advanced Member level 5
    Points: 20,490, Level: 34
    Achievements:
    7 years registered

    Join Date
    May 2009
    Location
    Prime Meridian
    Posts
    3,056
    Helped
    892 / 892
    Points
    20,490
    Level
    34

    Re: Assembly instruction cycle for 3 counters delay loops

    Quote Originally Posted by BLaacK89 View Post
    @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 H50				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.

--[[ ]]--