Building Millisecond Timer

Discussion in 'General Electronics Chat' started by bilbo_braggins, Feb 16, 2011.

  1. bilbo_braggins

    Thread Starter New Member

    Feb 16, 2011
    2
    0
    I have a project which requires me to determine the amount of time it takes for a relay to close after having pushed a button on a keyboard. I'd like to use the keyboards momentary switch to start the timing, and and use the voltage from the relay to stop the timing. Am I crazy for considering rewiring a stopwatch like this (timing down to the millisecond is needed)? I am a software engineer with almost no electrical engineering experience, but hopefully with forums help I can pick up a little as I delve into this project.:)
     
  2. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    There is a great deal to the task.

    First, if you are using a PC, you need to decode the key.

    Then there is the OS delay in interpreting the keystroke, then sending the data to the serial or USB external relay board, at which point you'd have to time the contact closure time.

    This may be in the 1mS or less range (even through the OS).

    If you are trying to measure switch time of a relay with a button, battery, and relay, you only need a handful of ICs. The button would start a timer (32.768kHz crystal counter), and the contacts of the relay closing would stop the timer (counter). Then a display system added on and you have what you want.

    To sum: I'm unsure if you want to measure time from a PC keyboard to a Relay on a port, or the speed of a relay on it's own.
     
    bilbo_braggins likes this.
  3. bilbo_braggins

    Thread Starter New Member

    Feb 16, 2011
    2
    0

    Thanks for the reply. I hoped to wire into the key's momentary switch to start the timing, and then stop the timing upon the relays trigger. The keyboard is not a PC keyboard, and timing on a single PC will not suffice. The (simplified) setup looks something like this:
    [​IMG]
     
  4. someonesdad

    Senior Member

    Jul 7, 2009
    1,585
    141
    Here are two things to think about. First, if you have a computer running an OS in there, the timing will likely not be deterministic. But the standard deviation might be small enough for your purposes -- you can't tell without making measurements.

    Second, if the keyboard involves a switch with no electronic buffering, then you may have to deal with contact bounce. This can confuse the timing if you're not careful.

    The simplest way to do this task is to use a scope. Of course, that's salting the bird's tail if you don't have access to a scope. But it probably would be worth your time to hunt one up because you'll know immediately if you need to deal with a bouncing switch and you'll be able to get some timing measurements with virtually no work.
     
  5. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    "Contact bounce" is going to be fun for you to deal with.
    Have a look at this article:
    http://www.ganssle.com/debouncing.htm

    This is the kind of project that begs for a microcontroller.
     
Loading...