Getting accurate time at a ms resolution?
patterson7019
Posts: 25
I'm liking basic stamp. Nice piece of work!
In my main loop, I don't want to have to guess how long it has been since I sent a pulse to a servo. If I were writting for my Mac, I would use a system timer, like the following. From my reading here, the DS1302 won't work as that only goes down to seconds. I haven't used a 555 timer, but can it be set to make an i/o pin high, then low once a certain amount of time has passed?
Thanks,
Lee
Post Edited (patterson7019) : 7/4/2008 8:36:49 PM GMT
In my main loop, I don't want to have to guess how long it has been since I sent a pulse to a servo. If I were writting for my Mac, I would use a system timer, like the following. From my reading here, the DS1302 won't work as that only goes down to seconds. I haven't used a 555 timer, but can it be set to make an i/o pin high, then low once a certain amount of time has passed?
long lastUpdate=0; long now=0; while(true) { now = System.currentTimeMillis(); if(now-lastUpdate > 20) { updateServos(); lastUpdate = now; } dosomething(); }
Thanks,
Lee
Post Edited (patterson7019) : 7/4/2008 8:36:49 PM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!
For $6 or so, you get a programmable clock (50 mSec typical) as well as an 11-byte recieve-only serial buffer, in an 8 pin chip.
You can then use the programmable clock as a 'tick' generator for your own multi-tasking BS2 program.
And I believe the clock is very accurate.
Post Edited (allanlane5) : 7/8/2008 4:57:34 PM GMT
The coprocessors looks rather interesting. Have you actually used them allan? Thanks kenwtn, after working with the servos directly, which is a really good exercise, I plan to use one for my V2 robot. For my first robot the BS2 will be doing it all. But now I don't know which I like better, that little servo controller from pololu or the one from parallax!
perhaps something along these lines:
time VAR word
time = 0
Main:
PULSOUT 5, 1000
time = time + 2
PAUSE 5
time = time + 5
If time > 20 then ServoUpdate
goto Main
EDIT: Yes you could use the 555 in the way you describe. In "monostable" mode you would send the 555 a trigger pulse, this would cause the 555 to output one squarewave pulse and you could then monitor this with the Stamp.
Post Edited (BobLowry) : 7/8/2008 5:55:47 PM GMT