Shop OBEX P1 Docs P2 Docs Learn Events
IR emitter/detector pair behaving badly — Parallax Forums

IR emitter/detector pair behaving badly

mparkmpark Posts: 1,305
edited 2009-07-18 15:18 in Propeller 1
I am trying to use an infrared emitter and detector I got from Radio Shack (part 276-142) as an electric eye, just to detect when an object passes between them.

The emitter is hooked up to 3.3V through a 100 ohm resistor.

The detector is connected between P9 on the Prop and ground. There's a 5k pot between P9 and 3.3V.

The emitter and detector are pointed toward each other.

I run a simple loop like
repeat
  debug.dec( ina[noparse][[/noparse]9] )


As I adjust the pot the output goes from 1111... to 101100... to 00000. When I put my hand between the emitter and the detector, the output is 11111... So far, so good.

Now, if I add snd.start(15) before the loop (snd being a "NS_sound_drv_052_11khz_16bit" obj), the loop prints 11111... whether my hand is in the way or not. I have to readjust the pot to get it back to 000000...

Why should starting the sound driver change what I see on P9?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-02-19 17:44
    Does the output from the sound driver connect to an audio amp that draws appreciable current? It sounds like Vss to the phototransistor may be biased upwards a bit when you start the sound driver. How is this connection made? Directly back to the power supply or through other circuitry? Another possibility is that the IRED circuit is getting less voltage with the sound driver on. In any event, I'd put my money on a power supply issue.

    -Phil
  • mparkmpark Posts: 1,305
    edited 2009-02-19 19:26
    The sound output pin just goes to a little RC filter; the filtered output goes to the audio input of my tv.
    I also have the tv driver going. I'm just using the protoboard's power supply.
  • mparkmpark Posts: 1,305
    edited 2009-02-22 08:21
    Here's my detector circuit:
    3.3V
      │
      ┐ 0-5k
        │
        ├──── P9
       
        │
       gnd
    
    



    Without the sound driver, I measure 1.2V at P9. With the sound driver, it jumps to 1.6V. Earlier I thought it was up to 1.7 or 1.8 but something changed (maybe the ambient light?). Anyway, I don't understand what's happening. Help!
  • parskoparsko Posts: 501
    edited 2009-02-22 17:08
    Mpark,

    I just went through this with my coil winder. I was using the same emitter detector from Radio Shack. I would suggest you may need some hysteresis. Try a timer 555 and use it as a Schmitt trigger on the detector (3.3->10k->detector->ground, input to 555 is between 10k->detector). Cured all my problems.

    -Parsko

    Post Edited (parsko) : 2/22/2009 10:03:50 PM GMT
  • TreeLabTreeLab Posts: 138
    edited 2009-02-22 19:56
    If I understand correctly, having a higher voltage means lower light levels on the detector, which may mean that the emitter is starved for supply current.

    This may be a long shot, but if your power supply on the 3.3V side is marginal, perhaps running an extra cog can cause it to droop.

    Trying loading your prop even more (as a stress test) or toughing up the supply. I ran my pairs off the 5 V supply, and put a voltage divider on the emitter output to connect the detector at a safe running voltage swing for the prop input terminal.

    Cheers!
    Paul Rowntree
  • mparkmpark Posts: 1,305
    edited 2009-02-23 04:51
    Parsko -- What symptoms did you observe? I have no idea how to use a 555 as a Schmitt trigger, but wasn't there a thread here on faking a Schmitt trigger with some I/O pin cleverness?

    Paul -- I don't see the 3.3V supply dropping significantly with the sound cog running but maybe I'll throw a few more cogs at it and see what happens.

    PJ -- I think you're doing something a lot more advanced than the brain-dead electric eye I'm trying to make.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-02-23 05:32
    mpark,

    Is the IRED too far removed physically to drive it from the Propeller? If not, I have an idea...

    -Phil
  • mparkmpark Posts: 1,305
    edited 2009-02-23 06:04
    The IR emitter and detector are connected to the protoboard by about 2' of ribbon cable (each). The devices themselves are mounted about a foot apart.

    All ideas welcome!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-02-23 06:39
    My thought was to modulate the IRED so you can detect the modulation through an AC-coupled phototransistor circuit:

    attachment.php?attachmentid=58876

    This would make it insensitive to ambient light, temperature, and Vdd variations. You will have to experiment with the component values, but they shouldn't be critical. Both resistors in the input voltage divider should be the same, though, probably 22K or higher. A cap around 0.1uF should be fine. The pullup on the phototransistor needn't be a pot, since the input voltage threshold level is fixed and set on the other side of the cap.

    From a programming standpoint, what you want to do is toggle the IRED rapidly on and off at around 10KHz. Not too fast, or the phototransistor won't keep up. (If it still doesn't keep up, there's another trick to help speed it up, but we'll cross that bridge when we get to it.) This can be done in your program or by a counter output. After each toggle, wait a couple microseconds, then add one to a counter if the detector input agrees with the toggle output; zero, if not. Do this maybe 64 times. Then, see if the the count was at least 48, say. If so, the beam was not broken. When the beam is broken, the count should be around 32 — half the number of toggles.

    -Phil

    _
    460 x 260 - 2K
  • parskoparsko Posts: 501
    edited 2009-02-23 14:32
    Mpark,

    I simply had a pin watching the state of the output from misc. circuits I was trying (I really wanted to make my own Schmitt trigger). In the end, I kept noticing that my "odometer" would increase in count WAY faster than it should, at times. This ended up being where the threshold of the pin was (~1.65V). Around this level, this "runaway" counting would occur.

    I ended up adding a 555 in Schmitt mode, seen here:
    www.kpsec.freeuk.com/555timer.htm
    bottom of the page.

    It worked like a charm. Prior to this, I would get erratic behavior. Ambient lights on and around my desk were messing with my handmade circuits (they would work brilliantly when I "shaded" them).

    I used a 330ohm resistor for my IR emmitter. I also noticed that they had to be pointed pretty good at one another. You may have a problem with your 1 foot distance. It may make your life easier to use the "official' IR reciever, which is designed to work more robustly, should you not get this all going. That one can be found here:
    www.parallax.com/Store/Sensors/ColorLight/tabid/175/CategoryID/50/List/0/Level/a/ProductID/177/Default.aspx?SortField=ProductName%2cProductName

    Does that sound like your problem?

    -Parsko
  • mparkmpark Posts: 1,305
    edited 2009-02-23 16:03
    Thanks Phil and Parsko. Right now I'm most interested in understanding why the voltage at P9 goes up when the sound cog is running. That just seems wrong.
  • parskoparsko Posts: 501
    edited 2009-02-23 16:06
    What pin is the sound running from? If it is the pin next to Pin 9 that is looking at your detector, that might have something to do with it. If it isn't, I'm stumped at the moment.

    -Parsko
  • mparkmpark Posts: 1,305
    edited 2009-02-23 21:04
    The sound is on P15. I moved the detector to P4 and saw the same strangeness there.
  • william chanwilliam chan Posts: 1,326
    edited 2009-02-24 12:29
    Your detector circuit's power supply cannot be connected directly to the common 3.3v rail.
    It must be connected through a RC filter.
    Read Sharp IR detector datasheets which indicate the importance of this filter.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • mparkmpark Posts: 1,305
    edited 2009-07-18 15:18
    This went on the back burner for a while but recently moved to the front.

    I've given up trying to figure out why turning on the sound driver changed the voltage at P9. There were too many other weird things going on, all of which disappeared as soon as I attached a scope. That's just unfair.

    But I finally got around to trying Parsko's 555 Schmitt trigger suggestion and it worked! I now have a reliable electric eye. So, thanks, Parsko and everyone else who replied.
Sign In or Register to comment.