PDA

View Full Version : Need help with BS2pe Motherbard and AVR Analog inputs



Joe Dunfee
12-04-2006, 05:01 AM
I am attempting to use the BS2pe motherboard, with its AVR co-processors to read an analog input.· The manual gives this example;



The following example reads the voltage on Port 0, using Vdd as a reference, and returns the entire 10-bit value:
Voltage VA Word
Busy VAR Bit
OWOUT Owio, 0, [%00001011]
DO : OWIN Owio, 4, [Busy] : LOOP WHILE Busy
OWIN Owio, 0, [Voltage.HIGHGYTE, Voltage.LOWBYTE]


However, when I attempt to run this example, the Basic editor says that Owio is an "unidentified symbol."
Reading the Basic Programming manual, I see that the place where the "Owio" is located is the "Pin" field that should be a value from 0 to 15. So, apparently the example in the manual had already assumed the Owio was a variable set to one of these values.· In my case, I will be using AVR co-processor "A", so I am guessing I should set Owio to be zero, and modified the code as follows (I made other changes to get the stamp to loop and output the readings to serial output pin)


' {$STAMP BS2pe}
Voltage VAR Word
Busy VAR Bit
Owio CON 0
Start:
·OWOUT Owio, 0, [%00001011]
·DO : OWIN Owio, 4, [Busy] : LOOP WHILE Busy· '<<<the·Basic programmer says the "WHILE" expected ":" or a "end of line"
·OWIN Owio, 0, [Voltage.HIGHGYTE, Voltage.LOWBYTE]
·DEBUG Voltage.HIGHGYTE, Voltage.LOWBYTE
GOTO Start


It has been quite a while since I have programmed the stamp, and I have never used the OWOUT or OWIN commands before.· I my understanding of the Owio variable correct?· What am I doing wrong?
Thank You in Advance,
Joe Dunfee

Phil Pilgrim (PhiPi)
12-04-2006, 06:16 AM
Joe,

owio is the pin used by the Stamp to interface with the AVR. For socket A it's pin 10; for B, pin 6. You can use the PIN statment to define it, e.g.:




owio PIN 10




The "Port 0" referred to is an identifier for one of the AVR ports. (See the GPIO3 documentation.) These are A0 to A3 for daughterboard socket A, and B0 to B3 for socket B. A0, A1, B0, and B1 are connected to the AVR chip only. A2, A3, B2, and B3 are shared with Stamp pins.

-Phil

Joe Dunfee
12-04-2006, 11:14 AM
Just to be clear, when I put "Owio" it is all letters. When I put

Owio PIN 10

at the beginning of my program, where I declare the other variables, the interpreter highlights PIN and says "Expected ":" or end of line. I tried substituting the number 10 anywhere the Owio pin declaration is used, but now I get that same "Expected ":" or end of line." statement that I've been getting all along.

Out of concern that the Do While loop has some problem with being placed all on one line, I've divided it up, and now am testing the following version;
============================
' {$STAMP BS2pe}
Voltage VAR Word
Busy VAR Bit

Start:
OWOUT 10, 0, [%00001011]
DO
OWIN 10, 4, [Busy]
LOOP WHILE Busy
OWIN 10, 0, [Voltage.HIGHGYTE, Voltage.LOWBYTE]
DEBUG Voltage.HIGHGYTE, Voltage.LOWBYTE
GOTO Start
======================
However, I get the exact same "expected ":" or end of line." error with the WHILE highlighted.

Joe Dunfee

Phil Pilgrim (PhiPi)
12-04-2006, 12:09 PM
Joe,

You need a PBASIC 2.5 directive in your program. That will clear up the PIN error and also the one-line DO : LOOP and LOOP WHILE issues.
Also, I notice that you've misspelled "HIGHBYTE" in a couple places.

-Phil

Joe Dunfee
12-04-2006, 02:36 PM
Phil, thank you very much. You found the problems and things are working. I was completely ignorant of the pbasic 2.5 version directive issue. I had noticed the Highbyte mispelling, but assumed it was just the way the command expected it. I have now changed it to be HIGHBYTE, and it works.

The bad news is that I checked this message board and found your answer at 1 am sunday night. With the above correction, I think I am finally over the hill, and starting to make progress on my project... now I will have to stay up at least another hour or two, to see it working!

Joe Dunfee