IR detect
jonduncan
Posts: 40
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
In particular, look at the routine "pulseOut" around line 1460 and the Basic function IRZONE around line 500.
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
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
Thanks, Andy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
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
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
**Google just answered this
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
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
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
-Phil
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?
or
Post Edited (TChapman) : 4/2/2007 8:44:27 PM GMT
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.
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
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
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
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