next instruction that was about to be
executed when the interrupt
occurred.
Now, let’s turn our attention to
the setint command, and how we
specify the input condition(s) and the
pin(s) that we want to use for the
interrupt. The complete syntax is
setint input, mask, where input
defines the desired input condition(s)
(high/low), and mask defines which
pin(s) are to be checked to see if an
interrupt should occur.
Since the interrupt we need is a
simple one (i.e., one pin and one
condition), let’s use that as an
example to clarify the use of the
setint command. First, on all current
PICAXE M2-class processors (and the
20X2), only port C pins can be used
to trigger an interrupt. In addition,
each processor is limited to specific
port C pins. Figure 4 presents the
available pins for each processor. In
the present experiment, we’ll use C. 3
on the 08M2 because it’s fixed as an
input, and it can’t be used for an
ADC reading.
When I first started working on
this experiment, I assumed it would
make sense to use the built-in pull-up
resistor on pin C. 3 to hold the input
line in a high state, and have the Pi
interrupt the PICAXE by pulling C. 3
low. However, that didn’t work very
well. When a program is first run on
the Pi, all the input pins are set low
(which is the same safety precaution
that PICAXE uses), so a “false”
interrupt is generated every time a Pi
program starts to run.
As a result, I switched to the other
option (pin C. 3 normally low, with a
high interrupt pulse). We could use
the internal pull-down resistor on the
Pi to hold GPIO 22 low, but I decided
to use an external 10K pull-down
resistor (see the schematic in Figure 1),
just to remind myself that the interrupt
line is being held low.
Now, let’s examine the setint
command we need to implement the
interrupt (setint %00001000,
%00001000). We’ll start with the
second parameter (mask) because it
makes things easier to understand. As
mentioned, the mask specifies which
pins are to be checked. The fact that
there is only one “1” in the mask (in
the bit 3 position) indicates that we
are only interested in checking the
state of pin C. 3.
In the first parameter (input), the
1 in the bit 3 position indicates that
we want the interrupt to occur when
pin C. 3 is pulled high. This syntax may
seem unnecessarily complicated, but
that’s because we’re implementing a
simple one-pin interrupt.
If, for some reason, we wanted
to implement an interrupt that should
be triggered whenever pin C. 3 is high
and pin C. 2 is low, we would write
April 2014 13
;;;
;;;;;;;;;;;
;;; ;;;;;;;;;;;
,,,; +)('$ *; (&
;*%&*; )((;;*&&; ;;;;;;;;;;;;
;;;;#;; ;;;;;;; ;;
;;;";;;;";;;;;;;
;;;; ;;;; ;;;"();;;;;;;
*0<C;=><982; 19<; 4>=;=4D0;;
;; ; 2,?==;;
<<02? 6,<6C;= 3,:0/;;
;;;;B;;;;;;;B;;;;;;;;;;;
;;;;;;;;;; &%+$&% *'$&;
;;;;;;;;;;;;;;;; ;;;;;;#;
;;;; ;;;;
;;!;;; ;;;;;;;;;;;
;<423>;; 77;;- 6?0; ;;;;7465C;A34>0; 48;
911;=>,>0;;A4> 3;-? 46>; 48;<0= 4=> 9<; 19<; ;*/.;;
" 9;0B>0< 8, 6;<0= 4=> 9<;<0;? 4<0/;;+ 9< 5=;A066;
98;;;;*/.;;;4770<;,>;69A0<;@96>, 20=;;
;411?=0/;;;;E;@40A482;,8260;
;;;;;;;;;;;; ;;F ;;;; ;;;;"(); F ;;;;;"();;F
;;;; ;;;;
;$;; 6,<0;#:> 9;;!H;;#;;;;
;98><96;*96>, 20;;;;;;;*/.
#?>:?>;&,>482;;;;;;;;;;;;;;;
#:> 4.,66C; 4=96,>0/;;:.; 79? 8>;=964/;
=>,>0;<06,C;; ;;B; ;;;B;;;; 77;;;';;;*;;;
;;;;;;;;;;;;;;
;;;"();;;;;;;!
;;;;;,;;;; ;;;; ;;;
;;I;;;;;;;;';;
423;;?, 64>C;
;;;A4/0;;;;:,806;
70>0<;;'964/;:60B4;
26,==;08.69=?<0;;
;;;A4/0;B;;;;;;; 9@, 6;;
&079@0/;1<97;0;?4:708>;
;;;;;;;;;;;;;; ;; ;;;;
;;;;;!;;;;J;
" 4. 34.98;);';;;;;!;;;;(;;
;;);;;;;;*;<,/4, 6;;;;E;;;
;; 77;/4,;;B; 77;6982;;
;; 77;;;;;;;;;.?>; 60,/=;
;;;;;;;;;; ; ; F ;;;;
;;;"();;;F #;;G;;;;"();;;F
;;;;;;;;;;;;;; ;; ;;;
':0.><96;;* 4= 3,C;!9/06;;;;;
; 6?748? 7; 39?=482;;;0<, 74.;
=0,60/;-,. 5;; ;#37;6480,<;
>,:0<;;;;+,>>;;;;;; 16,>>0/;=>, 48;
60==;=>006;= 3,1>;;;;;;;> 3<0,/0/;
-?=3482; 79? 8>;;&079@0/;1<97;
0;?4:708>;A4> 3;= 39<>;A4<0=;
=96/0<0/;> 9;>?<<0>;>0<748, 6=;;!,C; 3,@0;
A< 4>482; 9<;>0=>; 7,< 5=;
;;;;;;;;;;;;;
;;;;;; ; ;;;
;;;;;;;;
;;;- 6,. 5;;;;+;;'*(;
:9A0<;. 9</;;!96/0/;:96,<4D0/;
;:<982;: 6? 2;;!96/0/;=><, 48;
<06401;;$42>, 46; 60,/=;A4> 3;
;;;;;%;;1?66C; 48=? 6,>0/;
.9880.> 9<=;;) ;;;';;
;;;;;;;;;;;;; ;; ;; ;;;;
;;;"();;;;;;! #;G;;;;"();;;;;;!
;;;;;;;;;;;;; ;;;
; 77;;;;;;/4,;;B;;77;
=>0::0<; 79> 9<;;;; 60,/=;;
;;6982;;! 9? 8>482;3960=;98;
; 77;.08>0<=;;;;; 77;/4,;;
> 3<0,/0/;= 3,1>;
;;;;;;;;;;;;;; ;; ;;;;