instruction execution time


Closed Thread
Results 1 to 4 of 4
  1. #1
    tjg's Avatar
    tjg Guest

    Default instruction execution time

    hello ,
    i'm on a project that really imposes me knowing the different execution times of the various picbasic pro instructions but i can't really lay hands on this information.
    Does anybody know where i can find this?

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi tj,

    I don't think there is a list that shows execution times for each statement, because it depends on where the code is located in program memory, what bank the variables are in, and what size variable is being used. All the bank switching and code page changing takes time too.

    However, it's pretty easy to actually measure the time it takes to execute any block of statements. This saves you from having to add them all up anyways.

    Since a timer set to 1:1 prescaler uses FOSC/4, each tick represents the time it takes to execute 1 instruction cycle.

    So you can simply zero the timer and then turn it on just before the statements you want to time. Then turn it off immediately after those statements. The value in the timer will indicate the number of cycles used. You can then convert that to uSeconds if needed fairly easily by multiplying * 1/(OSC*1000000/4).

    Here's an example of measuring the time to do a 16/16 bit divide. But you can have any number of statements inbetween, as long as the time does not exceed 65535 instructions.
    Code:
    T1CON = 0                 ' Prescaler = 1:1,  Timer off
    @  MOVE?CB  OSC, _PicOSC  ; Get OSC value, for Time calculation
    
    W1        var word
    W2        var word
    Dummy  var word
    
    W1 = 12345
    W2 = 12
    
    ' -----  Measure Time for 16/16-bit variable divide -----
    Gosub ClearTimer1:
    @ bsf     T1CON, TMR1ON   ' Start timer
    Dummy = W1/W2               ' The statement to measure
    @ bcf     T1CON, TMR1ON   ' Stop timer
    Hserout ["16/16 Var divide= "] : Gosub ShowTime
    
    STOP
    '----------------------------------------------------------------
    PicOSC     Var Byte
    Cycles     Var Word
    Period     Var Word
    Time       Var Word
    
    ClearTimer1:
        TMR1H = 0
        TMR1L = 0
    Return
    
    ShowTime:
        Cycles.lowbyte  = TMR1L
        Cycles.highbyte = TMR1H
        Period = 1000 / PicOSC * 4 / 10   ' Time for 1 Instruction Cycle in 100ns
        Time = Cycles * Period
        Time = Div32 10
        Hserout [ Dec Cycles, "   ",Dec Time/10, ".", Dec Time//10," uS", 13,10]
    Return
    @ 20Mhz, the result for this is 382 instructions or 76.4uS

    HTH,
       Darrel
    Last edited by Darrel Taylor; - 17th April 2004 at 22:40.

  3. #3
    tjg's Avatar
    tjg Guest


    Did you find this post helpful? Yes | No

    Default instruction execution time

    Thanks very much Taylor for such an inspiration.
    I tried it out and with some minor modifications, I finally obtained what i was looking for. I'm still on the project and was also wondering if this technique could be extended to a PC. Can you help me out?

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Not quite sure what you mean, do you want to time a program that's running on the PC, or send the results from the PIC to the PC?

    DT

Similar Threads

  1. Code execution time?
    By achilles03 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th February 2009, 16:07
  2. Code snippet: time execution for each line: help please
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th April 2008, 15:46
  3. Execution time in programme
    By Adrian in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th November 2007, 22:29
  4. PIC instruction time
    By Adrian in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th June 2007, 02:53
  5. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 19:55

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts