I thought (hoped) that SETINT and SETINTFLAGS were separate?

MartinM57

Moderator
This code works as expected - an interrupt every 0.5 secs with a sertxd on every other interrupt showing the (whole) seconds counter
Code:
#picaxe 28x2
#no_table
#slot 0
#terminal 38400

symbol secs	= b15
symbol half_sec_count = b55

setfreq em32

;interrupt every 0.5 seconds
SETTIMER t1s_16
TIMER = 65535

;interrupt on timer (flag) overflow
SETINTFLAGS %10000000,%10000000

DO
LOOP

interrupt:
	SERTXD ("Interrupt...")
	INC half_sec_count 
	IF half_sec_count  = 2 THEN
		INC secs
		SERTXD ("...secs = ", #secs)
		half_sec_count  = 0
	END IF
	SERTXD (CR, LF)
	SETTIMER t1s_16
	TIMER = 65535
	SETINTFLAGS %10000000,%10000000
	return
but this produces no (timer) interrupts at all :(
Code:
#picaxe 28x2
#no_table
#slot 0
#terminal 38400

symbol secs	= b15
symbol half_sec_count = b55

setfreq em32

;interrupt every 0.5 seconds
SETTIMER t1s_16
TIMER = 65535

;interrupt on timer (flag) overflow
SETINTFLAGS %10000000,%10000000

DO
	;turn (pin B.0 = 1) interrupts on and off
	SETINT %00000001,%00000001, B
	;...in fact you don't even need this line to stop SETINTFLAGS responding
	SETINT OFF
LOOP

interrupt:
	SERTXD ("Interrupt...")
	INC half_sec_count 
	IF half_sec_count  = 2 THEN
		INC secs
		SERTXD ("...secs = ", #secs)
		half_sec_count  = 0
	END IF
	SERTXD (CR, LF)
	SETTIMER t1s_16
	TIMER = 65535
	SETINTFLAGS %10000000,%10000000
	return
Everything I see in the manual seems to suggest that SETINT and SETINTFLAGS are separate - but it doesn't explicitly say so. It appears they aren't - which is bad news for my app (concurrent elapsed timing with ON/OFF manipulation of the pin interrupts at certain times).

Ideas?
 

westaust55

Moderator
In the Manual 2 (ver 6.9) page 180 under the function heading, it states:
"X1 and X2 parts can also alternately interrupt on certain 'flags' byte conditions - see setintflags command.

Bottom of the same page:
The can also use the 'flags' byte (instead of the input port) to generate the interrupt condition.

Maybe not 100% clear for all readers but the intent I believe is to indicate one or the other (not both simultaneously).
 

MartinM57

Moderator
:( - oh well, at least it's only a proof of concept/prototype, and all should be well in the ultimate target AVR...
 

popchops

Well-known member
Only the latest of SETINT or SETINTFLAGS will be active ...

http://www.picaxeforum.co.uk/showpost.php?p=106222&postcount=9
Hi all,

I had the same query regarding the need for 'setint' in the case 'setintflags' is issued, so it's helpful to know that 'setintflags' is an alternative and does not depend on 'setint'.

'hintsetup' has a clear statement in the command help:
Therefore to have the PICAXE program call the "interrupt:" section of code upon a hardware pin interrupt you must follow two steps:
1) use hintsetup to allow hardware flag setting.
2) then use setintflags to actually generate an interrupt upon the setting of those flags. This means it is possible to interrupt on a combination of any, or all, of the flags via use of the setintflags command. See the setintflags command description for more details.
This implies, although I can't see it specified, that setintflags must be re-issued after the interrupt occurs? The same decription for 'hintsetup' says:
Activation of each individual pin sets two flags, its own unique flag and the shared 'hintflag'. The flags must be cleared manually in the user's PICAXE program
Which flags need to be cleared and how? I have a very simple need - to trigger an interrupt on every rising edge of hint2 (pin23 on the 28X2). The source is configured (currently) to go high for 20ms, and should reach 4.4V when driven high. Is this enough to trigger the hint2 interrupt?

I have the following code (simplified):
Code:
init:
hintsetup %01000100    ;enable hint2 upon rising edge
setintflags %00000100,%00000100 ;configure hint2 only (pinB.2)

main:
...
goto main

interrupt:
if pinB.3 = 1 then ;increase
    if bvol<255 then ;only if not already at maximum
        inc bvol
    endif
else             ;decrease
    if bvol>0 then ;only if not already at minimum
        dec bvol
    endif
endif
hintsetup %01000100    ;enable hint2 upon rising edge
setintflags %00000100,%00000100 ;configure hint2 only
return
My interrupt routine is not getting called, as I'm seeing neither an increase nor decrease in the 'bvol'. I know I must be close - please put me out of my misery. What am I missing? Thanks in advance!

Pops.
 
Top