Shop OBEX P1 Docs P2 Docs Learn Events
code execution time — Parallax Forums

code execution time

ichoelichoel Posts: 17
edited 2009-06-27 02:24 in Robotics
Hi, i am looking for answers of questions below. Someone can help ??

1. From datasheet, program execution speed for BS2 is 4000 instructions/sec. How does it come?
2. On Robotics with the Boe Bot chapter 2, page 83, there is a time calculation for servo code.
1.7 ms - pulse duration 850
1.3 ms - pulse duration 650
20 ms - pause duration
1.6 ms - code overhead - what does it mean ?


-ichoel-

"There is sky over the sky"

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-24 12:53
    Look at Tracy Allen's website (www.emesystems.com). At the bottom of the page, there's a link "app-notes". Among other things, he has a discussion of measured execution times for various statements on various Stamp models.

    1) Someone at Parallax took a look at the source code for the Stamp Basic interpreter and estimated the execution time for typical interpretive instructions. The simple statements like HIGH / LOW / TOGGLE, GOTO, and IF / THEN typically compile into a one or two instructions. Arithmetic operations like + , -, =, < would compile into one or two instructions.

    2) The units for the PULSOUT (as described in the manual) are 2us for the BS2. If you have a "PULSOUT 11,1370", then you will get a pulse on pin 11 of 2.74ms (2us x 1370).

    In the program fragment shown, there's probably a "PAUSE 20" which results in a 20ms pause in program execution. Servo motors require a control pulse roughly every 20ms and the PAUSE is used to create that timing.

    Code overhead is the approximate execution time of all of the statements used in the loop or program fragment of interest other than the actual timed operation of the statements. For example, if you have a PULSOUT followed by a PAUSE, they both specify a time for execution, but there's some additional time (overhead) for the Basic interpreter to get the instruction codes out of program memory and interpret them. There may also be some control statements like FOR / NEXT or IF / THEN that surround the timed statements. They are considered overhead as well since they don't result in a specific time interval, but they do take some time to execute.
  • ichoelichoel Posts: 17
    edited 2009-06-27 01:50
    Thanks for your information about Tracy's website, Mike. It's so helpful to understand this thing. But still I didn't find answer for my first question "BS2 execution speed is 4000 instructions/sec". How do they calculate that? Is it from BS2 clock speed (20 Mhz), but how?




    -ichoel-


    "There is sky over the sky"
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-27 02:24
    The "instructions" they're talking about are interpretive instructions, not PIC instructions. They probably took a relatively simple non-I/O dependent program (because I/O statements have additional delays inherent in them), put it in a loop that executed it maybe 10000 times, put a DEBUG statement at the beginning and end to put out a message to the connected PC, and used a stopwatch to time the difference between the begin and end messages. They divided the elapsed time by 10000 and got the execution time for a single execution of the program. They then looked at a dump of the compiled program and counted the number of interpretive instructions. They divided the elapsed time for a single execution by the number of interpretive instructions and got 4000.

    I don't know for certain if that's exactly how they did it, but this is the way I'd come up with that number.
Sign In or Register to comment.