Why do I need the delay in IR detection program?
RichardF
Posts: 168
{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!
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
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
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