Interrupt problem on a 28X1

I am trying to create an interrupt when a pulsin command receives a value of less than 150 from an RC receiver.
When I run this code in the simulator, upon the execution of the instruction "if RXIN<150 then Let Land=1", OUTPUT PIN 2 takes the value 1 instead of INPUT PIN 2. Therefore, the interrupt never occurs. I am probably doing something wrong but I can't figure what that is. Any advice will be greatly appreciated.
The code is as follows.
Code:
#picaxe 28x1
#com 4
 
'Variables
Symbol RXIN =W0
Symbol Dly = b6
Symbol M=b4
Symbol N=b5
Symbol R=b7

Pause 5000
'Pins
Symbol Land = Input2
Symbol RX_IN= Input0

 	let dirsc = %11110010
 	let pinsc = %00000000
 	setint %00000100,%00000100
Main:
	Dly=30
	Pulsin 0,1,RXIN
	if RXIN<150 then Let Land=1
	endif
		SHOW:
	For R=0 to 5
		FORWRD:'***********************************
............
..............
............
	Pause 20
	Goto Main
'********************************************************
	Interrupt:
	For R=0 to 5
	let pinsc=%00010010
	pause Dly
	let pins=%00000000
	M=%10000000
	let pinsc=%00010000
	for N=0 to 7
	let pins=M
	M=M/2
	pause Dly
	Next N
	let pins=%00000000
	pause DLY
	let pinsc=%10010000
	Pause Dly
	let pinsc=%01010000
	Pause Dly
	let pinsc=%00110000
	Pause Dly
	let pinsc=%00010000
	Pause Dly
	Pause Dly
	let pinsc=%00010000
	pause Dly
	let pinsc=%00010010
	Next R
	
setint %00000100,%00000100
return
 

MPep

Senior Member
I didn't think that you could do mathematics in a "IF...THEN" construct.

Post your whole code so that others can use in a simulator as well.
 
Last edited:
Here is the whole code
Code:
#picaxe 28x1
#com 4
 
'Variables
Symbol RXIN =W0
Symbol Dly = b6
Symbol M=b4
Symbol N=b5
Symbol R=b7

Pause 5000
'Pins
Symbol Land = Input2
Symbol RX_IN= Input0

 	let dirsc = %11110010
 	let pinsc = %00000000
 	setint %00000100,%00000100
Main:
	Dly=30
	Pulsin 0,1,RXIN
	if RXIN>150 then goto Show
	High pinsc 2
	
		SHOW:
	For R=0 to 5
		FORWRD:'***********************************
	
	let pinsc=%00000010
	pause Dly
	let pins=%00000000
	M=%10000000
	
	for N=0 to 7
	let pins=M
	M=M/2
	pause Dly
	Next N
	let pinsc=%00000000
	let pins=%00000000
	pause DLY
	let pinsc=%10000000
	Pause Dly
	let pinsc=%01000000
	Pause Dly
	let pinsc=%00100010
	Pause Dly
	let pinsc=%00000000
	pause Dly
	let pinsc=%00000010
	
	
	Next R
	Pause 20
	
	
	For R=0 to 5
		FORBACK:'***********************************
	let dirsc=%11110010
	
	pause Dly
	let pins=%00000000
	M=%10000000
	let pinsc=%00000010
	for N=0 to 7
	let pins=M
	M=M/2
	pause Dly
	Next N
	let pins=%00000000
	let pinsc=%10000000
	Pause Dly
	let pinsc=%01000000
	Pause Dly
	let pinsc=%00100010
	Pause Dly
	let pinsc=%00000000
	Pause Dly
	Pause Dly
	let pinsc=%00100010
	pause Dly
	let pinsc=%01000000
	pause Dly
	pause Dly
	let pinsc=%10000010
	pause Dly
	let pinsc=%00000000
	pause Dly
	M=%00000001
	For N=0 to 7
	let pins=M
	M=M*2
	pause Dly
	Next N
	let pinsc=%00000010
	
	Next R
	Pause 20
	
	
	Dly=51
	For R=0 to 10
		FROMCENT: '***********************************
	
	Let pinsc=%00000010
	Pause Dly
	let pinsc=%00000000
	
	let pins=%00000100
	Pause Dly
	let pins=%00000010
	Pause Dly
	let pins=%00000001
	Pause Dly
	let pins=%00100000
	let pinsc=%10000000
	Pause Dly
	let pins= %01000000
	let pinsc=%01000010
	Pause Dly
	let pins=%10000000
	let pinsc=%00100000
	pause Dly
	let pinsc=%00000000
	let pins=%00000000
	Pause Dly
	let pins= %10000000
	let pinsc=%00100000
	Pause Dly
	let pins= %01000000
	let pinsc=%01000010
	Pause Dly
	let pins=%00100000
	let pinsc=%10000010
	Pause Dly
	let pins=%00010001
	let pinsc=%00000000
	Pause Dly
	let pins=%00001010
	Pause Dly
	let pins=%00000100
	'Dly=Dly-5 min 15
	Pause Dly
	let pinsc=%00000010
	Dly=Dly-1
	Next R
	Dly=30
	Pause 20
	Goto Main
