Shop OBEX P1 Docs P2 Docs Learn Events
Need to measure time within hundredths of a second — Parallax Forums

Need to measure time within hundredths of a second

Michael @ AfineolMichael @ Afineol Posts: 33
edited 2007-11-14 21:52 in BASIC Stamp
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

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-11-14 20:20
    Is the maximum time delay less than 131mS? If so, you don't neeed an RTC at all — just a little external gating to form a pulse that you can measure with the PULSIN statement. If this is the case, what is the polarity (active high or active low) of the signal that drives the LED? What is the polarity of the signal arriving from the target?

    -Phil
  • SkeilSkeil Posts: 7
    edited 2007-11-14 21:00
    If you want to work with what you have you could try the following

    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
  • Michael @ AfineolMichael @ Afineol Posts: 33
    edited 2007-11-14 21:08
    The maximum time delay could be as high as several seconds to as low as (I don't know the answer to that). It is a matter of the individuals hand/eye speed. The answer to LED polarity is HIGH.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-11-14 21:29
    There is a little note on external timers and also on using a program loop for this purpose, at
    www.emesystems.com/BS2speed.htm#longpulse

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • metron9metron9 Posts: 1,100
    edited 2007-11-14 21:52
    Hmmm sounds like a job for a tiny45.

    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!
Sign In or Register to comment.