Go Down

Topic: Problems with a code for reservoir filling process (Read 947 times) previous topic - next topic

vasyapypkin

Oct 05, 2012, 03:48 am Last Edit: Oct 05, 2012, 04:00 am by vasyapypkin Reason: 1
Hello,

Currently I am working on a project the purpose of which is to test filling process of a reservoir. Filling process has a medium: an airgap with 3 floating switches: 1. lower level 2. upper level 3. overflow. The way it has to go is I fill an airgap with a city water. Inlet of water is controlled by a solenoid valve (in code - upper_relay; needs to be in LOW state due to SPDT (single-pole-double-throw) relay). Once I reach lower level floating switch, I activate airgap-draining pump (in code: lower_relay, needs to be HIGH). The reality is that airgap pump flow rate is smaller that the one for inlet valve, thus I have evacuate function of level things up. In case water hits overflow floating switch (#3), I drain water up to upper limit floating switch (#2).

While doing all this, I monitor pressure switch, which is mounted inside a big reservoir, which I try to fill up to a certain level (nearly 8 liters). So, once I reached 8 liters, I go to cycle_complete function, where I drain airgap to a lower level floating switch (#1), and then activate another function - chamber_drain which drains the reservoir completely (i.e. all 8 liters).

The code worked fine just before I inserted 2 functions:
1. final drain //to drain airgap to a lower level floating switch #1
2. chamber_drain //to drain 8 liters

These 2 functions are getting called in a cycle_complete function, but they mess up all the code, or cause it to malfunction...

Please help me to understand the reasoning behind it... I've been trying to fix it for over 1 week..

I attached picture with test setup.


The code is attached as well (cannot show it here, since will exceed max limit)

Coding Badly

Code: [Select]
##''cycle_complete''  FUNCTION IS BEING EXECUTED####''bring_back_to_norm''  FUNCTION IS BEING EXECUTED##
##''initial_fill''  FUNCTION IS BEING EXECUTED##
##''regular_fill''  FUNCTION IS BEING EXECUTED##
##''evacuate''  FUNCTION IS BEING EXECUTED##
error in LOOP function: cannot have lower_level=LOW and upper_level=HIGH
raising water level in ''initial_fill''
ps_reading was detected in ''initial_fill'' function
water level was brought to lower level in ''initial_fill''
raising water level and filling chamber in ''regular_fill''
ps_reading was detected in ''regular_fill'' function
water level was brought to upper level in ''regular_fill''
lowering water level for a specified delay time or until hit lower level in ''evacuate''
erial.print ("time elapsed in sec, counter i=
ps_reading was detected in ''evacuate'' function
erial.print ("water level was brought to medium level, after delay in ''evacuate'' #Total evacuation time is (sec):
unexpected result: both or one of ul_reading and ol_reading show(s) LOW in ''bring_back_to_norm'' function
lowering water level in ''bring_back_to_norm''
ps_reading was detected in ''bring_back_to_norm'' function
water level was brought to norm in ''bring_back_to_norm''
erial.print ("check for pressure switch was run 10 times.#The number of closed contact reads is as follows (out of 10):
CYCLE COMPLETE: pressure switch is activated #more than 8/10 readings supported this result ##
CYCLE FAULT: pressure switch reads floating result #less than 8/10 readings were detected ##
Activating ''final_drain'' function#
Activating ''chamber_drain'' function#
#Airgap and chamber were drained. Wait 3 minutes or Press RESET to RESTART#
unexpected result: ll_reading show(s) LOW in ''final_drain'' function
ll_reading shows LOW in ''final_drain''. Water is already below lower level
lowering water level to below lower level in ''final_drain''
water was drained from airgap in ''final_drain''
erial.println("I've been to ''chamber_drain''
draining chamber in ''chamber_drain''
Water was drained from chamber in ''chamber_drain''



That's 2068 bytes worth of string constants.  The processor has 2048 bytes of SRAM.  You are out of memory.

Try wrapping all those string constants with F( "your string goes here" ).  For example...

[font=Courier New]    Serial.println (  F(   "\n\n''cycle_complete''  FUNCTION IS BEING EXECUTED\n\n"  )   );[/font]

vasyapypkin

Quote

That's 2068 bytes worth of string constants.  The processor has 2048 bytes of SRAM.  You are out of memory.

Try wrapping all those string constants with F( "your string goes here" ).  For example...

[font=Courier New]    Serial.println (  F(   "\n\n''cycle_complete''  FUNCTION IS BEING EXECUTED\n\n"  )   );[/font]



Thank you Coding Badly!

That worked. Can you please explain how you calculated number of bytes something takes and also what the F() statement does in:
Serial.println (  F(   "\n\n''cycle_complete''  FUNCTION IS BEING EXECUTED\n\n"  )   );


AWOL

Quote
Can you please explain how you calculated number of bytes something takes

wc?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Coding Badly

Thank you Coding Badly!  That worked.


You are welcome.

Quote
Can you please explain how you calculated number of bytes something takes


One character = one byte.  Used grep to extract the println calls to a text file.  Removed all but the string constants using a simple search-and-replace.  Still using search-and-replaced changed the escapes (\n) to single characters.  Resave the file to disk.  Get the file-size from the operating system (in my case, Explorer).

Quote
and also what the F() statement does in:
Serial.println (  F(   "\n\n''cycle_complete''  FUNCTION IS BEING EXECUTED\n\n"  )   );


The F-macro causes the string to be stored exclusively in program memory (aka Flash or PROGMEM).  The macro is defined here...

https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/WString.h#L36


Go Up