'*********************************************************	
	Interrupt:
	For R=0 to 5
		
	
	let pinsc=%00010010
	pause Dly
	let pins=%00000000
	M=%10000000
	let pinsc=%00010000
	for N=0 to 7
	let pins=M
	M=M/2
	pause Dly
	Next N
	let pins=%00000000
	pause DLY
	let pinsc=%10010000
	Pause Dly
	let pinsc=%01010000
	Pause Dly
	let pinsc=%00110000
	Pause Dly
	let pinsc=%00010000
	Pause Dly
	Pause Dly
	let pinsc=%00010000
	pause Dly
	let pinsc=%00010010
	Next R
	
setint %00000100,%00000100
return
 

kevrus

New Member
i'm not sure that you can modify or alter the value of an input pin with an 'if...then' statement, only act on the actual value present on the pin.

If the outpin 2 is spare, you could connect it to input 2, then when outpin 2 goes high, then input 2 would also go high hence triggering the interrupt.
 
Last edited:

hippy

Ex-Staff (retired)
It is, as kevrus says, not possible to set an input pin from within a PICAXE program.

"input2" is a synonym of "pin2" provided for convenience and historical reasons, so while "LET b0=input2" reads the input pin as expected, "LET input2=1" is the equivalent of "LET pin2=1" which is why the output pin is being set.

Likewise "outpin2" is ( generally ) a synonym for "pin2" so one could use some pretty strange coding such as "LET input2=outpin2" but that still translates to "LET pin2=pin2", sets output pin 2 from input pin 2.

If you need to invoke an interrupt by forcing an input pin, the best solution would be to assert an output pin which connects to that input pin as suggested.

The circumstances in which there is a need to use this mechanism are limited, and it would normally be easier to simply "GOSUB interrupt" instead of setting the output pin to cause that.

If you do need this mechanism, it is possible in some circumstances on some PICAXE's where the input pins which can trigger an interrupt are also usable as output pins. The pin ceases to be an input pin but the interrupt detecting code will read what is on the output pin as if it were an input pin.

For example, this code works on an 08M -

#Picaxe 08M
SetInt %00100,%00100
Do
Pause 5000
High 2
Loop

Interrupt:
SerTxd("Interrupt",CR,LF)
Low 2
SetInt %00100,%00100
Return

In the case of the 28X1, rather than "LET input2=1" or "HIGH 2" using "HIGH PORTC 2" achieves the interrupt desired. Input Pin 2 should not be connected to external hardware unless short-circuit prevention circuitry is used. This works on a 28X1 -

#Picaxe 28X1

SetInt %00000100,%00000100
Do
Pause 5000
High PortC 2
Loop

Interrupt:
SerTxd("Interrupt",CR,LF)
Low PortC 2
SetInt %00000100,%00000100
Return

The following works on a 28X2 as a direct translation of the 28X1 code -

#Picaxe 28x2
SetInt %00000100,%00000100,C
Do
Pause 5000
High C.2
Loop

Interrupt:
SerTxd("Interrupt",CR,LF)
Low C.2
SetInt %00000100,%00000100,C
Return

And the "HIGH C.2" and "LOW C.2" can be achieved through using pin variables as below. Note the initial "dirC.2=1" to set the pin as an output -

#Picaxe 28x2
dirC.2 = 1
SetInt %00000100,%00000100,C
Do
Pause 5000
pinC.2 = 1
Loop

Interrupt:
SerTxd("Interrupt",CR,LF)
pinC.2 = 0
SetInt %00000100,%00000100,C
Return

Using "SYMBOL land=pinC.2" and replacing references to "pinC.2" wth "land" would give the equivalent of the original 28X1 program for the 28X2. The compiler does not support "SYMBOL land=PORTC pin2" so this is not possible with the 28X1, but would work for the 08M.
 
Last edited:
Hippy,
I copied exactly the following code into the editor and run the simulator. It stays in the loop and never goes to Interrupt.
Code:
#Picaxe 28X1

SetInt %00000100,%00000100
Do
Pause 5000
High PortC 2
Loop

Interrupt:
SerTxd("Interrupt",CR,LF)
Low PortC 2
SetInt %00000100,%00000100
Return
 

MPep

Senior Member
That's because you are trying to use an output pin to trigger an input interrupt event.
I modified the code to use pin3 as the input, and pin2 as the output.
Code:
#Picaxe 28X1

SetInt %00001000,%00001000
Do
Pause 50
High PortC 2
Loop

Interrupt:
SerTxd("Interrupt",CR,LF)
Low PortC 2
SetInt %00001000,%00001000
Return
This works as expected.:)

You could also use the following code. Uses PortB as the output and C as the input
Code:
#Picaxe 28X1

SetInt %00000100,%00000100
Do
Pause 50
High 2
Loop

Interrupt:
SerTxd("Interrupt",CR,LF)
Low 2
SetInt %00000100,%00000100
Return
PS: I shortened the delay for simulation purposes.

@SilentScreamer, thanks for the clarification.
 
Last edited:

hippy

Ex-Staff (retired)
Hippy,
I copied exactly the following code into the editor and run the simulator. It stays in the loop and never goes to Interrupt.
That doesn't surprise me; the Simulator simulates a PICAXE running the program, it does not simulate PICmicro hardware and all its nuances.

Run the program on physical 28X1 hardware and it will work.
 
Top