Strange behavior, can't figure it out

regpye

New Member
I hope someone can help me with this.
The project is a catchment tank for my wife's laundry, she wants to save the water and direct it to some trees in the garden.

I have written a small simple program to control a water pump. In simulation mode it works fine, but in practice it has a strange behavior like switching on and off instead of staying on.
The circuit has 3 float switches. The bottom float switch is used to keep the pump going until the water has been emptied from the tank. The second switch is the high level trigger that turns on the pump. The third and top switch is to show an alarm state if for some reason the water has climbed too high in the tank.

When running on the computer in simulation mode it works flawlessly. the tank can fill, pass the first float switch and when the water level reaches the second float switch, the pump turns on and starts to empty the tank. When the bottom float switch has been reached, a delay timing is used to let a further amount be emptied before shutting off.
The top float switch just turns on a flashing RED LED as a warring.

In practice, the system sort of works, but the pump which is activated by a solid-state relay pulses on and off and doesn't stay on as it should.
In test mode I substituted a LED for the SSR to see how it works, in real life, I have both the SSR and the LED working, but it is pulsing on and off. Tried with the LED only and also the SSR only, same thing happens.

Here is a copy of the BAS file that I wrote, maybe have done something wrong, although in simulation it works fine.

;Pin 3 top float sensor, pin 1 bottom float sensor, pin 0 ?pump? power through solidstate relay, pin 2 ?alarm? LED

start:
low C.0
low C.4
input 2

main:
if pinC.3 = 1 then pump
if pinC.2 = 1 then alarm
goto main

pump:
high C.0
pause 20000 ; tried to give it a pause to keep the pin on longer
if pinC.1 = 1 then pump
if pinC.1 = 0 then pump_off
goto main

pump_off:
for b1 = 1 to 5 ; make a delay to empy tank more before turning off ?pump?
pause 1000
next b1
low C.0
goto main

alarm:
high C.4
for b1 = 1 to 2
pause 5000
next b1
goto start
 

lbenson

Senior Member
Do you have pulldown resistors on your input pins to prevent them from floating? In the range of 10K to 100K.

Inputs don't float in the simulator, but in real life, they do.
 

regpye

New Member
Yes, I am using 10K resistors on all inputs between ground and 1K between input pin and input switch.laundry pump.jpg
 
Last edited:

oracacle

Senior Member
I would suggest that you start by using the sertxd command to send the label back. So after each label send that back ie:
Code:
Start:
   Sertxd("Start",13,10)
Do that for each label and it should give an idea of what is doing on. If you keep getting start you know that something is causing it to restart, either by your calling it in the alarm section or by done other means. This could be further checked by:
Code:
   Sertxd("Calling start",13,10,)
   Goto start
The 13,10 is return line feed which will get the terminal to move to the next line
 

AllyCat

Senior Member
Hi,

To summarise: The LEDs are drawn the wrong way around and there should be capacitors (of at least 100 nF) between pins 1-2 and 3-2 on the 7805 regulator. But the most significant omission is a pull-down resistor on C.5, it can be around 100 kohms and then you can still add on an external Programming Adapter "In Circuit" for development purposes.

But it is very nearly always best to include the programming circuit interface on the board for "In-Circuit Debugging". Then include the following at the top of the Program to confirm that it is not spontaneously re-booting:
Code:
#picaxe 08m2       ; Optional for verification
#no_data           ; Optional to speed downloading program modifications
#terminal 4800
pause 2000         ; Recommended to give the terminal time to start up
#sertxd("Starting ")
Cheers, Alan.
 

regpye

New Member
I have checked using the method described and all seems to be working OK, so I will re-build the electronic circuit and try again.
I may have done something stupid or have a faulty connection somewhere.

The results of the test shows the following, all sections appear to be working fine.

Start
main
main
main
main
main
main
main
main
main
main
main
main
main
main
main
main
pump
pump
pump
pump
pump
pump
pump_off
main
main
main
main
main
main
 

regpye

New Member
Hi,

To summarise: The LEDs are drawn the wrong way around and there should be capacitors (of at least 100 nF) between pins 1-2 and 3-2 on the 7805 regulator. But the most significant omission is a pull-down resistor on C.5, it can be around 100 kohms and then you can still add on an external Programming Adapter "In Circuit" for development purposes.

