Flow meter using 2 interupts and pulses

troyjcm

New Member
Hi,

I have a beer bottle filler with a beverage flow meter and a valve to start and stop flow of beer into the bottle. The beer flow stops when the correct volume of beer has passed through the flow meter.

When a "programming" switch is cosed on power up the beer valve opens there is a setint command to use interupt and increment pulses from the flowmeter until the switch is open again. This is for the user to use the write command to store how much beer/how many pulses are to flow through the meter by filling a bottle and releasing the switch when the liquid reachs the right level in the bottle. The required volume for main use has been determined.

The program then has a main section where the interupt is used again to determine how many pulses there have been when the beer valve opens. When the incremented pulses exceed the number written to memory the beer valve closes.

The problem I have is that there are duplicate interupt labels even though the first interupt is not needed as part of the main program. Once the inital pulse count is done and written to the memory it is not part of the rest of the program and not needed. I could have 2 chips but is there a simple solution?


Many thanks

Phil


#slot 0

init: pause 500



Symbol Cylinder = b.1
Symbol CO2 = b.2
Symbol Purge = b.3
symbol Beerin = b.4
Symbol Startbutton = Pinc.1
Symbol Program = Pinc.4
Symbol Flow = pinc.0



Start:

low b.1
low b.2
low b.3
lowb.4

let b0 = 0

if Program = 1 then goto Preset ;preset the desired pulses/volume of beer
if Program = 0 then goto Main ; go to main filling program

Preset:

setint %00000001,%00000001,C ; interrupt when pinC.0 flow goes high

Preset2:

high B.4 ; switch output B.4 beerin high

if Program = 0 then goto Main
goto Preset2 ; loop back to start


interrupt: Let b0 = b0+1 ; increment b0 with each interupt
write b0, w2 ; write pulses to memory

setint %00000001,%00000001,C ; re-activate interrupt
return ; return from sub



Main:

If Pinc.1 = 1 then goto Main1
If Pinc.1 = 0 then goto Main

Main1:

setint %00000001,%00000001,C ; interrupt when pinC.0 goes high

Main2:

high B.4 ; switch output B.4 beerin high
goto Main2 ; loop back to start


interrupt: Let b1 = b1+1 ; increment b0 with each interupt
if b1 > w2 then low B.4:goto Main endif ;if current pulses exceed save memory pulses then turn off beer flow

setint %00000001,%00000001,C ; re-activate interrupt
return ; return from sub
 

AllyCat

Senior Member
Hi Phil,
Code:
interrupt:
      Let b1 = b1+1            ; increment b0 with each interupt
      if b1 > w2 then          ; if current pulses exceed save memory pulses then turn off beer flow
             low B.4 : goto Main       ; "ILLEGAL"
       endif
       setint %00000001,%00000001,C    ; re-activate interrupt
return                ; return from sub
Hi,

Welcome to the forum ... or a first post after 8 years? ;)

It would be helpful to specify the PICaxe you're using and to put your code within [code ] .. [/code] tags, but it looks as if it must be a 28 or 40X2? But I'm afraid there seems to be quite a lot "wrong" with at least the interrupt section(s) of the program. Firstly, wrong comments are probably worse than NO comments: b1 = b1 + 1 doesn't increment b0 and is it supposed to be a RETURN from a subroutine or from an interrupt routine? Also the goto Main is jumping OUT of the routine (be it subroutine or Interrupt) which may cause "problems" (you should always exit only via the RETURN). And the if b1 > w1 is "suspicious" because b1 can only have a value up to 255, whilst w1 can be up to 65535, so w1 is more likely to exceed b1 than vice versa.

But the fundamental issue is that "interrupt:" is a "global" label, so you can have only one (how did it get past the syntax check?). If you really need more than one type of interrupt, then the interrupt routine itself must decide (normally at the entry point) what caused the interrupt and/or what it is required to do. Typically, you would set up a "flag" (perhaps b0 = either 0 or 1, or maybe bit0 = 0 or 1 if there are only two possibilities) which indicates what the interrupt is expected to do (next). The flag might be set up by the interrupt routine itself, before it RETURNs (via a legitimate route :) ) , or in some other part of the program. Or maybe it's your "Program1" ?

I think that's probably enough for now. ;)

Cheers, Alan.
 
Top