Activity P5 – Interfacing to a serial adc summary: Students will use the BalloonSat

Download 18.02 Kb.
Date conversion13.06.2017
Size18.02 Kb.


a ACES Student Ballooning Course

Programming Unit

Activity P5 – Interfacing to a serial ADC

Students will use the BalloonSat development board to demonstrate synchronous serial communication between the BASIC Stamp micro-controller and the ADC0834 analog-to-digital converter (ADC). An analog voltage signal from a variable power supply or voltage divider will be digitized by the ADC0834 and readout by the BASIC Stamp micro-controller.
Each student team should have the following materials, equipment, and supplies:

1. An assembled and tested BalloonSat development board.

2. Bench power supply capable of supplying 9 to 15 VDC at 100 mA of current.

3. Personal computer with Parallax BASIC Stamp software. Version 2.2 was current as of 08/17/2005. Download from Parallax, Inc. website (

4. Standard 9-pin serial cable.

5. BalloonSat schematic diagram. (BalloonSat Assembly Manual)

6. Manufacturer’s datasheet for the ADC083x family of serial Analog-to-Digital Converters (BalloonSat uses the ADC0834).

7. Variable voltage source, 0 to 2.5VDC (power supply or potentiometer voltage divider).


  1. Setup the BalloonSat development board, appropriate DC power supply and host computer. Verify communication with BASIC Stamp micro-controller.

  1. Referring to the BalloonSat manual, identify the circuit board pads for the analog-to-digital converter inputs. The BalloonSat board has square pads for connecting a voltage source to the individual analog inputs of the 4-channel ADC0834 chip. These are labelled CH0, CH1, CH2 and CH3. You will connect a variable voltage source to ADC CH0 for this exercise. The positive terminal of your voltage source should connect to the CH0 pad and the return lead (or circuit common) must connect to a suitable GND connection on the BalloonSat board (one of the GND testpoints for example).

  2. Refer to the examples in the Parallax “Basic Analog and Digital” Student Guide. Chapter 3 has a detailed discussion using an ADC0831 serial ADC. BalloonSat uses the 4-channel ADC0834 so the details of communicating with the ADC0834 will differ from the examples in the Parallax Student Guide. You will need to specify the correct channel when you write serial I/O routines for your ADC. Refer to the component datasheet for details.

  3. Write a program that will select channel 0, start a conversion cycle and display the results in the debug window. Vary the voltage input to CH0 between 0 and 2.5VDC and observe the converted value. Modify your ADC program to perform a series of A-to-D conversions at a specified time interval (once conversion per second for example) and print the results to the debug window.

Expected Outcome:
Each student should become familiar with synchronous serial communication and write a simple BASIC Stamp program for setting up and reading the ADC0834 serial ADC. The techniques learned will be useful in developing software for balloon payloads where analog-to-digital conversion is needed.
Synchronous serial communications problems are usually the result of incorrect I/O pin selection or improper timing relationship between clock and data lines. A dual-trace oscilloscope is a useful debugging tool for synchronous serial communications problems. Observing the CHIP SELECT, CLOCK, and DATA lines of a serial bus can help identify hardware and software problems.
The ADC0834 ADC datasheet should be carefully reviewed. Pay particular attention to the ADC0834 Timing diagrams and to the MUX addressing tables. In order for the ADC to work properly it must be setup with the correct START BIT and correct channel selection bits. See the hints below.
The ADC0834 requires a reference voltage. On BalloonSat this voltage is generated by the AD780 Precision Voltage Reference U5. The reference voltage can be set to 2.5 or 3.0VDC by jumper JMP2. The reference voltage used determines the full-scale value of the ADC.
CH3 of the ADC can be connected to either the CH3 input pad or to BalloonSat’s temperature sensor. Jumper JMP3 must be placed in the proper position for the function desired.
Be sure to use the proper I/O pins for communicating with the ADC0834. On BalloonSat, Chip Select is P15, CLK is P14 and the DataInOut line is P13. Verify this by referring to the BalloonSat schematic.
To select CH0 and START a conversion cycle your BASIC Stamp program must properly sequence the CLK and DataInOut lines as shown in the ADC0834 datasheet. The following code fragment illustrates one way to do this:




Where CS, CLK and DataInOut have been defined as their respective I/O pins. Mux is a variable which has a value of 12 (or hexadecimal $C) for channel 0. Can you see from the datasheet why mux must be $C for ADC channel 0? The Start bit has a value of 8 and the SGL/DIF bit has a value of 4. The value of mux is then 8 + 4 = 12 or $C. What are the correct values of mux to start conversions using ADC inputs CH1, CH2 and CH3?
An example program that reads ADC Channel 0 can be found at the end of this Activity document.
The code fragment above starts the A-to-D conversion, now the resulting value must be readout by the BASIC Stamp. The code example below is an example for reading the ADC value into the variable “result”.
SHIFTIN DataInOut, CLK, MSBPOST, [result\8]
Use the BASIC Stamp HELP Utility or the Programming Manual for a detailed discussion of the SHIFTOUT and SHIFTIN instructions.
You may construct a subroutine containing the instructions necessary for ADC setup and readout. That subroutine could be called at a period interval and/or executed a specified number of cycles depending on your particular application.
Many applications will require collecting data with BalloonSat then transferring the data to a personal computer for display and analysis. The following sequence of steps illustrates one way to accomplish this.
1. Using the BASIC Stamp Editor write and download a suitable data collection program. This program might, for example, do an A/D conversion every 100 milliseconds, then output the sample number and the A/D converter value as a decimal integer to the DEBUG window. Once the program has been downloaded to BalloonSat, exit the BASIC Stamp Editor on the PC.
2. Run a terminal emulator program such as Hyperterm configured for the proper serial port and communications parameters to be compatible with BalloonSat (9600 baud). As an alternative to Hyperterm, you might want to use a free program called Term232. It can be downloaded from Industrologic, Inc (
3. Restart the BalloonSat. The program you downloaded will now begin execution and the data normally sent to the DEBUG window will be captured by your terminal emulator program. You could copy and paste the data or save it to a file.
4. Use a suitable program to display or analyze your data. For example, the captured data could be imported to a spreadsheet or graphing program.
A useful exercise to demonstrate this technique is to use a function generator as the signal source for BalloonSat’s A/D converter. Be careful to adjust the function generator output to a level safe for BalloonSat. Set the function generator output to be a sine, square or triangle waveform,

collect data and graph the results in Excel. This procedure illustrates the steps required to collect data in an actual payload, retrieve the data and analyze.

BalloonSat Assembly Manual (Includes schematic, parts list, and layout drawing)
Parallax, Inc. Student Guide “Basic Analog and Digital” (on the CD or Parallax website).
Parallax Programming Handbook (
BASIC Stamp Editor software and Help files
Manufacturer’s datasheet for ADC083x family of ADC’s.

EXAMPLE Program to Read the ADC Channel 0

' {$STAMP BS2p}

' {$PBASIC 2.5}

adcBits VAR Byte

v VAR Byte

mux VAR Byte


DataOutput PIN 13
mux = 12 'mux=12 for ADC CH0
DO 'Main Program Loop


GOSUB Display

PAUSE 10 'pause as desired between loop iterations





'Send command to start conversion on ADC CH0

SHIFTOUT DataOutput, CLK, MSBFIRST, [mux\4]

'Now read the resulting value

SHIFTIN DataOutput, CLK, MSBPOST, [adcBits\8]



DEBUG "value = ", BIN8 adcBits 'format the output


LSU 08242005 Programming Unit - Activity P5

The database is protected by copyright © 2016
send message

    Main page