By Jim Anunson email@example.com
Following is information helpful in using the Analog-to-digital converters on the M68HC811 E2 microcontroller chip on the BOT2 board. I spent some time struggling with the program but as usual all seems to make sense now. At the end of this paper is the software in SBasic which programs the BOT2 board enabling four separate channels of analog to digital conversions. The software after being compiled, then assembled and finally downloaded to the BOT2 will continuously resample and display the digital outputs to a terminal and readout the voltages in milli volts. The accuracy is about 100 mv on my board. This ability built into the M68HC811 E2 and others like it is very powerful and simple to use.
Several people have asked how to display this information to a terminal. I will try to explain using three methods.
Method #1 - Just after downloading the program to the BOT2 board using PCBUG11 the terminal displays the ">>" prompt. Just type in "term" and enter and a large box appears on the terminal. In this box will appear all data sent by using the "print" statement of SBasic. After the box appears move the A and B switches on the BOT2 board to OFF and then hit the reset push-button. From that point within the box all data will appear. In my case one row of data appeared as -
--- Jims A/D in mv 0 = 2760 1 = 1960 2 = 1460 3 = 1200 Do Loop 33 ---
Here the A/D channel 0 = 2760 means there is 2.760 volts on the outer pin of the AD0 plug on the BOT2 board. I really have 2.72 volts there as I have the outer pin of the AD0 plug jumpered to my backup battery voltage though a 5 k ohm resistor. Channel 1 & 2 and 3 are all floating at this point. I can move the jumper to the other channels and they will read the 2720 mv +\- 100 mv. When I jumbered the inputs (AD0, AD1, AD2 & AD3) to ground through the 5k resistor each channel read 0 mv while jumbered. 1 = 1960 as indicated in the example above indicates that channel 1 was reading 1.960 volts. In reality that channel had no input and was just floating. The same is true for channel 2 and 3. The Do Loop 33 just means we have looped 33 times in the running program.
I have noticed my terminal sometimes can run 9 seconds or so behind as it tries to keep up.
Method #2 - Use the windows 3.11 Terminal program. The Terminal program is in my Accessory folder. Connect a cable from the BOT2 board DB9F connector to a COM port on the IBM. In the Terminal program select Settings and then select Communications and enter the following.
Baud Rate = 9600
Data Bits = 8
Stop Bits = 1
Parity = none
Flow Control = Xon/Xoff
Connector = Com2: (or the port you use, I use com4:)
Then go to File and then File Save As and save the settings as BOT2.trm or something. When you start the Terminal you can go to File then Open and then double click on BOT2.trm (or something) and the data should appear on the screen.
Method #3 - With the below program loaded into the BOT2 board.
1. Set the BOT2 board A and B switches to ON.
2. Turn on the BOT2 and hit the reset.
3. Start the PCBUG11 using a working macro file.
4. At the >> prompt enter "TERM".
5. Move the BOT2 boards A & B switches to OFF.
6. Hit the BOT2 boards reset switch.
7. Observe the data rapidly displaying in the box of the PCBUG11 program.
Hope all this is helpful! My thanks goes to those who have helped me. Including Tom Dickens, Kevin Ross, Karl Lunt, Marvin Green , and of coarse Motorola.
email - firstname.lastname@example.org
My working SBasic program below.
REM Modified by Jim Anunson Sep 28, 1998
REM Saved to a file called analog.bas
REM This program demonstrates use of the analog to digital converter using the BOT2 board.
REM With a M68HC811E2 chip.
REM Put inputs to ad0, ad1, ad2 or/and ad3 of the BOT2 board.
REM Do not exceed the 5 volt power supply voltage.
REM Began with hercules.bas
Const k = 20 REM Scales output to mvolts. 5v/256 = .020 or 20 mv.
declare ad0 REM ad0 = identification of analog channel 0 on BOT2 board
declare ad1 REM ad1 = identification of analog channel 1 on BOT2 board
declare ad2 REM ad2 = identification of analog channel 2 on BOT2 board
declare ad3 REM ad3 = identification of analog channel 3 on BOT2 board
pokeb spcr, $07 REM SPI OFF
pokeb ddrd, $3F REM Set port D for outputs.
pokeb baud,$30 REM Configure SCI output.
pokeb sccr2,$0C REM Configure SCI output.
pokeb option, %10000000 REM Powers A/D using E clock.
pokeb tflg2, %01000000 REM Timer Interrupt
pokeb tmsk2, %01000000 REM Interrupt request enabled
print " Do loop ";
wait = 0
pokeb adctl, $10 REM multi-chnl, 1-4
waituntil adctl, $80 REM loop until conversion complete
ad0 = peekb(adr1) REM get analog to digital results
ad1 = peekb(adr2) REM get analog to digital results
ad2 = peekb(adr3) REM get analog to digital results
ad3 = peekb(adr4) REM get analog to digital results
Print "Jims A/D in mv 0 ="; REM Print to SCI port
Print ad0*k; REM Print A/D value times k to make reading in mvolts.
Print " 1 =";
Print " 2 =";
Print " 3 =";