Need to measure time within hundredths of a second
Michael @ Afineol
Posts: 33
I have a BS2 with a DS1302 RTC. This chip only measures up to seconds and I need an RTC that will measure hundredths of a second. Does anyone know of a chip like the DS1302 that will do this? I called the manufacturer and they suggested the DS1390 RTC. I am new to this so any help will be appreciated.
What I am "trying" to do is measure the time between turning on an LED and an object hitting a target. I have worked out the LED and target detection, but the time tracking still a mystery.
Michael @ Afineol
What I am "trying" to do is measure the time between turning on an LED and an object hitting a target. I have worked out the LED and target detection, but the time tracking still a mystery.
Michael @ Afineol
Comments
-Phil
use one var to hold the prevoius second read CurSecond
use another var to hold the just read second NewSecond
have a var that holds the last count between seconds CurCount
then finally a var that holds the ongoing count between seconds TmpCount
the below is just a representation not actual code
:loop
NewSecond = RTCSecond' RTCSecond is assumed to be the second portion of the time
If NewSecond = CurSecond then
TmpCount=TmpCount+1
else
CurCount=(CurCount+TmpCount)/2
TmpCount=0
endif
you would call the loop at the end of the main program loop
anytime you want to find out what fractional part of a second you are in
you look at CurCount and divide by TmpCount to get the fraction at any moment
the higher CurCount is the more accurate it will be
the larger your main loop will be the lower CurCount will be (hence less accurate)
the reason why it is constantly adjusting the average of the old count to new count
so if program length changes, temperature, voltage, or anything else that effects how fast the Basic Stamp executes code.
If you do try this please post what the CurCount is I'd like to know
basically this should be a cheap method to get some additional resolution in your project of your main program
that doesnt contain pause, sleep, pollwait, or any other big delays in your code.
Post Edited (Skeil) : 11/14/2007 9:07:31 PM GMT
www.emesystems.com/BS2speed.htm#longpulse
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I would just program a serial interface to a tiny45 that would turn on an led and set an internal timer to the resolution you need and an interrupt would stop the timer.
If 1 millisecond resloution is ok you could get a 2 byte response back that gives you the time from 1ms to 65535 ms
Of course if you would like a millionth of a second is also easy to do.
I can program one up for you if you like. i think I may just start charging 5 bucks for custom chips.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!