Shop OBEX P1 Docs P2 Docs Learn Events
Best way to time events — Parallax Forums

Best way to time events

pmcgeepmcgee Posts: 6
edited 2007-07-31 17:21 in BASIC Stamp
Hi
I'm pretty new at this, so you'll have to forgive me if I get completely lost. My question is, what's the easiest and most accurate ways of timing events? I have a professional development board as well as a BS2, BS2p40 and a BS2px. Thanks.

Paul

Comments

  • metron9metron9 Posts: 1,100
    edited 2007-06-28 16:13
    Basically having a clock where you save the time at the start of the event and then calculate the time difference at the end of the event and save that in eeprom.
    Alot depends on how many events you need to time at whatever resolution you need to have. The longer the time periods the more timers you can keep track of, but you still only need one clock unless you need resolution in the us or ms range.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-28 16:20
    To answer that, you'd need to describe the kinds of events you're talking about. The professional development board has a clock (the DS1307) that can be used for timing events on the order of seconds. There's also the COUNT statement which can be used for timing pulses on the order of milliseconds to roughly a minute (smaller times when using the BS2p/px). In between, you can write a program that uses the PAUSE statement to provide a "tick" on the order of 10s to 100s of milliseconds.
  • pmcgeepmcgee Posts: 6
    edited 2007-07-25 16:18
    Hi,
    Sorry to bring this back up again after a while, but I now have a better idea of what my end goal is. I would like a way of measuring the time between the rising edges of two separate inputs. For instance, I am currently using a USBee DX test pod to generate signals on two pins. I'm not sure I really understand how to use the COUNT command to time things. It is my understanding that I must supply the COUNT with a duration of time and it would spit back the number of cycles. How would I be able to manipulate it to return the duration? I first thought that this whole timing thing would be quite trivial, but the further I get into it the more obstacles I find. There's a good chance I'm missing something obvious here so that's why I'm seeking the help of some experienced experts. I'm looking to achieve accuracy on the level of microseconds, if possible.

    How can I measure time between the two rising edges?

    __________________| |_______________________________

    ___________________________________| |____________


    Thanks for all your help.

    Paul

    Edit: You'll have to excuse my little stick diagram.

    Post Edited (pmcgee) : 7/25/2007 4:23:07 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-25 16:26
    You'll need to use external components to do this with a Stamp since the Stamps don't have a way to measure the time difference between two input pulse edges on the time scale you need. A simple flip-flop with a set/reset input would do. The first pulse edge would set the flip-flop and the second pulse edge would reset it. A PULSIN statement would measure the width of the flip-flop on pulse to the nearest 2us (for BS2/e/pe) or to the nearest 0.8us (for BS2sx/p/px).

    The COUNT statement counts the number of input pulses occurring during a specified time period ... not what you want (sorry for the wrong suggestion).
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-07-25 16:32
    The first thing that comes to mind is to use an external
    flip-flop, one of your signals to set it and the other to reset it, and time the single pulse Q output.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • pmcgeepmcgee Posts: 6
    edited 2007-07-25 17:03
    I have a StampWorks kit, so could I use the 555 that came with it as the flip flop or do you suggest something else? Reading the Wiki for the 555 it says that it works as a flip-flop in bistable mode. Thanks.

    Paul
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-25 17:20
    The 555 should work. Keep in mind that the 555 is not a fast device and has propagation delays on the order of tenths of a microsecond. The datasheet for the specific device should give you the specific delays involved.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-07-25 17:28
    The 555 would not be the most convenient thing for this. It does contain an SR filp flop, but that sets and resets when the trigger and reset pins respectively go low. Could you time between the falling edge of your pulses, instead of the rising edges?

    The easiest thing would be to go over to Radio Shack and buy a CD4001 or a 74HC02, quad NOR gate, and make an SR flip flop. It would set and reset on the rising edges of the two pulses.

    P.S. How long is the event, the time between the two triggers? The PULSIN command on the vanilla BS2 can measure pulses of duration up to 0.131 second with a resolution of 2 microseconds.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 7/25/2007 9:35:37 PM GMT
  • pmcgeepmcgee Posts: 6
    edited 2007-07-31 14:39
    Okay, I now have some 74HC02's and some 74S74's. How should I construct my circuit? I'm not too well versed in reading data sheets. Thanks.

    Paul
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-07-31 17:21
    Here is a connection diagram for the 74HC02. This uses 2 of the 4 gates in the 74HC02. Connect pins 8,9,11 and 12 to Vss if they are not used for anything else.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
    206 x 225 - 5K
Sign In or Register to comment.