Shop OBEX P1 Docs P2 Docs Learn Events
IR detect — Parallax Forums

IR detect

jonduncanjonduncan Posts: 40
edited 2007-04-05 10:12 in Propeller 1
how do you do a simple ir detect with a prop with a freqout and a ir detect. How do you detect objects at various distances, like with the bs2 you use different frequencies?·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-31 23:22
    Look at the IR routines in BOE-BOT Basic in this thread: http://forums.parallax.com/showthread.php?p=635533.

    In particular, look at the routine "pulseOut" around line 1460 and the Basic function IRZONE around line 500.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-04-01 00:26
    With the Propeller you have another option for inferring distance: duty-cycle sweeping. When pulsed with a 50% duty-cycle, the IRED is transmitting at maximum modulated power. But when the duty-cycle approaches 0% or 100%, the modulated power output approaches zero. The ability of the detector to "see" an object varies with the returning signal strength, which is directly proprotional to both the IRED's power output and the object's IR reflectivity, and inversely proportional to the square of the out-and-back distance. By sweeping the duty cycle from 0% to 50%, you should be able to get a fair approximation of an object's relative distance. Also, with the Propeller, you can transmit and receive simultaneously, rather than having to catch the sensor's residual output after the the IRED is turned off.

    Incidentally, one problem I've encountered with sweeping the IRED's modulation frequency is that the detectors have a rather short demodulation time constant. What happens at an off-center frequency is that a beat phenomenon occurs, wherein the output can be high or low, depending on when you read it.

    Given the option to sweep the power, rather than the frequency, I think I'd pick the power approach.

    -Phil
  • edited 2007-04-01 19:41
    jonduncan

    There's an IR detection object in this package that you can get about 40 zones out of (instead of the 5 you can get with the Boe-Bot).

    http://forums.parallax.com/showthread.php?p=641644

    Andy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 4/2/2007 3:31:57 AM GMT
  • edited 2007-04-01 19:44
    Phil, that's really a great idea! I'll give it a try.

    Thanks, Andy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
  • edited 2007-04-02 03:25
    Phil,

    Before going too far down the duty cycle sweeping path, I remembered some problems I had with·that approach with the SX chip.· The PNA4602 (or maybe it was one of its clones) would latch low after the duty cycles was either swept·above 80%·or below 20%.·

    So, I instead·left the frequency at 38 kHz, 50% with one counter module on the IR LED's anode and then set the other counter module to duty mode and swept it from 255/256 to 0/256 on the cathode.· Now, the measurement takes a fraction of the time, has six times the resolution, and·a lot less noise.·

    Although it still needs a lot of refinement, the test code I used is attached.

    Andy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 4/2/2007 3:30:25 AM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-04-02 05:37
    Andy,

    Ahh, I really like that approach! It's the Propeller way! (And way easier than PWM wrangling.)

    'Turns out, you can take it one step further and just output both counters to the same pin. The outputs get ORed, just as they would between cogs. That way, you can connect the IRED's cathode to the pin; the anode, through a resistor, to Vdd.

    -Phil
  • T ChapT Chap Posts: 4,217
    edited 2007-04-02 06:26
    Very clever tricks. I am curious how effective the IR detection is when under naturally bright light from the sun, or even artificial lighting.

    **Google just answered this
    pna4602 said...
    These sensors provide a very clean signal and won't even saturate in sunlight.

    How many cogs required if not using Full Dup for terminal? PWMsweep = 1 and IR detect = 1?

    Post Edited (TChapman) : 4/2/2007 6:39:36 AM GMT
  • edited 2007-04-02 14:14
    TChapman,

    Just one cog. The cog's two counter modules do a lot of the work (38 kHz signal with one counter and a duty signal with the other), leaving the cog to just execute a loop that sweeps the register used for duty control (frqa) from 255 to 0 and record the IR detector's outputs. At 80 MHz, the measurement takes a little over 3 ms right now, but I'm sure we can improve on that. The IR LED and receiver work alright indoors, but they will get swamped if you take it outside on a hot, sunny day.

    Phil,

    Thanks! Hmmm, I'll have to take a closer look; getting back to one I/O pin would be ideal. I went·with two pins because I thought the NCO and PWM signals would have to be AND'd instead of OR'd to get it to work that way.

    Andy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 4/2/2007 5:04:00 PM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-04-02 18:33
    Andy,

    Actually, you would be ANDing them, if you consider the inverse signals, which the pull-down configuration implies:

    ··/IRED = CTRA + CTRB = /(/CTRA * /CTRB), so
    ·· IRED = /CTRA * /CTRB

    One counter just outputs a squarewave, so nothing gets changed there. The other one does the duty-cycle modulation, so the actual duty cycle is inverted. But, since you're accumulating the count over a full duty-cycle sweep, your program should stay the same.

    -Phil
  • T ChapT Chap Posts: 4,217
    edited 2007-04-02 18:51
    What is the sweep accomplishing versus a fixed pulse?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-04-02 19:05
    The idea is to determine the minimum IRED output power required to obtain a readable reflection. This, in turn, can be used to infer the object distance: more required power = farther away.

    -Phil
  • T ChapT Chap Posts: 4,217
    edited 2007-04-02 20:24
    Thanks Phil, that makes sense.

    My understanding so far is, it sends out a 38k pulse with one counter nco fixed at 50%, then gradually, one counter in duty mode sweeps and effectively ORs with the fixed. When enough energy(duty) hits the detector, it turns on, and returns a high on its output. Not clear on this, the dist return of the method is stated as 0-40, but the potential for the detector to turn on is more than 40 times over the 0-255 repeats?

    I can't tell if the result takes the original fixedduty and extends it from between 50 - 100 or reduced is from 50-0, or better yet, even allows 0-100? I didn't think there was a way to manipulate only two pins to achieve a set freq with fully adjustable duty.

    There would have to be some distance consideration for the reflective material of the object.


    This IR detector shows the first example I remember seeing of the use of setting ctra parameters separately, not that it matters for the fixed pulse, but which is faster below?

     ctra[noparse][[/noparse]30..26] := %00110 
     ctra[noparse][[/noparse]5..0] := cathode
    



    or

     ctra[noparse][[/noparse]30..26] := %00110  << 26 + 0 
    
    

    Post Edited (TChapman) : 4/2/2007 8:44:27 PM GMT
  • edited 2007-04-02 20:50
    Ah ha! I see it now Phil, thanks.

    Instead of synthesizing a DC voltage on the cathode terminal that attenuates the 38 kHz signal applied to the anode, the one-pin approach provides a DC voltage during what would otherwise be the low portion of the 38 kHz signal.

    By sweeping that DC voltage (the duty signal), it progressively takes away from the low portion of the signal, which in turn reduces its amplitude. When the duty signal synthesizes a low DC voltage, the 38 kHz signal is almost 3.3 V. By the time the duty signal gets to 50%, the 38 kHz signal is only 1.65 V, and so on.

    BTW, the next PE Kit Lab is almost done, and it's a potpourri of circuits and counter applications. IR object detection is in there as an example, but I was saving frequency sweep distance detection for an assigned project. It’s more fun when there are more interesting examples, so now I can append the object detection example with this little distance detection gem and still have a variation for the assigned projects.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
  • edited 2007-04-03 02:05
    TChapman,

    Sorry about that. 0 to 40 is an artifact of an earlier incarnation of that object. The current range should be 0 to 256. (I intended it to be 0 to 255.)

    If you want 0 to 100, open Ir Detector.spin and change the scale constant to 232/100 = 42,949,673, and then sweep duty from 0 to 99 in the repeat loop.

    Phil,

    I've been experimenting with (38 kHz OR duty) on one pin, and the results just aren't the same.·It's·useable, but I haven't had time to sort through all the caveats.· I think something in the IR receiver (maybe the agc or filter) doesn't like it when the duty signal turns on/off at 38 kHz.

    With the two pin arrangement, the duty signal remains “on” through the entire sweep, and the response is a lot cleaner. Another thing about the two pin arrangement, it's only one more pin regardless of how many IR LEDs get used. They can all share the same duty pin.

    Andy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 4/3/2007 2:13:25 AM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-04-03 03:44
    Andy,

    Are you connecting the IRED cathode to the pin and the anode, through a resistor, to Vdd? (If you connect anode to pin and cathode to ground, the IRED will be completely on half the time, which might — but theoretically shouldn't — compromise performace.) With the two-pin configuration, the IRED is off half the time and duty-cycled half the time, which should be exactly equivalent to pulling it down in the one-pin configuration.

    The only other thing I can think of is that, in the two-piin setup, the IRED is being driven into and out of reverse bias; whereas, it simply relaxes in the one-pin situation. But that should make things worse, not better, due to charge build-up on the reverse-biased junction.

    -Phil
  • T ChapT Chap Posts: 4,217
    edited 2007-04-04 08:39
    I have 2 spare pins, 3 at the most, and would like to check distance with two PNC4602's. The use is to check if an object is in motion within X inches of each detector, beyond a threshold I don't care if there is motion. My guess is, you'd store the distance on every sweep, and compare to the distance on the next round, if there is a change of some amount outside a tolerance range, there is motion.

    I would guess you could transmit two IRleds off the same pin(s), but I can't think of anyway to read both detectors back on just one pin with some OR scheme.

    Post Edited (TChapman) : 4/4/2007 9:23:03 AM GMT
  • T ChapT Chap Posts: 4,217
    edited 2007-04-05 10:12
    How about on one pin, toggle a DAC on and off at 38K with a duty specified by waitcnts, setting the voltage from 0 - 3.3v depending on Threshold? The same could be applied to checking distance on one pin by sweeping the DAC while toggling.

    Repeat Threshold   'set threshold for detecting object within this range on any detector, range is 0-100
      [noparse][[/noparse]set DAC to Threshold  here] := Threshold   'DAC turns ON  for 50% of cycle at Threshold
      waitcnt( set to38000/100)/2 + cnt)
      [noparse][[/noparse]set DAC to 0) := 0   'turn off DAC for 50% of cycle
      waitcnt( set to 38000/100)/2 + cnt)
      If ina[noparse][[/noparse]detector] := 1   'may need own cog here?
          'object detected within threshold, some action
      
    
    




    In a case where all I care about is whether ANY detector is tripped, the detector can be any number of detectors ORed to the same pin with external logic. This method allows 1 pin for multiple emitters, and one pin for multiple detectors(with external OR/diodes).

    Post Edited (TChapman) : 4/5/2007 11:42:39 AM GMT
Sign In or Register to comment.