Interrupts - some pointers please.

russbow

Senior Member
I currently read data from a radio link to the 18m2 base. The base uses an RTC for real time display.
Due to the blocking nature of serin, displayed time can be wrong, especially if received data is missed from the link.

I am hoping to overcome this with an interrupt request. The 18m2 code is

Code:
#picaxe18m2

setint %00000010,%00000010	'Enable interrupt on pin c.1

do
'
'Whatever 
'
loop


interrupt:

serin c.1,n2400,b0,b1,b2

sertxd ("b0= ",#b0," b1= ",#b1," b2= ",#b2,cr,lf)

setint 010000010,%000000010

return
Request sent TO the 18m2 on pin c.1, and received serial in on pin c.7

The corresponding 08m2 code is

Code:
#picaxe08m2

setfreq m4

symbol ANT=c.1	'Data in from RX
symbol INT=c.4	'Int request TO 18m2
symbol SER=c.2	' Serial data TO 18m2
high ANT

do

serin ANT,T600,($AA,$BB,$CC), b0,b1,b2	'Get RX data
pause 200

High INT	'Send IRQ
pause 500
Low INT

serout SER,N2400,(b0,b1,b2)	'Send data
pause 200
sertxd ("b0= ",#b0," b1= ",#b1," b2= ",#b2,cr,lf)


pause 5000

loop
08m2 data received from link on c.1, IRQ when c.4 goes high, data out to 18m2 via c.2

Is this basically sound? I can't test fully at the moment due to lack of bits.
Would a pulseout be better on c.4
Do I need a pre-amble for the 08m2 to 18m2 link

All pointers would be appreciated.
 

Hemi345

Senior Member
Looks like it would work to me, but I would use a single pin on the 08m2 for both the interrupt and serout and include a qualifier on the serin on the 18m2.
 

geoff07

Senior Member
from the manual:

All processing stops until the new serial data byte is received. This command
cannot be interrupted by the setint command. The following example simply
waits until the sequence “go” is received.

I'm assuming that they mean any interrupt when they say setint

One way around this is to use an 08 as a dedicated receiver, and have that interrupt the 18M when it has a message for it.
 

russbow

Senior Member
Geoff, that's exactly what I'm proposing / trying to do

The 18m2 chunters away doing it's fast bits and upgrading time. The 08m2 waits for received RF and interrupts the 18m2 to pass data across.
 

geoff07

Senior Member
Sorry but I didn't grasp that from your message.

I built a photographic turntable moved in increments by a stepper motor, controlled by one chip but instructed by an IR remote (similar in effect to a radio) talking to another chip that did the interrupting in order not to mess with the timing of the rotations and controlling of the camera. It works fine. As already mentioned, one pin is enough, and you won't in principle need a qualifier as the 'channel' is noise-free, though I used one.

The attachments are the full code for that app. You can find the relevant sections and discard the rest. It only works for Nikon cameras at the moment, in case anyone is interested. It isn't up to my usual standard of documentation but I expect you can follow it.
 

Attachments

russbow

Senior Member
I have has some success with this insofar as the interrupt works on a live set up. However, trying to develop / integrate routines into the program
caused a fall at the first hurdle.

Please consider this.
Code:
#picaxe18M2

init:

setfreq m4

[B]setint %00000010,%00000010[/B]	'Enable interrupt on pin c.1

symbol LCD= c.2

pause 2000	'Allow OLED to initialise
serout LCD,n2400,(254,1,254,1)

do

gosub timeit


pause 5000
loop

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


timeit:	'current time

i2cslave %11010000, i2cslow, i2cbyte
	readi2c 0,(b0,b1,b2,b3,b4,b5,b6)
	
	pause 100

	b11=b2/16	 'hour MSD
	b12=b2 & $0F 'hour LSD
	b7=b1/16	 'min  MSD
	b8=b1 & $0F  'min  LSD
	b9=b4/16	 'day MSD
	b10=b4 & $0F 'day LSD
	b2=b5/16
	b3=b5 & $0F
	b0=b6/16:b4=b6 & $0F
	
	serout LCD,N2400,(254,192,#b11,#b12,":",#b7,#b8) 'H/M
	serout LCD,N2400,(254,200,#b9,#b10,"/",#b2,#b3,"/",#b0,#b4)
	
return


''''''''''''''''''''''''''''''''''''''''''''''''''''''



interrupt:

serin c.7,n2400,b0,b1,b2

pause 200


serout LCD,N2400,(254,128," b0= ",#b0," b1= ",#b1," b2= ",#b2)


setint %00000010,%00000010

return
If I rem out the first setint line, the bold one, the program runs and time increments.
When I un-rem this line, the program doesn't get as far as clearing the screen.

What am I missing?
 

hippy

Technical Support
Staff member
If I rem out the first setint line, the bold one, the program runs and time increments.
When I un-rem this line, the program doesn't get as far as clearing the screen.

What am I missing?
I would guess noise or a pulse from the receiver after it is turned on is causing an interrupt and then it sits there waiting for data which it never receives.

Try adding a PAUSE at the start of the program before the first SETINT, a #TERMINAL 4800 and a SERTXD after 'interrupt:' so you can check if it is entering interrupt unexpectedly.

If using dumb 433MHz modules I am not confident your interrupt approach will work or be reliable in all circumstances.

Note that the pulse needs to be long enough to guarantee getting into interrupt and to the SERIN. That pulse has to be at least as long as the time your longest SEROUT takes to execute. If it starts when within a SEROUT and has finished before the SEROUT has the data packet will be missed or data bytes will trigger an interrupt and cause a hang because it's expecting data which may never arrive.
 

russbow

Senior Member
Thanks Hippy.Working fine with just the RX, 08m2 and basic int program.
Tried on a separate chip without RX etc and got the trouble.
Just hit me. The Interrupt pin is not connected - floating :mad:
Will rectify tomorrow and add your enhance ments.
Thank a lot.
 

russbow

Senior Member
@Hippy. Thanks, that cracked it.
Also found that pulling the interrupt pin low stabilised everything well. Now have 1K reistors connecting the 08m2 interrupt and serial lines, and 10k interrupt to earth.

18m2 test program -

Code:
#picaxe18m2
setfreq m4
pause 1000
setint %00000001,%00000001	'Enable interrupt on pin c.0
symbol loops=b10
b12=0
do
'
pause 2000
 
'
loop


interrupt:

b12=b12+1
sertxd ("Count = ",#b12," ")

serin c.6,n2400,b0,b1,b2,loops

pause 200
sertxd ("Loop ",#loops,cr,lf)
sertxd (" b0= ",#b0," b1= ",#b1," b2= ",#b2,cr,lf)



setint %00000001,%00000001

return
Been running all day and well in sync. mini sertxd dump included.
Thank you.

Count = 93 Loop 93
b0= 201 b1= 40 b2= 18
Count = 94 Loop 94
b0= 201 b1= 40 b2= 18
Count = 95 Loop 95
b0= 202 b1= 40 b2= 18
Count = 96 Loop 96
b0= 202 b1= 40 b2= 18
 
Top