Shop OBEX P1 Docs P2 Docs Learn Events
2 Problems One with Debug comand and other with reading a sensor — Parallax Forums

2 Problems One with Debug comand and other with reading a sensor

pimp200277pimp200277 Posts: 22
edited 2007-06-15 13:13 in BASIC Stamp
Results:

A/D Reading: 1626
volt Reading: 1.98
pH Value is: 7.07
power filter is off

and

A/D Reading: 1673
volt Reading: 2.04
pH Value is: 8.08
Power filter is onf·· <- Problem # 1 : When the pH goes above·8.00 the message suppose to change to "Power filter on" but I don't know why·
················································· the·" f " is still there. Anyone know how I can·get rid of it?

Problem # 2: Does anyone know how I can get the program to change the Value of the " pH " more frequently like how the A/D Reading and volt reading do? What I mean is as my A/D reading changes so does the voltage reading at the same time but with the pH value it's not changing·as fast as the other values do. For example in my above results the A/D reading and voltage reading change only by a little but the pH value jumps from 7.07 to 8.08 instead of gradually increasing. What do you think that problem could be.

Program:
' {$STAMP BS2}
' {$PBASIC 2.5}
' Pin Assignments
CS····· CON·· 9······· ' Chip Select
DIO_10· CON·· 10······ ' Data I/O pin 10
CLK···· CON·· 11······ ' 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
IF pH < 7 THEN filter_on
DEBUG "ph level is greater than 7", CR
RETURN
filter_off:
HIGH 0
LOW 1
DEBUG "power filter is off", CR
PAUSE 500
GOTO again
filter_on:
LOW 0
HIGH 1
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.

Post Edited (pimp200277) : 6/15/2007 8:08:59 AM GMT

Comments

  • metron9metron9 Posts: 1,100
    edited 2007-06-15 12:37
    power filter is off
    Power filter is on

    notice the first statement has 1 extra letter, the "f"

    simply add a space to erase that or clear the screen.

    "Power filter is on "

    It is because the screen is not cleared before writing. I don't use debug much but there may be a clear screen, or clear rest of line command, or you can clear a line using debug " " any number of spaces. If your numbers vary in length you for sure want to make sure you erase the previous numbers for example.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!

    Post Edited (metron9) : 6/15/2007 12:42:14 PM GMT
  • metron9metron9 Posts: 1,100
    edited 2007-06-15 13:13
    IF pH > 7 THEN filter_on
    IF pH < 8 THEN filter_off
    IF pH < 7 THEN filter_on

    The above logic turns the pump on if PH>7 and OFF if PH<7 and the third IF PH <7 never gets executed because the second if PH < 8 is true when PH < 7

    IF pH > 7 THEN filter_on
    IF pH < 7 THEN filter_off

    The code above turns the filter on if PH>7 and back off only when PH<7 It has a built in do nothing or Hysteriesis if the PH=7 so for example, if your number has a resolution of .1 then filter on when PH=7.1 or higher and filter goes off if PH=6.9 or lower, you control the hysteriesis with the resolution of your numbers.

    You are dropping off the lowest bits in your calculation using the ** operator. To increase the resolution you need to keep the lowest bits in the calculation as well.

    The calculations are the same in the code below but you can use this loop to work on your code independently from the ADC readings. It will then be easier to modify your code to get what you want. Substitute your minimum and maximum ADC readings you expect to get in the for next loop, I just picked some numbers. I will need more coffee this morning before actually looking at math problems...

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' {$PORT COM2}
    
    
    
    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
    oldPH   VAR   Byte
    
    FOR AD=500 TO 2000
    
    v = 8000 ** AD
    v2 = v * 100
    pH = v/025
    
    IF oldph<>Ph  THEN
    DEBUG "PH=",DEC PH, ".",DEC2 pH, CR
    oldph=ph
    ENDIF
    
    NEXT
    END
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
Sign In or Register to comment.