Instruction times


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116

    Default Instruction times

    Hi all,

    Can anyone tell me how to work out how long an instruction takes to execute when running at 20MHz?

    I have some software for firing a 3 phase bridge rectifier using thyristors. It now needs modifying to work on 50 or 60Hz. working with 50Hz just required a simple pauseus. Now it needs an if then else.

    if frequency = 50 then
    pauseus 1533 'delay for 60 degrees on 50Hz
    else
    pauseus 977 'delay for 60Hz
    endif

    The way phase angle firing works means that you get 6 peaks of current every mains cycle but the peaks are uneven, by as much as 200A.
    I think this is because of the extra time the if then takes to run.

    This just got me thinking how can I work out the time it takes to run an instruction, for time sensitive applications.

    Regards
    Bob...

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BobEdge View Post
    Can anyone tell me how to work out how long an instruction takes to execute when running at 20MHz?
    That would be about 5,000,000 single word instructions per second. But those are assembly instructions, not PicBasic instructions. Each PicBasic instruction differs in length. To get an idea how large parts of your code is in assembly, try the codesize.php utility here: http://www.picbasic.co.uk/forum/showthread.php?t=2418

    Then you can try to figure out the approximate speed of parts of your program.
    http://www.scalerobotics.com

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Some asm instructions takes 1, some other takes 2 instruction to execute, if you add conditionnal instruction then you mess up everything as they can use 1 OR 2 instructions, hence Code size is not a safe way to evaluate execution speed.

    What you want to use is a internal Timer, MPLAB stopwatch OR toggle a I/O then measure it with a scope.

    Look at the following, for simple code implementations. Note that you'll need to adjust those to suite 20MHz.
    http://www.picbasic.co.uk/forum/show...33&postcount=9
    http://www.picbasic.co.uk/forum/show...9&postcount=13


    For accuracy, you want to use internal timer instead of Pause/PauseUs. This also allow you to do something else in meantime.

    HTH
    Last edited by mister_e; - 5th June 2009 at 09:20.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  2. Calling Subroutines Multiple Times
    By Forkosh in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th March 2008, 07:11
  3. instruction cycles for math operations
    By Michael Wakileh in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th July 2007, 11:03
  4. code size using On Interrupt PBP instruction
    By eduardojx in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st December 2005, 09:57
  5. instruction execution time
    By tjg in forum Code Examples
    Replies: 3
    Last Post: - 21st April 2004, 18:15

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