Shop OBEX P1 Docs P2 Docs Learn Events
Is there a way to time total prgram execution time? — Parallax Forums

Is there a way to time total prgram execution time?

The DoctorThe Doctor Posts: 37
edited 2007-05-12 16:58 in BASIC Stamp
For example, 20 mS seems to be a key time for servo control.· I have a program that checks various sensors, then sends a pulse to the servos to move the bot.· Since servos like a 20 mS cycle, I would like to know how long the program takes to execute, so I can add an appropriate Pause statement at the end of the code to make the total loop take 20mS to run.

In VBScript, you can simply echo the computer clock at the start and end of the routine, but there is no RTC on the BS2.· Is there a way to start some type of clock timer at the beginning of you code, then stop and echo the·timer value at the end?· Something like this:

Start timer at 0
Execute code
end timer
echo timer value to console

Any input you can provide would be appreciated.· Thanks!

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-05-12 16:20
    Lacking an oscilloscope, the next best alternative is to use an LED or the Debug window as a start/stop indicator, run the routine to be timed a thousand times, time it manually, and divde the result by a thousand. That should get you close enough to do what you want.

    -Phil
  • The DoctorThe Doctor Posts: 37
    edited 2007-05-12 16:25
    Didn't think of that.· Thanks Phil!

    BTW, is there a way to interface a VBScript with the Stamp Editor?
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-12 16:41
    Another trick is to dedicate one pin to an RC circuit that gives an RCTIME value of around xcountref=50000. (around 100 milliseconds on a BS2, 2e or 2pe) Say C=0.1 uf and R=750 kohms. Start with the pin high, but make the pin an input when it hits the section you want to time. Then at the end of the section, change over to RCTIME. (RCTIME xpin, 1, xcount). The capacitor will already be partly discharged. Then the time taken by by the process is, (xcountref - xcount / 500) milliseconds. Or use /5 if you want it in units of 0.01 millisecond.

    If you have a second BASIC Stamp, use it as a pulsin timer.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-05-12 16:54
    Hi Doctor, regarding your question about scripts.·There are many·programming languages·that·can be used to communicate with a Stamp via the serial port, my preference is Visual Basic.

    There are applications at this link already designed just for that purpose.

    http://www.parallax.com/html_pages/downloads/software/software_basic_stamp.asp

    Jeff T.
  • The DoctorThe Doctor Posts: 37
    edited 2007-05-12 16:58
    Thanks all!
  • DufferDuffer Posts: 374
    edited 2007-05-12 16:58
    I've used the Basic Stamp Logic Analyzer (http://www.parallax.com/detail.asp?product_id=30010) with several of the Stamp modules to determine program timing and analyze/decode I/O streams. In your case, you could just insert a TOGGLE instruction on a pin at some point in your main or embeddid loop and use the BSLA to measure the square wave produced on that pin for very precise timing.

    I've used the above methode to test instruction times, loop times and to determine scaling values between various speed Stamps (BS2, BS2p and BS2px).

    Once you have one of these puppies, you'll find a lot of uses for it. It's a lot cheaper than an O-scope and for an amature like me it's a lot easier to use. The simple USB 2.0 interface and an excellent Windows GUI makes this a slam-dunk buy for Stamp users that need to dig deeper into their code performance than the DEBUG command allows.

    Good luck, Steve
Sign In or Register to comment.