Counting pump cycles

Tyro

Member
I have a system with a number of pumps, water tanks and float switches controlled by a 18M2. The software works correctly. I continuously scan the float switches and switch the pumps on and off as required. No problems.

I want to count the number of times a particular pump is switched on and off and after a preset number of times I want to do another action then reset the count to zero and start again.

Any ideas?
 

Goeytex

Senior Member
This should be relatively simple. However, we need to see your existing code in order to offer specific help.
 

Tyro

Member
I do not understand why you need to see the code. This code is a sample portion of the total. I generate small snippets of code, get it to work then add everything together and do a final debug. I just want a count of how many times a pump, 'batchp' in this case has cycled ON and OFF.

'18m2

symbol cycles = b0
symbol batchcycles = b1
symbol bkwshnum = b2

symbol ClarV = b.0
symbol Inp = b.1
symbol Batchp = b.2
symbol Bkwshp = b.3
symbol Resp = b.4

symbol BatchHI = pinc.0
symbol BatchLO = pinc.1
symbol SandLO = pinc.2
symbol ResHI = pinc.5
symbol ClarLO = pinc.6


low ClarV

let bkwshnum = 4

main:
gosub batchpump


goto main


BatchPump: 'This controls batch tank fill

if batchLO = 0 and ClarLO = 1 then pause 10 'water level low AND clarifier OK
endif
if batchLO = 0 and ClarLO = 1 and batchcycles < bkwshnum then high Batchp 'Batch pump ON
endif

' if batchcycles >= bkwshnum then Backwash

if batchHI = 1 or ClarLO = 0 then pause 10 'Batch water level full OR clarifier low water
endif
if batchHI = 1 or ClarLO = 0 then low batchp 'Batch pump OFF
endif



return
 

clonetwo

New Member
hi, maybe i can suggest some ideas.
a question first.

Do you want to be able to read/see the number of times the pump was shut off for records?
or
do you want to use that number in your code? (ok i see you want to use it in your code)

How many times do you expect the pump to be cycled on/off? this will help you decide
if you should use a bit, byte or word. (Variables - General page 10 in PICAXE_manual2)
www.picaxe.com/docs/picaxe_manual2.pdf

In the area of the code that shuts the pump off is where you should count because you can only shut off what
was on to start with.

and if you want to retain that number in memory if after power is off then you should store it in the eeprom
of the PICAXE. the command is page 61 or 62



note* im going to use a word in this pseudo example:
IF YOUR WORD OR BYTE IS LARGER THEN IT SHOULD BE YOUR CHIP MAY LOCK UP AND WILL NEED TO BE RESET.
so make sure you have something that can reset the value of the integer before it goes over

Byte variables can store integer numbers between 0 and 255
Words are capable of storing integer numbers between 0 and 65535

Code:
symbol PumpCycleCount = w2  '  w2 is also b5 and b4
symbol PresetNumber = w3      '  w3 is also b7 and b6 
PresetNumber = 5 'or any other number you need


...

if batchHI = 1 or ClarLO = 0 then 
low batchp	 'Batch pump OFF

PumpCycleCount = PumpCycleCount  + 1 ' this will make a counter for the pump cycles. 

     if PumpCycleCount  = PresetNumber  then 
           PumpCycleCount  = 0 
           goto DoAnotherAction
      endif
 
endif
return

DoAnotherAction:
other action code
...
return
I hope this helps
Regards from MN, USA :D
 
Last edited:

Tyro

Member
I only want to use the count number in my code. This number will be small, typically less than 10.

The very simple command;

PumpCycleCount = PumpCycleCount + 1 ' this will make a counter for the pump cycles.

does not work. The code cycles through this loop hundreds of times a second, each time incrementing the PumpCycleCount. That is the problem, the pump only turns off once but the code cycles many times. I need to increment the PumpCycleCount once every time the pump cycles both ON and OFF.
 

Buzby

Senior Member
Your code needs to 'remember' that it has counted a pump on signal, so it won't keep adding to the PumpCycleCount every loop.

Define a new variable call CountDone, then try these mods :

Code:
if batchLO = 0 and ClarLO = 1 and batchcycles < bkwshnum then 
     high Batchp 'Batch pump ON
     If  CountDone = 0 then 
         PumpCycleCount = PumpCycleCount + 1
         CountDone = 1
     endif
endif

.
.
.

if batchHI = 1 or ClarLO = 0 then 
  low batchp 'Batch pump OFF
  CountDone = 0
endif
 

clonetwo

New Member
does this help?
This code will only turn the pump ON if it's off and OFF if it's on.
and count every time the pump has changed state.

i think your code was telling the pump to turn on even if it was on already and also with off.

also, you might only want the code "batchcycles = batchcycles + 1" once.
I would put it in the pump off code and not the pump start code as i have done in example.
or you can could, "let bkwshnum = 8" instead of 4 and leave the code as is.

when you gosub Backwash , you can change the pump to the state you need and also check any other states required.




Code:
main:
gosub batchpump    


goto main


BatchPump:    'This controls batch tank fill

if batchLO = 0 and ClarLO = 1 then 
    pause 10     'water level low AND clarifier OK
    if batchcycles < bkwshnum then 
        if pinb.2 = 0 then 'check to see if pump is off
            high Batchp    'Batch pump ON
            batchcycles = batchcycles + 1
        end if
    end if
endif

    if batchcycles >= bkwshnum then Backwash

if batchHI = 1 or ClarLO = 0 then 
    
    pause 10     'Batch water level full OR clarifier low water
    if pinb.2 = 1 then 'check to see if pump is on
        low batchp     'Batch pump OFF
        batchcycles = batchcycles + 1
    end if
endif



return

Backwash:
batchcycles = 0
I hope i'm understanding what you need.
clonetwo
 
Last edited:
Top