Help please.Inrafra-red

ernest

Member
--------------------------------------------------------------------------------

Hello all . I ues picaxe with my Meccano Hobby its a lot of fun.
I am trying to create a programe, to use with infra-red , so that when I
press the transmmiter button the output goes high ,and remains high ,so long as I keep the button pressed, and when I take my finger off, the output goes low. With my code the output remains high. I think I know why it stays high but I dont know how to fix it. A bit of code would be a big help please.
main
infrain
start:
if infra = 1 then high 4
else low 4
endif
goto start
 

benryves

Senior Member
As infrain blocks execution until a command is received, the most "correct" way to fix the issue would be to use irin with a suitable timeout (though that requires an X1/X2 PICAXE). Sony-compatible remote controls repeatedly transmit the code when a button is held, and nothing when a button is released.

If you don't care which button is pressed (or even which remote control protocol) you could just check that the input pin goes low at least once every hundred ms (say). If so, switch the output on, otherwise switch it off.
 

ernest

Member
Thanks for your reply .I have tryed switching the out put high and low 100ms but
it drops the voltage 12v down to 3v , I have to use a full second to maintain 12v,
which effects the smooth running of the motor. Brian
 

benryves

Senior Member
Here's a crude version that works for me without using an X1/X2 part:

Code:
SetFreq M8 ; Reduces the timeout period to 0.3s
Do
	PulsIn 1, 0, W0
	If W0 = 0 Then
		Low 4
	Else
		High 4
	EndIf
Loop
There's a 0.3s delay between releasing the button and the output going low again, but it comes on pretty much instantaneously. Note that this may also be susceptible to interference (it doesn't check if it's received a valid IR signal).

A better alternative may be to use the Count command and a shorter period, which allows for a quicker response and slightly improved robustness:
Code:
Do
	; We'd expect at least one command every 45mS.
	Count 1, 45, W0
	; SIRCS commands are at least 12 bits long.
	; We'll check and see if we've received at least 8.
	If W0 >= 8 Then
		High 4
	Else
		Low 4
	EndIf
Loop
Neither of these solutions allow for more intelligent decoding of the signal (eg permitting different outputs for different buttons). An X1 or X2 part would be much easier, but I don't believe you've mentioned which PICAXE you're using.
 
Last edited:

ernest

Member
Here's a crude version that works for me without using an X1/X2 part:

Code:
SetFreq M8 ; Reduces the timeout period to 0.3s
Do
	PulsIn 1, 0, W0
	If W0 = 0 Then
		Low 4
	Else
		High 4
	EndIf
Loop
There's a 0.3s delay between releasing the button and the output going low again, but it comes on pretty much instantaneously. Note that this may also be susceptible to interference (it doesn't check if it's received a valid IR signal).

A better alternative may be to use the Count command and a shorter period, which allows for a quicker response and slightly improved robustness:
Code:
Do
	; We'd expect at least one command every 45mS.
	Count 1, 45, W0
	; SIRCS commands are at least 12 bits long.
	; We'll check and see if we've received at least 8.
	If W0 >= 8 Then
		High 4
	Else
		Low 4
	EndIf
Loop
Neither of these solutions allow for more intelligent decoding of the signal (eg permitting different outputs for different buttons). An X1 or X2 part would be much easier, but I don't believe you've mentioned which PICAXE you're using.
Hi I ran your first code on the simulator ok ,but no joy with the infer-red remote. Do I need to extend this code to use the remote, and how please? I am using 18X
 
Top