Shop OBEX P1 Docs P2 Docs Learn Events
The Mad Scientist's Chronograph Needs your help Measuring time — Parallax Forums

The Mad Scientist's Chronograph Needs your help Measuring time

PromagicPromagic Posts: 17
edited 2009-03-06 20:12 in BASIC Stamp
I was wondering just how fast my BB gun fired at some of my homemade armor for a competition at mech-warfare.com
6 hours later I built a contraption that uses 2 bump switches 1 foot apart.

Formula:
T2 - T1 = Total time it takes to go from one bump switch to another
(Distance in feet) / (Total Time) = fps

Example:
19.29975 - 19.28540· = ·0.01435 seconds OR 14ms
3 feet / 0.01435· = 209fps smilewinkgrin.gif

Hardware.....Check!
Electronics...Check!
Software..... Che...Wait, what?!?

Do you know of a some code that can help me solve my problem?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
···· -Devin


"I can only ask every question once."

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-03-05 05:05
    Try poking around in this thread:

    http://forums.parallax.com/showthread.php?p=732526
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-03-05 05:53
    Hi Devin,

    If you are using PULSIN to measure the time on a BS2, then the result in in units of 2 microseconds. For example, 14.35 milliseconds is 14350 microseconds, but the result returned by PULSIN will be b2b=7175 (µs*2). Then if distance is 3 feet (or was it 1 foot?), the formula to convert to feet per second is
    3 * 1000000 / (b2b * 2) = 1500000 / b2b
    Which includes the factor of 1000000 for microseconds and the factor of 2 for the PULSIN units. For example, 1500000 / 7175 = 209 feet per second
    The math has a variable in the denominator, and on the Stamp, a binary division loop is the best way to deal with this, as follows:
    b2b VAR Word  '  transit time in units of 2 microseconds
    Fx VAR Word    ' calculation variable for division loop 
    Nx VAR Word    ' dividend for division loop
    J VAR Nib   ' index for division loop
    DO
      PULSIN 0, 1, b2b   ' b2b is pulse width in units of 2 µs
      IF b2b THEN  ' skip calculation if no pulse
        Nx = 1500
         '---------binary division loop-----------
         FOR J=15 TO 0               ' 16 bits 
           Nx=Nx // b2b << 1                   ' remainder*2 
           Fx.bit0(J)=Nx / b2b               ' next bit 
         NEXT
        '----------------------------------------
        Fx = Fx**10000                  ' renormalize to make a decimal fraction
        DEBUG CR,"Velocity = ", DEC Fx/10, ".", DEC1 Fx, "ft/s"      ' e.g. 209.0 ft/s
      ENDIF
    LOOP  ' try again
    END
    


    The above works so long as the velocity is less than 1000 feet per second.

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

    Post Edited (Tracy Allen) : 3/6/2009 8:05:48 PM GMT
  • PromagicPromagic Posts: 17
    edited 2009-03-06 18:39
    Thanks for the insightful code Tracy! I only found one error and by changing all F's·to Fx's that seemed to solve the problem.
    Ok how am·I supposed to use one PULSOUT command with two push-buttons? Do·I wire them to the same pin? I tapped one of the push-buttons and it have me a reading of about 200 ft/s, which was awesome but how did it figure that out with only one tap?
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    b2b VAR Word  '  transit time in units of 2 microseconds
    Fx VAR Word    ' calculation variable for division loop
    Nx VAR Word    ' dividend for division loop
    J VAR Nib   ' index for division loop
     
    DO
    DEBUG HOME
    DEBUG ? IN8     'on one side
    DEBUG ? IN9     'on the other side of a foot
    
    IF (IN8 = 0)THEN
       HIGH 11              'light LED
     ELSEIF (IN9 = 0) THEN
       HIGH 10              'light other LED
    ENDIF
     
     
    PULSIN 8, 1, b2b   ' b2b is pulse width in units of 2 µs            changed pin 0 to pin 8
      IF b2b THEN  ' skip calculation if no pulse
        Nx = 1500
         '---------binary division loop-----------
         FOR J=15 TO 0               ' 16 bits
           Nx=Nx // b2b << 1                   ' remainder*2
           Fx.BIT0(J)=Nx / b2b               ' next bit
         NEXT
        '----------------------------------------
        Fx = Fx**10000                  ' renormalize to make a decimal fraction
        DEBUG CR,"Velocity = ", DEC Fx/10, ".", DEC1 Fx, "ft/s"      ' e.g. 209.0 ft/s
      ENDIF
    LOOP
    


    My contraption at the moment is only 1' apart at the moment but·I can change it whenever·I want.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ···· -Devin


    "I can only ask every question once."
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-03-06 20:12
    If there are two different switches, then tie them to the inputs of a flip-flop circuit. One switch sets it and the second one resets it, so its output is one clean pulse for the duration of the transit time. Look at the thread SLRM pointed out. Poke around down to a schematic posted by PJ Allen.

    PULSIN 8, 1, b2b ' <--- note that this command detects the duration of a 010 pulse

    What exactly is a "bump switch" and how is that set up to detect the BB?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.