Mad Labs
Dedicated to fun science!


Stamp Velocity Timer


I recently purchased a Basic Stamp SX. A Basic Stamp is a micro-controller, a small computer that can be programmed using the BASIC programming language. For it's first project, I decided to make a velocity timer for my Coil gun. For more information about Basic Stamps, click HERE.

The first problem that confronted me was the fact that the 2SX doesn't have an event timer. I could have built a 555 timer running at 1kHz and gone that route, but I am lazy and didn't feel like mucking with extra hardware. Looking through the Stamp command reference, I noticed the "PULSIN" command. This command measures the length of a single pulse sent to one of the inputs. I set up a single photgate so that it sends a pulse to the Stamp for as long as it is blocked by the projectile. Since we know the length of the projectile and the length of the pulse, we can now calculate the velocity. Simple!

To verify the accuracy, I set up a 68mm plastic tube, and used our reliable friend gravity to drop a projectile down the tube. The average of ten drops was 0.1m/s slower than calculated. Seeing as there must have been some drag from projectile/tube contact, this is pretty darn close! More importantly to me, the gravity drops were all within 0.2m/s of each other, indicating that the system is at least consistent. If the timer is a few tenths of a m/s incorrect, I could care less. I am not as interested in knowing the precise speed as I am having a reliable benchmark to test the CG.

The cool thing about using a Stamp instead of a logic circuit is that one can easily add "features". I got a LCD display, and at this point the user can select the length of the projectile and then go to firing mode using two push button switches. In the works are all sorts of features, including a "test mode" that will count and average 10 shots, a shot counter to keep track of total shots during a session and total shots ever fired, max. speed record and so on.

Here is the circuit employed. The input driver section of the circuit is the same as the SCR driver circuit from the Magnetic Gun Club. Works fine. I am going to play with using a comparator to speed it up, but since it agrees with gravity right now, well, if it ain't broke, don't fix it...

All power is pulled from the Stamp board, not the coil gun. Almost any photo detectors/emitters can be used, but you may have to adjust the resistor values. Practically any NPN transistor will work for Q1. R7 is there to keep pins 2 and 3 pulled high, this is because I used a built in STAMP command to that sets pins 0-3 as inputs. Amazingly simple, considering what it does. The code for it is pretty simple too.

'$BS2SX Velocity Timer for the Basic Stamp, Jonathan Peakall, 2002

'------------------------------------------------------------
Here are the LCD declarations

n9600 con $40f0 'baud rate
I con 254 'prefix value for LCD addresses
CLR con 1 'LCD clear command
line2 con 192 'Address for 1st char of second line
Pause 1000 'To let LCD wake up
SEROUT 15,n9600,[I,CLR] 'Clears LCD
'------------------------------------------------------------
'VARS

SwIn VAR InA '|Sets pins 0-4 for switches
sw VAR Nib
x VAR Nib
lengthSet VAR BIT
currentLength VAR BYTE 'Max projectile length is 50mm
shot VAR BIT
velocity VAR WORD
time VAR WORD
factor VAR WORD
'------------------------------------------------------------ '
CONs and set VARS

currentLength=5 'Default projectile length in mm
'------------------------------------------------------------
Main:
IF lengthSet = 0 THEN SetLength
GOTO Main

SetLength: 'Allows user to change projectile length
SEROUT 15,n9600,[I,CLR]
PAUSE 1 'these pauses let the LCD display correctly
SEROUT 15,n9600,["Current Length"]
PAUSE 1
SEROUT 15,n9600,[I,line2]
PAUSE 1 SEROUT 15,n9600,[dec currentLength,"mm"]
PAUSE 5
GOSUB CheckSwitches 'See if user changes or accepts length
pause 5
IF sw=%0010 THEN AddLength
IF sw=%0001 THEN LengthSelected
goto SetLength

AddLength: 'Increments projectile length in 5mm segments
currentLength=currentLength+5
IF currentLength > 50 THEN ResetLength
GOTO SetLength

LengthSelected: 'User has chosen projectile length
lengthSet=1
GOTO GetVelocity

ResetLength: 'Resets currentLength if over 50mm
currentLength=5
GOTO SetLength

GetVelocity 'Gets and displays velocity
IF shot = 0 THEN FirstShot
PULSIN 14, 1, time IF time = 0 THEN GetVelocity
velocity=(factor/time*10)+(factor//time*10/time)
SEROUT 15,n9600,[I,CLR]
PAUSE 1
SEROUT 15,n9600,["C:",dec Time," L:",dec currentLength,"mm"]
PAUSE 1
SEROUT 15,n9600,[I,line2]
PAUSE 1
SEROUT 15,n9600,["Vel: ",dec velocity/10,".",dec1 velocity," m/s"]
PAUSE 1
GOTO GetVelocity

FirstShot: 'So the screen isn't blank before the first use
factor = currentLength*1250
shot = 1 SEROUT 15,n9600,[I,CLR]
PAUSE 1 SEROUT 15,n9600,["Ready to fire."]
PAUSE 1
GOTO GetVelocity

CheckSwitches: 'Checks for user input and debounces
sw=%1111
FOR x= 1 TO 10
sw=sw&~SwIn
PAUSE 5
NEXT
RETURN

This is my first Stamp project, and my programming is 15 years out of date, so I am sure there are many places the code could be improved. Any suggestions, comments or questions E-MAIL me.

Page Created: 07/05/02
Last Modified: 07/05/02



Home

About Us

Tesla Coils

The Hydrogen Fuel Cell
Robot Project Chronicles


Classes
- Mini Sumobots

Miscellaneous Experiments
- Acoustic Laser
- Coil Gun/Gauss Cannon

Miscellaneous High Voltage
- Jacobs Ladder
- Marx Generator
- Lightning Pendulum
- Flyback Fun

Electronics Stuff
- Velocity Indicator
- Atomic Nixie Clock
- IR Remote Module
- Sharp GP2D12 Sensor

Electricity & Magnetism
- Mag&Elec 101
- Worlds Easiest Motor
- Slow Motion Magnets
- Galvanometer
- L.E.D. Blinker
- Electromagnet
- Simple Speaker
- Simple Oscilloscope
- Simple Switch



Copyright Mad Labs.  All rights reserved.