Can NOT interrupt 2 Infrared Interrupts

4jaba6

New Member
I have 2 infrared sensors that are in opposite directions.
The program has a "Main" Loop which when interrupted by a certain Sony Remote Code should light a red or green led
to show which ir sensor received the ir signal.
Only the red led will light see code "flashred...." when ir received on ir sensor connected to pin4.
When ir is transmitted from opposite side, the green led will not light; ir should be received and pin3 do this.

I have checked this with irin pin3 only with another program: NOT using INTERRUPT and ir into sensor on pin 3 only ( no irin on pin 4 ect. ) and ir received
on sensor and pin3 go's high and green led lights.
Therefore I must conclude it is not in circuit but something in code.

I will appreciate any advice on this . It is probably something very simple
and I not seeing forest thru trees!

The code:



' TEST 2 IR INTERRUPT's

' 12-16-2015

' See page 69 of Manual "Getting
' Started" Section 1

symbol reccode = b0


setint %00000000, %00011000

main:
pause 100
high 5
low 4
pause 500
goto main

interrupt:

CKA:
irin[1000,CKB],4,reccode
pause 100
if reccode = 2 then flashred


CKB:
irin[1000,interdone],3,reccode
pause 100
if reccode = 2 then flashgreen


interdone:
setint %00000000, %00011000
return

flashred:
low 5
high 4
pause 2000
low 4
pause 200
goto interdone

flashgreen:
high 4
pause 500
low 4
high 5
pause 2000
low 5
pause 200
goto interdone
 

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

Perhaps start by checking that each IR sensor is receiving individually ...

Code:
Do
  Do
    b0 = pinsC & %00011000 
  Until b0 <> %00011000
  SerTxd( "IR detected on" ) 
  If bit3 = 0 Then : SerTxd( " pin C.3" ) : End If
  If bit4 = 0 Then : SerTxd( " pin C.4" ) : End If
  SerTxd( CR, LF )
  Pause 1000
Loop
 

Technical

Technical Support
Staff member
CKA accidentally 'falls' into CKB - you may want a 'goto interdone' between the two.
 

4jaba6

New Member
CKA accidentally 'falls' into CKB - you may want a 'goto interdone' between the two.
Technical, Thank You for the reply. Your suggestion does not solve. I tried it ...the CKB is never gotten to in this code.
Again, THANK ! any other ideas?
 

4jaba6

New Member
hippy, Thank You for the reply! I got a msg. " syntax error" for: "Until b0 <> %00011000"
Any thots? I have tested each IR sensor with another program and they do receive individually, but
I would also like to test with your program if I can correct the syntax.
Again, thanks for your efforts.
 

srnet

Senior Member
I got a msg. " syntax error" for: "Until b0 <> %00011000"
Syntax errors are normally an error in constructing a command as defined in the manual.

So lookup what the manual says about the do .... loop command and all will be revealed.
 

hippy

Ex-Staff (retired)
Sorry about that ...

Code:
Do
  Do
    b0 = pinsC & %00011000 
  Loop Until b0 <> %00011000
  SerTxd( "IR detected on" ) 
  If bit3 = 0 Then : SerTxd( " pin C.3" ) : End If
  If bit4 = 0 Then : SerTxd( " pin C.4" ) : End If
  SerTxd( CR, LF )
  Pause 1000
Loop
 

4jaba6

New Member
hippy,

Thanks, your code fix worked!

However, for some reason, I can not get the editor to print "IR detected on" ( the serial text )!?!?
I subsituted lighting leds for the text when the IR received and your sensor test program does what it issupposed to!
Perhaps the " non-printing" is related to baud rate or something!?!?
Ironically, when I run in simulation, it prints in the simulation window.
If there is any easy answer to why the editor will not print, I would like to know.
MORE IMPORTANTLY, I wish help on why my initial program will not receive the IR on pin3, interrupt and light the green le( we know the sensor works from your program ).
Again, THANKS for your assistance and others on this problem.

jb
 

hippy

Ex-Staff (retired)
You probably need to open the Terminal manually to see the text output, or add a #TERMINAL 4800 ( for M2 ) or #TERMINAL 9600 ( for X2 ) line to the top of the program to make that happen automatically.

If that polling loop works, the next step is to probably do the same but with an interrupt -

Code:
#Terminal ...

Gosub Interrupt_Enable
Do
  Pause 10
Loop

Interrupt:
  b0 = pinsC
  SerTxd( "IR detected on" ) 
  If bit3 = 0 Then : SerTxd( " pin C.3" ) : End If
  If bit4 = 0 Then : SerTxd( " pin C.4" ) : End If
  SerTxd( CR, LF )
  Pause 1000

Interrupt_Enable:
  SetInt %00000000, %00011000
  Return
Looking back at what you have, it is perhaps because the code waits for a second for IR on C.4 before checking for IR on C.3. If the IR seen on C.3 isn't present ( button isn't held ) for a full second it may not be seen.

You could perhaps fix that with a check to test which interrupted ...

Code:
Interrupt:
  If pinC.3 = 0 Then
    IrIn ... C.3 ...
  Else
    IrIn ... C.4 ...
 

4jaba6

New Member
hippy, THANK YOU for your assistance.
Got the program to execute as i had hoped with your code.
I have not yet tried to shorten the "wait time".
 
Top