Shop OBEX P1 Docs P2 Docs Learn Events
Why do I need the delay in IR detection program? — Parallax Forums

Why do I need the delay in IR detection program?

RichardFRichardF Posts: 168
edited 2007-06-24 01:30 in Propeller 1
{The following IR detection application works perfectly, but only with the last line
1/10 second delay in the program. If I remove this delay or shorten it, only the first pulse
out gives a return detect signal, then the red LED goes off until I remove the reflector
then reinsert it. I then get one detect pulse and then nothing again. In other words
I am only getting one return detected even though the reflector object remains in place.
It resets if I remove the reflector then reinsert it.
I can't figure out why the delay is needed. Any ideas, please?
Thanks,
Richard}

CON
_clkmode = xtal1 + pll16x················
_xinfreq = 5_000_000

VAR
byte IR_detect

OBJ
SqrWave··· : "SquareWave"

PUB main
IR_detect_1

PUB IR_detect_1
dira[noparse][[/noparse]2]~~··························· 'output to IR LED
dira[noparse][[/noparse]15]~~·························· 'output to red detect indicator LED
repeat
· repeat 40························· '1 millisecond burst @ 38.5 khz
··· outa[noparse][[/noparse]2]~~
··· waitcnt(clkfreq/19250 + cnt)····
··· outa[noparse][[/noparse]2]~
··· waitcnt(clkfreq/19250 + cnt)
···
· IR_detect := ina[noparse][[/noparse]3]··············· 'in from IR detector
· if IR_detect == 0················· 'IR return detect
··· outa[noparse][[/noparse]15]~~······················ 'turn on red LED
· else
··· outa[noparse][[/noparse]15]~······················· 'turn off red LED
· waitcnt(clkfreq/10+cnt)·········· 'don't know why I need this delay, but I do!

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-06-23 21:06
    I'm not sure about the delay thing, but your 38.5 KHz burst is actually 9.625 KHz. Any detection you're getting is coming from a fourth harmonic of the fundamental frequency. The correct divisor for clkfreq would be 77000 -- twice the desired output frequency, instead of half.

    As to the delay, it's possible that there's some latency in the detector, as it filters the input frequency. You could try a longer burst to, perhaps, secure an output more quickly; or maybe just fixing the fundmental frequency will do the job.

    -Phil
  • RichardFRichardF Posts: 168
    edited 2007-06-24 01:30
    Phil,
    I changed to 77000 and the detection distance quadrupled! Thanks, dumb mistake. However, the delay is still required. Wish I knew why. I tried a longer burst and that didn't work.
    Richard
Sign In or Register to comment.