It's tough to search for the phrase "IR" on this forum, so please bear with me while I probably ask a previously asked question.
What methods are there to eliminate issues with interference from surrounding light, through optical filters or code?
I have a project that uses a TV remote (programmed for Sony codes) and a 38KHz IR decoder (a 3-pin version from the local Radio Shack). This decoder is already optically filtered. I'm using a 28x1 PICAXE
It works beautifully and responds well up to 20 feet (in the right lighting). However, when I turn on the fluorescent lights, my code appears to respond to the lighting and then locks up the app. Same thing happens if I press a button on the remote that I don't specifically check for in code. Here is my detection routine, activated via an interrupt on the IR in port.
This code does several things. It waits for CH-UP/CH-DN and individual number presses. I add 1 to the captured value for my convenience because I'm using the captured value for math operations. Remember, with the IRIN command, button '1' comes in as 0, '2' as 1, etc.
I also have the POSITION variable peppered in the code because I'm building a value, up to three digits, by shifting in sequential number presses. The POSITION variable tracks the digit sequence for me.
I use IR_IN as a variable name to capture the IRIN result. I set IR_IN to '255' as a default, for my own use because I don't know what the value returned by the IRIN command is if it times out. My guess is, the IR_IN variable remains unchanged in that case. So, I use '255' as my timeout value. The first IF block should not execute if the IR_IN variable = '255'.
That being said, something must happen. After all, the interrupt gets generated when I switch on the room lights and the code executes. How do I detect this as garbage data? Is it possible a bug in the IRIN function?
What methods are there to eliminate issues with interference from surrounding light, through optical filters or code?
I have a project that uses a TV remote (programmed for Sony codes) and a 38KHz IR decoder (a 3-pin version from the local Radio Shack). This decoder is already optically filtered. I'm using a 28x1 PICAXE
It works beautifully and responds well up to 20 feet (in the right lighting). However, when I turn on the fluorescent lights, my code appears to respond to the lighting and then locks up the app. Same thing happens if I press a button on the remote that I don't specifically check for in code. Here is my detection routine, activated via an interrupt on the IR in port.
Code:
interrupt:
irin [100, mainloop],0,IR_IN
if IR_IN <> LAST_IR and IR_IN <> 255 then
LAST_IR = IR_IN
IR_IN = IR_IN + 1
if IR_IN = 17 then
CURCOUNT = CURCOUNT + 1 MAX 999
POSITION = 0
elseif IR_IN = 18 then
CURCOUNT = CURCOUNT - 1 MIN 1
POSITION = 0
elseif IR_IN > 0 and IR_IN < 11 then
IR_IN = IR_IN DIG 0
POSITION = POSITION + 1
select case POSITION
case 1
CURCOUNT = IR_IN
case 2, 3
CURCOUNT = CURCOUNT * 10 + IR_IN
endselect
SET_TIMEOUT = 800
else
LAST_IR = 99
endif
TIMEOUT = 120
endif
IR_IN = 255
setint %00000000,%00000001
return
I also have the POSITION variable peppered in the code because I'm building a value, up to three digits, by shifting in sequential number presses. The POSITION variable tracks the digit sequence for me.
I use IR_IN as a variable name to capture the IRIN result. I set IR_IN to '255' as a default, for my own use because I don't know what the value returned by the IRIN command is if it times out. My guess is, the IR_IN variable remains unchanged in that case. So, I use '255' as my timeout value. The first IF block should not execute if the IR_IN variable = '255'.
That being said, something must happen. After all, the interrupt gets generated when I switch on the room lights and the code executes. How do I detect this as garbage data? Is it possible a bug in the IRIN function?