Why doesn't this IR detection program work?
RichardF
Posts: 168
{Only the first pulse out gives a return detect signal (red LED on), then the red LED goes off until I remove the reflective surface from in front of the LED, then reinsert it. I then get one detect pulse and then nothing again. In other words I am only getting one return detected (the first one) even though the reflector object remains in place. It resets if I remove the reflector then reinsert it. The IR_detect_2 method is straight out of the Counter Modules and Cicuit Applications Lab PE Kit Lab Series, page 29. Any ideas, please?
Thanks,
Richard}
CON
_clkmode = xtal1 + pll16x················
_xinfreq = 5_000_000
VAR
byte IR_detect
OBJ
SqrWave··· : "SquareWave"
PUB main
IR_detect_2
PUB IR_detect_2
SqrWave.Freq(0, 2, 38500)········ '38.5 kHz signal → P2·······················
dira[noparse][[/noparse]15]~~····························· 'output to red indicator LED
repeat
· dira[noparse][[/noparse]2]~~···························· 'I/O pin → output to transmit 38.5 kHz
· waitcnt(clkfreq/1000 + cnt)···· 'Wait 1 ms
· IR_detect := ina[noparse][[/noparse]3]··············· 'Store I/R detector output·
· dira[noparse][[/noparse]2]~······························ 'I/O pin → input to stop signal
···
· if IR_detect == 0·················· 'object detect
··· outa[noparse][[/noparse]15]~~······················· 'turn on red LED
· else
··· outa[noparse][[/noparse]15]~························ 'turn off red LED
····
Thanks,
Richard}
CON
_clkmode = xtal1 + pll16x················
_xinfreq = 5_000_000
VAR
byte IR_detect
OBJ
SqrWave··· : "SquareWave"
PUB main
IR_detect_2
PUB IR_detect_2
SqrWave.Freq(0, 2, 38500)········ '38.5 kHz signal → P2·······················
dira[noparse][[/noparse]15]~~····························· 'output to red indicator LED
repeat
· dira[noparse][[/noparse]2]~~···························· 'I/O pin → output to transmit 38.5 kHz
· waitcnt(clkfreq/1000 + cnt)···· 'Wait 1 ms
· IR_detect := ina[noparse][[/noparse]3]··············· 'Store I/R detector output·
· dira[noparse][[/noparse]2]~······························ 'I/O pin → input to stop signal
···
· if IR_detect == 0·················· 'object detect
··· outa[noparse][[/noparse]15]~~······················· 'turn on red LED
· else
··· outa[noparse][[/noparse]15]~························ 'turn off red LED
····
Comments
Just out of curiosity, what happens if you just leave the IR's clock output enabled, instead of keying it on and off (i.e. put the dira~~ above the repeat, and eliminate the dira~)?
-Phil
-Phil.