Shop OBEX P1 Docs P2 Docs Learn Events
Calculating delay times in main program loop — Parallax Forums

Calculating delay times in main program loop

MightorMightor Posts: 338
edited 2007-05-30 19:42 in BASIC Stamp
Hi there,

I was wondering how I should go about calculating the pause times I need to make sure I get a semi-accurate 20ms delay between pulses going to the servos. I have a standard Boe-Bot and I noticed that in some of the IR frequency sweep experiments (FollowingBoeBot.bs2) in the "Robotics with the Boe-Bot" book, the pause argument was down to 5ms. How do you calculate such a delay time without resorting to an oscilloscope?
According to the docs, the BS2 can do about 4000 OPS (Operations Per Second), so that implies about 0.25ms per instruction, however an IF.. THEN...ENDIF comparison takes more than just a single instruction and could potentially take up 1 ms depending on how complex it is. What is a general rule of thumb in PBASIC-land?
Is there a little tester circuit I can make to see if my pulses are 20ms apart (or close to it). I just don't want to fork out 140-150 Euro for a scope if I can accomplish the same with a 0.50E IC and some resistors/capacitors.

Gr,
Mightor

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
| What the world needs is more geniuses with humility, there are so few of us left.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-30 13:42
    Have a look at Tracy Allen's website (www.emesystems.com). Among all kinds of applications notes on things like math, reading sensors of different kinds, he has information on execution times of different Stamp models and different statements in PBasic.

    You could make a tester with two 555 timers (or a dual timer). Set up one as a "missing pulse detector" (see: www.uoguelph.ca/~antoon/gadgets/555/555.html), reset by the servo pulse. If the time between servo pulses becomes greater than 20ms, it will put out a pulse that might be quite short. The second 555 acts as a pulse stretcher, is triggered by the output of the first (in monostable mode) and lights an LED. By lighting the LED for just under 20ms, it will be on most of the time any time the first timer is triggered, even if that pulse is very short.
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-05-30 14:34
    The servo's will work with a 20 mSec to 50 mSec refresh interval. This should give you enough 'slop' so that you don't need to be completely accurate.

    Having said that, the 'watchdog timer' 555 solution suggested by Mike above would be an inexpensive way to check.

    The other way to check would be to have an LED that you 'toggle' every 500 mSec (which would be every 25 Servo Pulses). Then you time the blinks with a stop-watch, or even count a few while timing, to see how accurate your program is.
  • MightorMightor Posts: 338
    edited 2007-05-30 19:42
    Thanks for the suggestions! I will have a look at the 555 solution, I have a spare breadboard and the actual ICs are pretty cheap. Timing the LEDs is probably not as accurate but then again if the slop is that great then it probably doesn't matter anyway [noparse]:)[/noparse]

    Looks like I have a new little project on my hands [noparse]:)[/noparse]

    Gr,
    Mightor

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    | What the world needs is more geniuses with humility, there are so few of us left.
Sign In or Register to comment.