How to calculate machine time in basic code?


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    May 2005
    Posts
    70

    Default How to calculate machine time in basic code?

    How to calculate machine time in basic code?
    Ex.
    Used 4 Mhz

    If porta.0 =1 then
    Portb.1=1
    Else
    Portb.2=1
    endif

  2. #2
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Execution Time Measurement

    The oldest timing trick is to drive an output bit high when
    entering a routine, and then low as we exit. Probe the port
    with an oscilloscope and measure the time the bit is set.

    * * *

    You can run your PBP program in the MPLAB simulator and use the
    StopWatch function to get the timing of the commands.
    (Menu Debugger\Stopwatch).


    Best regards,


    Luciano

  3. #3
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    We Used microcode studio plus software

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    A way that I often use is to compare the execution against a hardware timer.
    The example below works for an '8720 running at 20Mhz. You will have to modify accordingly if you use a different processor or XTAL.
    -----------------------------------------------------------------------


    DEFINE OSC 20

    DEFINE NO_CLRWDT 1 ' Don't waste cycles clearing WDT
    DEFINE _18F8720 1
    DEFINE HSER_RCSTA 90H
    DEFINE HSER_TXSTA 20H
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLROERR 1
    DEFINE LOADER_USED 1
    Define USE_LFSR 1

    TRISC = %10111111 ' Hardware serial port on PORTC.7,PORTC.6

    PSPCON = %00000000 ' No PSP
    MEMCON = %10000000 ' No External Memory
    CMCON = %00000111 ' No Comparator used, turn it off

    T0CON = %10001000 ' No Prescaler,16 bit


    TimerValue VAR WORD
    RealTime VAR WORD

    TestArray VAR BYTE[3600]

    DummyVal VAR Byte

    Restart:
    Intcon.2 = 0
    TMR0H =0
    TMR0L =0

    'Put code to be timed here





    '----------------------------------------

    TimerValue.LowByte = TMR0L
    TimerValue.Highbyte = TMR0H

    IF INTCON.2 = 1 THEN
    HSEROUT ["OVERFLOW - User different prescaler value",13,10]
    ENDIF



    HSEROUT ["Execution Time = ",#TimerValue, " Cycles, ",#TimerValue/5," Microseconds",13,10,10]


    HSEROUT ["Press any key to restart",13,10]

    HSERIN [DummyVal]
    GOTO Restart

    END
    Charles Linquist

Similar Threads

  1. PIC BASIC TLC5940 code
    By eletrokat in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2010, 21:01
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. 122x32 GLCD basic code
    By skimask in forum Code Examples
    Replies: 17
    Last Post: - 21st April 2008, 17:46
  4. Error code [112]/[113]
    By Dj tempo in forum General
    Replies: 3
    Last Post: - 17th June 2007, 16:15
  5. ASM Interrupts with BASIC code?
    By Desterline in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 31st October 2003, 19:21

Members who have read this thread : 0

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