Can someone check my code?

regpye

New Member
I have written some code and it appears to work fine in the simulator, but in practice, it has a problem. It seems to interfere with another section that as far as I can see there is no connection. Maybe there is a better way to do this coding?

start2: ; check reserve tank level and warn if low

do
if pinC.1 = 0 then ; a float switch that is NO and activates when closed
goto reserve_low
else
goto reserve_hi
endif
loop

;if pinC.1 =0 then reserve_low ; white leads
;if pinC.1 =1 then reserve_hi

reserve_hi:
low F_R_LED ; turn off flashing red LED reserve tank normal
goto start2

reserve_low:
high F_R_LED ; turn on flashing red LED reserve tank low
sound 0, (105,50) ; warning sounds through the piezo speaker
sound 0, (110,50)
sound 0, (115,50)
sound 0, (119,50)
goto start2
 

regpye

New Member
This seems to be a bit cleaner than my first attempt and also seems to work better too;

start2:
do
if pinC.1 = 0 then ; reserve tank low
high F_R_LED ; turn on flashing red LED reserve tank low
sound 0, (105,50) ; warning sounds through the piezo speaker
sound 0, (110,50)
sound 0, (115,50)
sound 0, (119,50)
else ; reserve tank normal
low F_R_LED ; turn off flashing red LED reserve tank low
endif
pause 1000 ; wait 1 second
loop
goto start2
 

micrometal

New Member
It seems to interfere with another section that as far as I can see there is no connection.
You don't really explain what you mean by this.

By the way, it is better if you put code extracts inside "code tags" ...
Code:
start2:
do
if pinC.1 = 0 then ; reserve tank low
high F_R_LED ; turn on flashing red LED reserve tank low
sound 0, (105,50) ; warning sounds through the piezo speaker
sound 0, (110,50)
sound 0, (115,50)
sound 0, (119,50)
else ; reserve tank normal
low F_R_LED ; turn off flashing red LED reserve tank low
endif
pause 1000 ; wait 1 second
loop
goto start2
... click on the ellipsis next to the smiley in the post header and select "</> code".
 
Last edited:

hippy

Technical Support
Staff member
Which PICAXE are you using ?

The M2's support multi-tasking and "start2" is more than just an arbitrary label for those. If it's an M2 then changing to 'xstart2' or something else will probably improve things.
 

regpye

New Member
Which PICAXE are you using ?

The M2's support multi-tasking and "start2" is more than just an arbitrary label for those. If it's an M2 then changing to 'xstart2' or something else will probably improve things.
Yes, Hippy, I should have been more specific.
The code is written for 14M2+ and the code has four sections that all run at the same time.
One section determines if it is night or day and depending on the outcome processes some code to control a pump on and off.
During the day the pump is on, during the night the pump is on for short periods of time and off for longer periods of time.
Checking for night and day continues during this part of the program. There are a number of wait commands in this section.
The second program checks the levels of water in a water tank and if low turns on a water pump and also an indicator LED.
The filling of the tank is extended with a delay time for turning off the pump so that when the float switch triggers activate the pump is not switched on and off quickly as the level reaches the trigger point.
The third program is the one mentioned in the thread that we are on now. Its purpose is to determine the level of a main supply tank (rainwater tank about 5000 l) that is used to top up the smaller tank (half an IBC about 400 L) It just gives a warning if low and makes a sound and switches on a flashing LED There is a short pause in the code to stop switch bounce problems and that is needed and doesn't;t affect the other programs as it is contained in its section of code.
The four program controls an air pump that is timed to switch on and off for so many minutes and then off for so many minutes. It has several wait commands.

All these programs run at the same time and have been working for several weeks without any issues at all, except on occasion something strange happens and the section start2 activates and slows down the whole system and after a while, it reverts back to working normally again. If I trigger the section manually during this time it has no effect. If I turn off the whole system and restart it also has no effect, it just starts all the programs again from the beginning and the start2 section flashes the LED as if the float switch has triggered

I would put the whole code up here if I knew how to do it properly as I am not familiar with the working of this forum yet.
Do I copy the code and place a code marker at the beginning and the end or is there some other way to do it properly?
 

Flenser

Senior Member
regpye,
Two ways to post code

1) You can use the "Insert Code" option from the list of icons at the top of the reply window:
25678

This will open a dialog box where you paste your code.

2) You can use the "Attach files" button at the bottom of the reply window to upload the file with your program:
25679
 

regpye

New Member
I found the problem.
It is not in the coding, but that is working fine.
The problem was a connection to the limit switch that had a stray fine wire that was touching every now and again to short out the switch causing it to trigger. Very hard to see and locate, but common sense lead me to the problem of what else could it be.
Sorry for any inconvenience to you guys. I guess that could also be a lesson for others though.
 
Top