Calculating delay times in main program loop
Mightor
Posts: 338
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.
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
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.
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.
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.