Basic Stamp Speed Trap
rifleman4040
Posts: 28
Hello everyone. I was thinking about constructing a speed trap with the basic stamp to check the speed of motor vehicles. It would be constructed along the lines of using 2 laser modules paired with photo detectors(would this be the right component?). The laser/photo detector pairs would be placed an exact measured distance apart. From the time the vehicle broke the first beam to when the time the vehicle broke the second beam could then be measured, and then the exact speed could be calculated. Now, I have a few questions if I may.
Would the PULSIN command be the direction I should go with this?
What sensor should I use for the laser? I was thinking about using a visible light red laser for aiming purposes.
The BSII can power a laser module, because the laser is nothing more than a diode, right (5mW laser) ?
Any help/suggestions/advice would be greatly appreciated.
Thanks a lot.
·
Would the PULSIN command be the direction I should go with this?
What sensor should I use for the laser? I was thinking about using a visible light red laser for aiming purposes.
The BSII can power a laser module, because the laser is nothing more than a diode, right (5mW laser) ?
Any help/suggestions/advice would be greatly appreciated.
Thanks a lot.
·
Comments
-Phil
DO
LOOP UNTIL IN3 = 0
DO
PAUSE 1
LOOP UNTIL IN4 = 0
LOOP
With this I can be accurate to the millisecond, right? So, it would be more accurate than with the 555 timer setup. With the PULSIN command, I should be able to get down to 2us increments I thought, so could be even more accurate.·Thanks again for your help guys, but still lookin for info on the PULSIN command being used to tell me the time between pulses between two sensors.
·
Now, all of that said, the second loop is deterministic and can be calibrated, leaving only the indeterminacy of the first loop to deal with. The farther apart you place your two lasers, the less of an effect this will have on the accuracy of your system.
You are right about being more accurate than a 555 timer, though. The Stamp timing is controlled by a resonator, which is far more accurate — and less temperature-sensitive — than the RC timing of a 555. This is especially critical when you're working outdoors.
-Phil
So, you told me why it won't work, and that was my best shot at it. So, what would be the most accurate way to make it work?
I need that initial do loop to continually monitor the first sensor to start the time, don't I? If not, how can I work around this?
I would like to know if and how I can use the PULSIN command can be used to measure the time between the high to low change of state between two separate pins.
You haven't noted·the distance between·these detectors nor the range of speeds involved.
Post Edit -- sp.
Post Edited (PJ Allen) : 6/22/2008 4:35:39 PM GMT
Post Edit --
In PBASIC Help we read:
Quick Facts
PULSIN will wait for the desired pulse, for up to the maximum pulse width it can measure, shown in the table above. If it sees the desired pulse it measures the time until the end of the pulse and stores the result in Variable. If it never sees the start of the pulse, or the pulse is too long (greater than the Maximum Pulse Width shown above), PULSIN "times out" and store 0 in Variable. This operation keeps your program from locking-up should the desired pulse never occur.
__________________
It won't wait indefinitely for a PULSIN cycle to occur.· So, I would have a leading trigger (another detector), IF·trigger_pin = 1 THEN GOTO PULSIN routine.
Post Post Edit -- I think that you will have to·situate your detectors closer together, given the 131.07ms max pulse time limitation.· (A car travelling at 50mph·will transit 10 ft. in ____ sec.)
Post Edited (PJ Allen) : 6/22/2008 5:24:19 PM GMT
Another thing that gets me, is if that the detectors are much closer together, they may both be activated at the same time depending on the length of the vehicle. You see, both detectors are HIGH when the beams are on, when the speed trap is set. When the beams are broken, the detectors give a low to the pins. So, will that "restricted combination" cause problems for the setup? Or, would the STAMP mind having two lows for the pulsin command (KEEP STATE) until the HIGH LOW combination could be given?
Isn't there a way to extend the time the PULSOUT can measure by increasing the timeout time?
It seems to me that since the PULSIN event/cycle·has to begin within 130msec of the command then you need a detector ahead of the timing pair to tell the Stamp, "Hey, get ready, here it comes!"
The "time-out" time is fixed, there's no programming it differently.
A·possible "restricted state" conflict.· True.· The solution would be to run each detector output into a non-retriggerable one-shot, and then to the SR Latch (the circuit diagram.) When the detector becomes active, it would trigger the one-shot, which would emit a pulse (very brief, a tick, 1usec) which would·"tap" the latch and would be unable to do so again till the detector went inactive.
50 mph, 10 ft. transit = 137msec (out of range)
200 mph, 10ft. transit = 34msec
Post Edit -- I didn't know what your detector inactive state was/is.· I showed an SR Latch with NOR gates and·its restricted state is 1 & 1.· An SR Latch can also be made with NAND gates and·its restricted state is·0 & 0.· "Wiki" that.· [noparse][[/noparse]RS, SR, 6 of the one, a half dozen of the other.]
Here's an excellent (dual)·non-retriggerable one-shot -- http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/MM74HC221A.pdf·
It has Q and /Q outputs (for a HI-going pulse or a LO-going pulse, respectively.)
Post Edited (PJ Allen) : 6/23/2008 1:29:35 PM GMT
15
__________
t (.000002)
_____________________ = MPH
11
Where "t" equals the PULSIN count. Is there any reasonable way to program this into the stamp,
or where would it just be better to do the calculations myself after the time is recorded by the device?
Post Edited (rifleman4040) : 6/25/2008 5:01:18 AM GMT
Thanks,
Phil
So, it is 15 divided by the quantity t * .000002 , and then all of that divided by 11 to equal miles per hour. Someone can check my math if they like. Basically, I'm placing the detectors 2 feet apart, as this will be more than enough space between them with 2us intervals. So, I took 2ft / t(.000002) * 3600 / 5280, and simplified it as much as I could. Again, "t" is my PULSIN count, and MPH is miles per hour. Basically, I want the program to put my PULSIN count into that equation to display MPH. You think you can actually put that into the BS II and get accurate results?
mph = fps * 0.6818
And since the detectors are 2 feet apart and the count is in units of 2 microseconds, that becomes,
mph = 68180 / t ' t from BS2 COUNT command
You said you expect a speed range of 50 to 200 mph, so t will range from 1363*2 uS down to 340*2 uS.
But 68180 is too large a number for the Stamp. Here are a couple of formulae that adjust the magnitude so it will fit:
or
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
If you could tap into it, get the distance change in a preset time you could effectively create a 'handheld' unit to do the same thing.
It would be really cool to build it into it's existing housing, maybe put new electronics in battery compartment, and power it externally.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Smile ... It increases your face value!
Post Edited (MrBi11) : 2/8/2009 12:59:13 AM GMT
Weird readings...?
Sketch out a schematic and post that and upload your program as an attachment and we can talk.
·
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=296-9187-5-ND Monostable Multivibrator
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=MM74HC00N-ND Quad 2-input NAND Gate, used for SR latch to use one pin for pulsin
The one shot is placed on each input of the SR latch.
Here is the basic program.
' {$STAMP BS2}
' {$PBASIC 2.0}
t VAR Word
mph VAR Word
SPEED_TRAP:
Trigger:
IF IN1 = 0 THEN Main
GOTO Trigger
Main :
PULSIN 0, 1, t
IF t = 0 THEN Trigger
mph = (34090 / t * 10) + (34090 // t * 10 + (t/2) / t) * 2
DEBUG CR, DEC mph/10, ".", DEC1 mph, " MPH" ' units of 0.2 mph
GOTO Trigger
Otherwise, get busy with good ol' MS Paint (which can take a while.)
For the time being, I'd just DEBUG the PULSIN time results and worry about the mph calc later.
N.B. -- You are aware that PBASIC doesn't·process parentheses, order of·operations,·etc. like in algebra class, right?··It just processes in order, left to right,·without regard to bracketing.· It lets you place them, alright, but it ignores them just the same.·
So, writing
mph = (34090 / t * 10) + (34090 // t * 10 + (t/2) / t) * 2
works out as:
mph = 34090 / t * 10 + 34090 // t * 10 + t / 2 / t * 2
Post Edit -- The BS2 does, in fact, handle parentheses, but the BS1 does not.
Post Edited (PJ Allen) : 3/11/2009 1:51:20 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
Reading back, there was also the matter of the extra (3rd) sensor which would prompt the Stamp·for an imminent·"pulsin event" (remember the "130msec rule").
Here is the basic program for the trigger circuit.
And I was getting pulsin times, they were just erratic.
Post Edited (rifleman4040) : 2/11/2009 12:21:54 AM GMT