18X and setint to count pulses

Simmicht

Senior Member
I have a 18X chip and i want to count the pulses per minute. It should be in the range on about 20 per minute. The problem is, the main loop seems to be not running. I started with the code from the manual SETINT section.

I think I should see this

X.....Count=1
.........Count=2
..Count=3


But nothing inside the loop.
I see this

XCount=1
Count=2
Count=3


It is if the code execution halts at the setint commands until the interupt occurs. Is this the case?


Code:
#PICAXE 18X
#terminal 4800
#no_data


'Pin 1 connected to pulse input to be counted, 
'about 20 pulses per second

'Pin 3 connected to LED, flash each time a pulse is counted

goto example


Example:
sertxd("X")

setint %00000010,%00000010
; activate interrupt when pin1 only goes high
do
'    B1=0
    sertxd(".")
    pause 1000
loop

sertxd("x")


interrupt:

high 3             'flash the LED
inc B1
sertxd("Count=",#B1,cr,lf)
low 3 

do
loop until pin1 <> 1 'loop here until the  interrupt cleared

setint %00000010,%00000010
return
 

Simmicht

Senior Member
solved it. a Duh moment really. the pulse pin is high and goes low briefly...

setint %00000000,%00000010
; activate interrupt when pin7 only goes high
main:
pause 1000 ; wait 2 seconds
sertxd(".")
goto main ; loop back to start

interrupt:
if pin1 = 0 then interrupt ; loop here until the
; interrupt cleared
high 3 ; switch output 1 on
pause 100 ; wait 2 seconds
sertxd("X",cr,lf)
low 3 ; switch output 1 off
setint %00000000,%00000010 ; re-activate interru
RETURN
 
Last edited:
Top