Help Testing a Program
nab014
Posts: 22
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
' {$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
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:
Post Edited (Mike Green) : 2/3/2008 11:02:07 PM GMT
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.
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!