But it is very nearly always best to include the programming circuit interface on the board for "In-Circuit Debugging". Then include the following at the top of the Program to confirm that it is not spontaneously re-booting:
Code:
#picaxe 08m2       ; Optional for verification
#no_data           ; Optional to speed downloading program modifications
#terminal 4800
pause 2000         ; Recommended to give the terminal time to start up
#sertxd("Starting ")
Cheers, Alan.
Thanks Alan,
I actually use another board for programming that has all the extra bits and pieces.
I have 0.1uF caps between the inputs and outputs of the 7805, just didn't show them on the drawing to reduce clutter.
I will add a pull down resistor at C.5, that may be the problem.
After testing again I see that C.0 cycles on and off in the main section, not sure why that is happening as there are only two jumps in there.
At least I am learning something from this exercise.
 

regpye

New Member
I have reprogrammed a few times and still have a problem although it seems to be working on the screen.
The problem I now have is that C.0 will switch on and off quickly between operations when it should be either on or off. (like a bounce on or off)

This is my latest try to resolve the problem(s)

#picaxe 08m2 ; Optional for verification
#no_data ; Optional to speed downloading program modifications
#terminal 4800
pause 2000 ; Recommended to give the terminal time to start up

start:
Sertxd("Start",13,10)
low C.0
low C.4
input 2 ;make pin 2 input
if pinC.2 = 1 then alarm ;top float switch

main:
Sertxd("main",13,10)
if pinC.2 = 1 then alarm ;top float switch
DO WHILE pinC.3 = 0
LOOP

pump:
Sertxd("pump",13,10)
if pinC.2 = 1 then alarm ;top float switch
DO WHILE pinC.3 = 1
high C.0 ;turn pump on
LOOP
DO WHILE pinC.1 = 1
LOOP

pump_off:
Sertxd("pump_off",13,10)

HIGH C.0
for b1 = 1 to 5 ; make a delay to empty tank more before turning off ?pump?
pause 1000
next b1
LOW C.0 ;switch pump off
goto main

alarm:
Sertxd("alarm",13,10)
high C.4 ;turn on LED indicator
for b1 = 1 to 2
pause 5000
next b1
goto start
 

inglewoodpete

Senior Member
Firstly, please enclose your code in [code] and [/code] tags. It presents your code better and easier for us to read.

The logic in your code does not match the log you have posted. I can't see how you can get a log of "main main main...." The only ways to get out of the 4 lines of code in your "main:" block is a log of "alarm" (which can only return to start: ) or "pump", which can only go to "alarm" or "pump_off".

A problem that I can see is that, if the tank is full (PinC.2), then the Pump will never get turned on.

I suggest you draw yourself an execution flow diagram of what you want and then write the code based on that.
 
Last edited:

regpye

New Member
OK, I have it working now. Between us I worked it out so everything functions correctly. The pump is actually working at this time and watering the garden as I write.
The final code is shown below, I added the missing pulldown resistor for C.5, that was the only change to the circuitry.

Code:
#picaxe 08m2       ; Optional for verification
;#no_data           ; Optional to speed downloading program modifications
;#terminal 4800
;pause 2000         ; Recommended to give the terminal time to start up

start:
Sertxd("Start",13,10)
low C.0
low C.4
input 2 ;make pin 2 input
if pinC.2 = 1 then alarm ;top float switch

main:
Sertxd("main",13,10)

DO WHILE pinC.3 = 0
if pinC.2 = 1 then alarm ;top float switch   
LOOP

pump:
Sertxd("pump",13,10)

DO WHILE pinC.3 = 1
high C.0  ;turn pump on
if pinC.2 = 1 then alarm ;top float switch
LOOP
DO WHILE pinC.1 = 1
LOOP

pump_off:
Sertxd("pump_off",13,10)

HIGH C.0
for b1 = 1 to 5 ; make a delay to empty tank more before turning off ?pump?
pause 1000
next b1
LOW C.0 ;switch pump off
goto main

alarm:
Sertxd("alarm",13,10)
HIGH C.0
HIGH C.4 ;turn on LED indicator
for b1 = 1 to 2
pause 5000
next b1
goto start
 
Top