Shop OBEX P1 Docs P2 Docs Learn Events
Running a long program and can't seem to get reading from a sensor continuously — Parallax Forums

Running a long program and can't seem to get reading from a sensor continuously

pimp200277pimp200277 Posts: 22
edited 2007-08-02 10:27 in BASIC Stamp
project: Automated Pool cleaning system
info-
Using· :· LTC1298 A/D
Sensor: Ph sensor

When I run my Ph sensor program sperately from·A long program it works perfectly.
Problem: When I·include the·Ph sensor program into a larger program the values tend to freeze and not vary or just not show up at all.

What I want the result to be: I want the Ph sensor to continuously read and show me the values of the Ph level as it goes through the· larger program. Basically I want the Ph sensor to first take a reading go through the whole program and then take a second reading.


How the·larger program works: Based on the Ph level of the water·the filter will·turn on·and then the· Dispenser will turn on for a certain period of time and then turn·off at the same time the Depenser is on an·Alarm indicating that the Depenser is releasing a liquid into the water goes off. Then·the filter just keeps running for a certain period of time then stops and then the Water level sensor is turned on to·check if the water level is to low·and if it is then a water pump will turn on and run until the water level sensor incidates it's reached a certain level and turn off. Then that's the end of the program.

How I want the program to run:

1.) Take a reading of the pH level
2.) Turn on Filter
3.) Turn on and off Depenser at same time Turn on Water_Alarm
4.) Filter just keeps running for a certain time
5.) Filter Turns off
6.) Water_Level sensor turns on -checks water level if water needs to be added and if needed water pump turns on
7.) Take a reading of the pH level if level is normal then End of program otherwise it will repeat

Ph program by itself:

' {$STAMP BS2}
' {$PBASIC 2.5}
' Pin Assignments
CS····· CON·· 4······· ' Chip Select
DIO_10· CON·· 5······ ' Data I/O pin 10
CLK···· CON·· 6······ ' Clock
' LTC1298 configuration

AD····· VAR·· Word···· ' Variable to hold 12-bit AD result.
config· VAR·· Nib
v······ VAR·· Byte
v2····· VAR·· Byte
pH····· VAR·· Byte···· ' pH value of the water
HIGH CS··············· ' Deactivate ADC to begin.
HIGH DIO_10··········· ' Set data pin for first start bit.
again:
· GOSUB convert···················· ' Get data from ADC.
· GOSUB calc_volt
· DEBUG HOME, "A/D Reading: ",DEC AD,CLREOL,CR
· DEBUG "volt Reading: ",DEC v/100,".",DEC2 v,CLREOL,CR
· DEBUG· "pH Value is: ",DEC pH, ".",DEC2 pH, CR

· PAUSE 500······························· ' Wait a half second.
· GOSUB Filter
·GOTO again······························· ' Endless loop.
Filter:
IF pH > 7 THEN filter_on
IF pH < 8 THEN filter_off
RETURN
filter_off:
HIGH 7
LOW 8
DEBUG "power filter is off", CR
PAUSE 500
RETURN
filter_on:
LOW 7
HIGH 8
DEBUG "Power filter is on ", CR
RETURN
Calc_Volt:
v = 8000 ** AD
v2 = v * 100
pH = v/025
RETURN

convert:
config = config | %1011
· LOW CS·································· ' Activate the ADC.
· SHIFTOUT DIO_10,CLK,LSBFIRST,[noparse][[/noparse]config\4]· ' Send config bits.
· SHIFTIN DIO_10,CLK,MSBPOST,[noparse][[/noparse]AD\12]······ ' Get data bits.
· HIGH CS································· ' Deactivate the ADC.
RETURN···································· ' Return to program.


Whole Program:


' {$STAMP BS2}
' {$PBASIC 2.5}
' Pin Assignments
CS····· CON·· 4······· ' Chip Select
DIO_10· CON·· 5······ ' Data I/O pin 10
CLK···· CON·· 6······ ' Clock
' LTC1298 configuration

AD····· VAR·· Word···· ' Variable to hold 12-bit AD result.
config· VAR·· Nib
v······ VAR·· Byte
v2····· VAR·· Byte
pH····· VAR·· Byte···· ' pH value of the water
cnt···· VAR Word
HIGH CS··············· ' Deactivate ADC to begin.
HIGH DIO_10··········· ' Set data pin for first start bit.
again:
· GOSUB convert···················· ' Get data from ADC.
· GOSUB calc_volt
· DEBUG HOME, "A/D Reading: ",DEC AD,CLREOL,CR
· DEBUG "volt Reading: ",DEC v/100,".",DEC2 v,CLREOL,CR
· DEBUG· "pH Value is: ",DEC pH, ".",DEC2 pH, CR

· PAUSE 500······························· ' Wait a half second.
· GOSUB Filter
·GOTO again······························· ' Endless loop.
Filter:
IF pH > 7 THEN filter_on
IF pH < 8 THEN filter_off
RETURN
filter_off:
HIGH 7
····································· <-- took out Fiter off command out
DEBUG "power filter is off", CR
PAUSE 500
RETURN
filter_on:
LOW·7·········
HIGH 8
DEBUG "Power filter is on ", CR
GOSUB Depenser
RETURN
Calc_Volt:
v = 8000 ** AD
v2 = v * 100
pH = v/025
RETURN

convert:
config = config | %1011
· LOW CS·································· ' Activate the ADC.
· SHIFTOUT DIO_10,CLK,LSBFIRST,[noparse][[/noparse]config\4]· ' Send config bits.
· SHIFTIN DIO_10,CLK,MSBPOST,[noparse][[/noparse]AD\12]······ ' Get data bits.
· HIGH CS································· ' Deactivate the ADC.
RETURN···································· ' Return to program.

Depenser:
HIGH 11
PAUSE· 12000
GOSUB Water_Alarm
RETURN

Water_Alarm:
DEBUG BIN IN11
IF IN11=1 THEN FREQOUT 0, 1500, 2000
PAUSE 50
GoSUB Water_level
GOSUB off
RETURN

Water_Level:
LOW·8···· <-- put Filter off command here
DO
HIGH 9 ' Turn ON the 555.
COUNT 10, 133, cnt ' Count pulses.
'^^
' USE YOUR CONSTANT divided by 10.
LOW 9 ' Turn OFF the 555.
DEBUG DEC cnt, " umho", CR ' Display micromho.
IF cnt > 36 THEN LOW 3 ' Level too high, turn pump off.
IF cnt < 30 THEN HIGH 3 ' Level too low, turn pump on.
LOOP ' Do it again.
RETURN

off:································· <-- program turns off Water_Alarm once depsenser is off
LOW 11
IF IN11=0 THEN LOW 0
END

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-08-02 03:58
    I can't see how either of those two programs will work as you show them. could you attach the actual code you run on the stamp?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-08-02 05:58
    pimp200277 -

    There is no way to exit from the Water_Level routine, so it will loop endlessly there. You either need an IF ... GOTO, a DO ... UNTIL, or LOOP ... UNTIL, or some other branch statement to exit from that routine down to the return statement at the end of that subroutine.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • pimp200277pimp200277 Posts: 22
    edited 2007-08-02 10:10
    BRUE Bates- ok, Since the water_level is at the end of the program I will just change RETURN to END which will end the program
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-08-02 10:27
    Pimp -

    Nope, that won't do it. It doesn't get past the LOOP statement. LOOP sends it back to the DO statement from which there is no escape!

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.