How to measure time with the Basic Stamp 2
chechio
Posts: 2
Basically I am using two light sensors that are separated by 12 inches to measure how fast a toy car is going.
When the car passes the first light sensor, I want the clock to start keeping track of time and when the car passes the 2nd sensor, I want it to calculate the the time that has passed.
I was wondering how you use the resonator in the BASIC Stamp 2 or if I have to buy other parts to keep time. It doesn't have to be very accurate since the time between sensors is very small.
Post Edited (chechio) : 10/1/2008 12:11:27 AM GMT
When the car passes the first light sensor, I want the clock to start keeping track of time and when the car passes the 2nd sensor, I want it to calculate the the time that has passed.
I was wondering how you use the resonator in the BASIC Stamp 2 or if I have to buy other parts to keep time. It doesn't have to be very accurate since the time between sensors is very small.
Post Edited (chechio) : 10/1/2008 12:11:27 AM GMT
Comments
You might also look at the PULSIN statement which can give you very accurate pulse width times. You'll need to use the two light sensors to make a pulse, on when the car passes the 1st sensor and off when it passes the 2nd sensor. It's pretty easy to do using a simple set-reset flip-flop. The output of the 1st sensor "sets" the flipflop and the output of the 2nd sensor "resets" the flipflop. The output of the flipflop goes to the Stamp I/O pin that does the PULSIN timing. Google "wiki flipflop" or "wiki set reset flipflop" for a discussion. You can use a quad NAND gate to implement this (74HC00).
I'm actually making a 5x5 grid of lights, 5 going across and 5 vertical and another grid of just 5 horizontal lights about a foot behind the first grid. I'm trying to make a device that detects if a pitch in baseball (with a larger ball) is either a strike or a ball and how fast it is going. The first grid is to detect if the pitch is a ball or a strike. And I want to record the time it takes from getting from the first grid to the second grid to get the speed. Does that make sense? I used the toy car example cuz that is what I am basically doing, the time between two sensors.
After I looked at the circuit diagram of the quad NOR IC of an RS flipflop in the other forum, I have many sensors that can start the detector and many that can stop detector. Is there a way I can still use just one RS flipflop? Or what the best way to find the time between grids?
I'm not a programmer so I'm not quite clear on using the pulse width? I looked at the sample of PWM on emesystems.com but i didn't really understand it. Can you give me a sample code.
Thanks
If you can get a reliable signal that's true when the ball is crossing the first grid and another reliable signal that's true when the ball is crossing the second grid, you can use those signals for the set/reset of a single RS flipflop and use the output of that flipflop for a Stamp pulse input which can be measured to an accuracy of a few microseconds with the PULSIN statement. The leading edge of the 1st grid's pulse will set the flipflop and be used to start the timing of the PULSIN statement. The leading edge of the 2nd grid's pulse will reset the flipflop and be used to stop the timing and report the difference between the two leading edges.
The PWM statement is something completely different and is normally used to produce a slowly changing or specific program defined analog voltage. Look at the description of PULSIN.
Jesse,
Please read my previous message.