Shop OBEX P1 Docs P2 Docs Learn Events
Help Testing a Program — Parallax Forums

Help Testing a Program

nab014nab014 Posts: 22
edited 2008-02-04 06:27 in BASIC Stamp
I'm writing a program and need a little help. The system I'm working with collects a value and then activates different things according to that value. Is there a way to declare the initial value in the programing when I'm testing the system?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-03 22:42
    How about an assignment statement at the end of your initialization section that sets your value to whatever you need for testing, then a GOTO that bypasses the part of your code that normally collects a value and just goes to the part of your program that activates something?
  • nab014nab014 Posts: 22
    edited 2008-02-03 22:46
    I'm fairly new to all this.....just a college student trying to use the boe-bot for this project. Could you put that in more layman's terms? I've pasted my program below as well if that helps.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    Salinity VAR Word
    Temperature VAR Word

    DEBUG CRSRXY, 0, 0,
    "Status of Salinity Tank Project", CR,
    "
    ", CR,
    "Tank Salinity = ", CR,
    "Salt Water Solenoid = ", CR,
    "Deionized Water Solenoid = ", CR,
    "Heating Element = ", CR

    COUNT 9, 1000, Salinity

    DO
    'Salinity Value
    DEBUG CRSRX, 16, 2, Salinity, " "
    IF (Salinity > 4409) THEN
    DEBUG CRSRX, 22, 3, "Open"
    'Salt Water Solenoid Status
    HIGH 0
    PAUSE 1000
    LOW 0
    RETURN
    ELSEIF (Salinity < 1250) THEN
    'DI Water Solenoid Status
    DEBUG CRSRX, 26, 4, "Open"
    HIGH 1
    PAUSE 1000
    LOW 1
    RETURN
    ELSEIF (150 < Salinity < 400) THEN
    COUNT 9, 1000, Temperature
    IF (Temperature < 80) THEN
    'Heating Element Status
    DEBUG CRSRX,18, 5, "Heating"
    HIGH 9
    PAUSE 10000
    LOW 9
    RETURN
    ELSEIF (Temperature > 120) THEN
    RETURN
    ENDIF
    ENDIF
    LOOP
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-03 22:56
    You need to go back and read the Basic Manual first so you understand the various control statements.
    In particular, you have a bunch of RETURN statement and no GOSUB statement. Where would the
    RETURN statement return to? The IF statement with "150 < Salinity < 400" won't work as you expect
    either. It first calculates "150 < Salinity" which results in a false (0) or true (1) answer. Since both are
    less than 400, the IF statement will always be successful.

    Download the "What's a Microcontroller?" tutorial and work through the programming examples first.
    You can get that by going to the main Parallax website, then choosing "Downloads", then "Stamps in
    Class Tutorials", then you'll see "What's a Microcontroller?" as well as other useful tutorials.

    When you want to post some code, please try to use indenting to show what statements are related
    to what. If you do have indenting, you need to remember that the forum software will ignore it unless
    you surround your code with "code tags". These consist of the word CODE contained in square brackets
    as the opening tag, then the word /CODE in square brackets as the closing tag. For example:
    Here's some code
       indenting
    

    Post Edited (Mike Green) : 2/3/2008 11:02:07 PM GMT
  • nab014nab014 Posts: 22
    edited 2008-02-03 23:19
    Thanks for the help! I forgot about the GOSUB routines, they make the program much easier to read. I also changed the "150 < Salinity < 400" part to just a blank, I believe that will make the program respond if the salinity value lies in between the two values. Does everything look better?

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    Salinity VAR Word
    Temperature VAR Word
    
    DEBUG CRSRXY, 0, 0,
          "Status of Salinity Tank Project", CR,
          "-------------------------------", CR,
          "Tank Salinity = ", CR,
          "Salt Water Solenoid = ", CR,
          "Deionized Water Solenoid = ", CR,
          "Heating Element = ", CR
    
    COUNT 9, 1000, Salinity
    
    DO
    DEBUG CRSRX, 16, 2, Salinity, " "
        IF (Salinity > 4409) THEN
          GOSUB Salt_Water_Solenoid
        ELSEIF (Salinity < 1250) THEN
          GOSUB DI_Water_Solenoid
        ELSE
          GOSUB Heater
        ENDIF
    LOOP
    
    Salt_Water_Solenoid:
    DEBUG CRSRX, 22, 3, "Open"
      HIGH 0
      PAUSE 1000
      LOW 0
      RETURN
    
    DI_Water_Solenoid:
    DEBUG CRSRX, 26, 4, "Open"
      HIGH 1
      PAUSE 1000
      LOW 1
      RETURN
    
    Heater:
    COUNT 9, 1000, Temperature
            IF (Temperature < 80) THEN
              DEBUG CRSRX,18, 5, "Heating"
              HIGH 9
              PAUSE 10000
              LOW 9
            ELSEIF (Temperature > 120) THEN
            ENDIF
    
    
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-03 23:31
    The formatting looks nicer and the GOSUBs help. You're still missing a RETURN at the end (for Heater).
    The COUNT statement that reads the salinity is outside the DO/LOOP. Your program will read the
    salinity once, then repeat the same action over and over again without reading the salinity value again.

    For testing purposes, you may want to hook up a variable resistor to an extra I/O pin and use the RCTIME
    statement to read its value instead of the salinity sensor. Read the section on the RCTIME statement in
    the Basic Manual and in What's a Microcontroller? If you do that, you will be able to try the program with
    different values.

    An alternative would be to use the DEBUGIN statement as a temporary replacement for the COUNT statement.
    This would let you enter values from the debug window of the Stamp Editor for testing. Read the chapter on
    DEBUGIN for more information.
  • nab014nab014 Posts: 22
    edited 2008-02-04 01:04
    Thanks! I fixed the RETURN error in the Heater subroutine. I'm trying to write the DEBUGIN part but I'm having some problems. I can't get the system to work properly if the command to read the salinity from the sensor is still in there so I took it out. I replaced it with the DEBUGIN command and everything works great except for on the DEBUG screen. The values show up and the system works but the values show up in the wrong places....not even close to where they need to be. Any suggestions?

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    Salinity VAR Word
    Temperature VAR Word
    
    DEBUG CRSRX, 0, 0,
          "Status of Salinity Tank Project", CR,
          "-------------------------------", CR,
          "Tank Salinity = ", CR,
          "Salt Water Solenoid = ", CR,
          "Deionized Water Solenoid = ", CR,
          "Heating Element = ", CR
    
    
    
    
    DO
    
    DEBUGIN DEC Salinity
    
    DEBUG CRSRX, 16, 2, Salinity, " "
        IF (Salinity > 4409) THEN
          GOSUB Salt_Water_Solenoid
        ELSEIF (Salinity < 1250) THEN
          GOSUB DI_Water_Solenoid
        ELSE
          GOSUB Heater
        ENDIF
    LOOP
    
    Salt_Water_Solenoid:
    DEBUG CRSRX, 22, 3, "Salt Solenoid Open"
      HIGH 0
      PAUSE 1000
      LOW 0
      RETURN
    
    DI_Water_Solenoid:
    DEBUG CRSRX, 26, 4, "Deionized Solenoid Open"
      HIGH 1
      PAUSE 1000
      LOW 1
      RETURN
    
    Heater:
    COUNT 9, 1000, Temperature
            IF (Temperature < 80) THEN
              DEBUG CRSRX, 19, 5, "Heating"
              HIGH 9
              PAUSE 1000
              LOW 9
            ELSEIF (Temperature > 120) THEN
            ENDIF
            RETURN
    
    
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-02-04 06:27
    Nab014 -

    The control of the cursor on the DEBUG screen is effected by the DEBUG modifier "CRSRX", which decoded into English means - set cursor to X column and Y row, or in other words, X column and Y line. The complete description of the DEBUG command and all its various modifiers can be found in the PBASIC Reference Manual, or the PBASIC Help File. Here is part of that documentation to get you started:

    quote

    Since individual DEBUG instructions can grow to be fairly complicated, and since a program can contain many DEBUGs, you'll probably want to control the character positioning of the Debug Terminal screen. DEBUG supports a number of different control characters, some with pre-defined symbols. The Debug Terminal in the Windows® version of the editor supports all the control characters shown below, while the DOS version only supports a few of them.

    Some of the control characters have pre-defined symbols associated with them. In your DEBUG commands, you can use those symbols, for example: DEBUG "Hello", CR displays "Hello" followed by a carriage return. You can always use the ASCII value for any of the control characters, however. For example: DEBUG "Hello", 13 is exactly the same as the code above.

    [noparse]/noparse][b]Ed. Particularly note below[/b

    The Move To control character is perhaps the most unique of the set. If the Debug Terminal receives this character, it expects to see an x and y position value to follow (in the next two characters received). The following line moves the cursor to column number 4 in row number 5 and displays "Hello":

    · DEBUG CRSRXY, 4, 5, "Hello"

    The upper-left cursor position is 0, 0 (that is column 0, line 0). The right-most cursor positions depend on the size of the Debug Terminal window (which is user adjustable). If a character position that is out of range is received, the Debug Terminal wraps back around to the opposite side of the screen.

    The Clear EOL (end of line) control character clears the characters that appear to the right of, and on, the cursor's current position. The cursor is not moved by this action.

    end quote

    You also may want or need to use the DEC modifier to more properly format both the salinety and temperature variables since they are both of WORD size.

    The trick here is to use a piece of grid paper (aka graph paper)·to layout what you want to do before trying to write or modify any of the present DEBUG statements. Then you can compare what is in the program vs. what you feel it should be. Note what is in the program presently, make your changes, and see how it relates to what you have on your grid paper. They SHOULD be the same, but if they are not, you can:

    · a) return the values to what they were prior to the change,

    ····· OR

    · b) view the original format vs. the·new format vs. your grid paper layout

    Using this debugging technique you should be able to see,·rather quickly,·how changing the CRSRX parameter is affecting the DEBUG data layout, and make your changes accordingly. I hope this helps to get the formatting straightened out in short order.

    Regards,

    Bruce Bates


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There is no pleasure in having nothing to do;
    the fun is in having lots to do, and not doing it!
Sign In or Register to comment.