Variable alias question
Dave W
Posts: 19
Hi,
My first post.· A search didn't turn up anything.· I'm just learning the Stamp Microcontroller and have a couple of homework boards with the Stamp 2 on them.· I've built a device which discharges rechargeable batteries under heavy load, one cell at a time.· It's a very simple program and I do have it working.· It puts a 1 ohm load on the battery and counts the seconds until the cell reaches the 1 volt level.
Now my question.· In order to make the the program readable, I tried to assign the variable name, "LED_Bat_Level" to the OUTB reserved variable.· That works, but only if I use decimal constants for setting the values.· If I try to use binary values (more convenient), the program runs, but the LED which indicates the status of the discharge never turns on.· Here is the code snippet which sets this up:
Red CON 4
Grn CON 1
Off CON 0
LED_Bat_Level VAR OUTB
LED_Bat_Level = Off······ 'turn battery level LED off
It's a bi-color LED and I'm using I/O pins 4 and 6 to drive it.· So, I would like to make Red = %0010 and Grn = %1000.· It's much clearer, at least to me, to do it that way, because I can more easily change the pins I'm using.· The decimal values work, the binary ones don't.· What am I missing?· Right now my controller only discharges one cell.· I plan to add 3 more cells and discharge 4 at a time, all independently, and measure the time it takes each cell to drop to 1 volt.· This tester has already uncovered one NiMh cell out of a 4 cell group which is way too weak to be used.· The other 3 cells are fine.· I think you can see the advantage of using binary numbers to specify the states of the output pins.
I'm sure I'm not using the alias assignment correctly, but just can't figure out what it is.· Can someone give me a hint?· I can easily add the entire program is that's of any value.· If so, should I use the editor file or submit it simply as a text file?· Thanks
Dave W
My first post.· A search didn't turn up anything.· I'm just learning the Stamp Microcontroller and have a couple of homework boards with the Stamp 2 on them.· I've built a device which discharges rechargeable batteries under heavy load, one cell at a time.· It's a very simple program and I do have it working.· It puts a 1 ohm load on the battery and counts the seconds until the cell reaches the 1 volt level.
Now my question.· In order to make the the program readable, I tried to assign the variable name, "LED_Bat_Level" to the OUTB reserved variable.· That works, but only if I use decimal constants for setting the values.· If I try to use binary values (more convenient), the program runs, but the LED which indicates the status of the discharge never turns on.· Here is the code snippet which sets this up:
Red CON 4
Grn CON 1
Off CON 0
LED_Bat_Level VAR OUTB
LED_Bat_Level = Off······ 'turn battery level LED off
It's a bi-color LED and I'm using I/O pins 4 and 6 to drive it.· So, I would like to make Red = %0010 and Grn = %1000.· It's much clearer, at least to me, to do it that way, because I can more easily change the pins I'm using.· The decimal values work, the binary ones don't.· What am I missing?· Right now my controller only discharges one cell.· I plan to add 3 more cells and discharge 4 at a time, all independently, and measure the time it takes each cell to drop to 1 volt.· This tester has already uncovered one NiMh cell out of a 4 cell group which is way too weak to be used.· The other 3 cells are fine.· I think you can see the advantage of using binary numbers to specify the states of the output pins.
I'm sure I'm not using the alias assignment correctly, but just can't figure out what it is.· Can someone give me a hint?· I can easily add the entire program is that's of any value.· If so, should I use the editor file or submit it simply as a text file?· Thanks
Dave W
Comments
There is no problem using binary numbers in constant definitions; I do this all the time.· The BASIC Stamp editor/compiler doesn't care -- no matter what format, a number is a number.
I think the problem that you're having is you're reading the bits left-to-right instead of right-to-left.· Given the values you want to use (Red is %0010 [noparse][[/noparse]P5] and Green is %1000 [noparse][[/noparse]P7]).··Finally, are you initializing the LED pins as outputs?· Before you try to set the LED state, you should have something like this in your program:
· DIRB = %1010
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dave W
HIGH 4
HIGH 6
And do the same things. The 'HIGH' and 'LOW' commands turn the pins into outputs, and 'HIGH' then outputs a 1, and "LOW" then outputs a 0. (Well, actually it doesn't "output" a zero, instead it turns on a transistor which provides a low-resistance path to ground. The result of this is that the signal at the pin goes to ground.
And typically I name my pins, so:
LED_Pin1 CON 4
LED_Pin2 CON 6
HIGH LED_Pin1
HIGH LED_Pin2
All of which would do the same thing, but make it MUCH easier to re-map your pins in the future.
·
· DIRB = %0101
is exactly the same as....
· DIR4 = 1
· DIR6 = 1
except that it only takes one line of code.
DEBUG normally prints characters, so if you're trying to print the value of variables you'll need to use the BIN, DEC, or HEX output modifiers.· Like this:
· DEBUG BIN4 Red
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Thanks again.
Dave W.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax