Shop OBEX P1 Docs P2 Docs Learn Events
Chrono and IR sensors — Parallax Forums

Chrono and IR sensors

gth629egth629e Posts: 40
edited 2009-03-14 04:45 in BASIC Stamp
Hello all,

Let me give you a little background. I am trying to make a chrono for detecting high speed projectiles. I composed the code to do so using the RCTime to gain the highest resolution of 2uS that is possible on my BS2. All that went well as I was only using 2 push buttons to do all the testing as my IR LED and detectors had not arrived from parallax yet. When the kits arrived, made the circuit as suggested on in the manual and BOE BOT book in chapter 8. The IR sensor is hooked up correctly with the output in series with a 220 ohm resistor to pin 0. The LED is series with a 2kohm resistor to pin 7 (also tried 470ohm and 1k ohm). Here is the code I am using to test a simple break between the LED and detector.

' {$STAMP BS2}
' {$PBASIC 2.5}


IR_detect  VAR  Bit
LOW 7

LOOP:

  PAUSE 50
  FREQOUT 7, 1, 38500
  IR_detect = IN0
  IF IR_detect = 0 THEN unbroken

    ' Make sure to add six spaces to the debug statement
    ' below.  That way both debug statements will have the
    ' same number of spaces for a better display.

    DEBUG HOME, "Beam is broken; object detected.      "
    GOTO LOOP

  unbroken:
    DEBUG HOME, "Beam is unbroken; object not detected."
    GOTO LOOP





I am having real problems with getting results with this setup. It is very buggy constantly switching between broken and unbroken states (view code). If I do get it barely working, I have to cover the detector for quite some time before the "Beam is broken; object detected" message appears. In total darkness, it doesn't want to work at all. So that would lead me to believe the LED is not working. I have 6 brand new LED's, the circuit and polarity of the LED's are correct. tested the detector by writing some simple code and using my TV remote and it did pick up.

Is there anything I can do different or is just how these things react?
Any assistance would be grateful.


I noticed in this code that was provided that the FREQOUT command would stop "emmiting" as soon as it proceeded to the next line of code. Wouldn't this give you an error? This is the example code given by parallax so I am a bit confused.

Thanks in advance.


Regards,

Comments

  • Larry~Larry~ Posts: 242
    edited 2009-03-05 21:14
    search for this post in stamps in class area

    Interested a little more information on the BS2 freqout generating the 38.5kHz harmonic

    also look up a post on speed trap in stamp area about 2 weeks ago
  • ercoerco Posts: 20,256
    edited 2009-03-05 21:30
    I wouldn't use modulated IR for this high-speed app. There are many delays associated with that IR sensor that would ruin any attempts at accurate timing. I also don't think RC time is your best bet for accuracy. Not sure if you are making a trap with 2 sensors a fixed distance apart, or using one sensor and measuring the blocked time for a known length projectile. I would suggest you use one or two make/break light beam (an IR LED shining DC onto a phototransistor) and feed that input into the Stamp. If you use just one sensor, you can use the PULSIN command to measure the blocked time with decent accuracy. The BS2 is pretty slow, a BS2-SX or BS2P is faster and can measure with greater resolution.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • gth629egth629e Posts: 40
    edited 2009-03-06 02:54
    Thanks for the ideas on searching for those terms. I did a search for IR sensors and such but did not find much.

    Erco,

    I am using 2 sensors set about 4 inches apart currently. The stamps seem to be quite reliable in this setup. Once the first sensor is triggered, the rctime starts and counts the time until trigger two goes high. I will post the code for that if you like. I am currently using an IR LED and photo transistor, sorry for the confusion.

    I am using 350-00014 product from parallax. I thought that was a photo transistor at least. I does send a high signal to the stamp upon not receiving an IR source at around 38 khz.

    The problem I am having is constant 38500 hz signal and being able to detect a triggered switch. I could try polling I guess but am unsure. I also though about using my PWMpal but it only produces a 20 khz max.

    How would you generate the freqout frequency for the led and also use the pulsin command to monitor. Sorry for any noob questions.

    Regards
  • ercoerco Posts: 20,256
    edited 2009-03-06 17:16
    Phototransistors come in clear cases, sometimes looking just like clear LEDs with 2 leads. Sometimes they'll come in a metal transistor-looking package with a clear lens and 3 leads. Phototransistors are simple discrete devices with instant on/off characteristics, ideal for timing applications, but they require a bit of external support circuitry.

    38 kHz modules are usually rectangular with a small dome lens on one side (sometimes covered by an X) and come in either black or metal covered. More importantly, the 38 kHz modules have lots of internal circuitry that filters out most non-38 kHz signals. That circuitry has a response delay associated with it, which is the only reason why the Parallax object detection method works.·Your code above (freqout 7,1,38500) sends a pulse train out, stops sending it, and after a brief execution delay, starts looking if the sensor sees the pulse. In reality, the pulse train is long gone at the speed of light, but due to the sensor's circuitry delay characteristics, it still shows active low for a brief detectable period. There is also a delay when it first goes low. Those delays will vary from sensor to sensor, so you may not get accurate timing results·using ·2 different sensors.

    Whatcha got?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."

    Post Edited (erco) : 3/6/2009 8:07:56 PM GMT
  • JonathanJonathan Posts: 1,023
    edited 2009-03-06 20:42
    GTH,

    In terms of providing a constant 38.5kHz signal, look up the 555 timer chip. Very simple to use, and all parts needed can be had from Radio Shack. The Stamp simply can't do two things at once. However, it isn't as easy to do the freq. sweep trick for distance detection. You could probably use a digital pot to do that along with the 555 timer.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • gth629egth629e Posts: 40
    edited 2009-03-07 00:50
    So my terminology is wrong but I think I had the right ideas. I wanted to use the ~40 Khz module to filter sunlight to make the system more robust. However in doing so, you need to create the ~40 khz which uses resources. I did finally get my circuit working. The problem was actually with the intensity of the IR led. The detector was picking the IR across the room, bouncing off walls etc. All I really needed was a spacing of about 1 inch. I ended up putting a 22 Kohm resistor and achieved decent performance. The problem is that, as you said, it is very inconsistent and for the velocity and spacing I am using is unacceptable.

    What I really need is just a n optocoupler type steup. I can recess the photo transistor to protect it from ambient light. You mentioned I would need external circuitry. Would something like this setup work? ( jpeg attached)

    Were can you photo transistors with the three connections and what is the difference between them and the ones that look like led's. I imagine they have internal circuitry like a switching transistor or something.

    How about the photo emitter and transistor set?
    952 x 796 - 45K
  • ercoerco Posts: 20,256
    edited 2009-03-07 01:09
    Your circuit is on the right track. I use Radio Shack phototransistors & IR LEDs with good results for these types of light sensors.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • gth629egth629e Posts: 40
    edited 2009-03-14 04:45
    So, I tried the circuit I posted but to no avail. I am using the 2 lead photo transistor and the IR led from the shack and also their small signal NPN transistor. Any assistance on a simple circuit to test the photo transistor with the bs2?
Sign In or Register to comment.