'{$STAMP BS2SX} '' '' Programmer: Craig Stuart Sapp '' Programmer: Florian Vogt '' Creation Date: Sat 10-23-1999 '' Last Modified: Sat 10-23-1999 '' Filename: max1270.bsx '' Syntax: Basic Stamp IIsx '' '' Description: This program reads in samples from the '' Maxim 1270 (a 12-bit, 8 channels A/D chip). '' The sampled value is then printed on the computer screen. '' clockpin con 7 ' synchronous clock pin to control MAXIM 1270 chip inputpin con 8 ' for reading data from MAXIM 1270 chip outputpin con 9 ' for sending the controlbyte to the MAX1270 chip sleeptime con 250 ' time in milliseconds to wait between samples msb con 1 ' mode for shiftout functions: msb behindclock con 2 ' mode for shiftin: msb post clock ' the MAX1270 control byte below is composed of several fields ' listed here from MSB to LSB bits: ' bit7: defines the beginning of the control byte ' bits4-6: selects the A/D channel (0-7). ' bit3: choose the A/D voltage range, 0=5v, 1=10v ' bit2: choose polar/bipolar range, 0=positive, 1=positive/negative ' bit0: choose clock mode: 0=internal, 1=external ' bits0-1: 10=standby, 11=power-down (clock mode unaffected) ' ' the control byte 1,000,00,01 means: channel 0, 0 to +5v, external clock: controlbyte con %10000001 ' Variables: bytea var byte ' for holding first 8 MSBs of 12-bit sample byteb var byte ' for holding 4 LSBs of 12-bit sample ' According to BASIC Stamp Programming Manual v1.9, page 208: ' "Unused pins that are not connected to circuitry should be set to output" ' to minimize power consumption, which is done here: DIRS = %1111111101111111 ' Don't set pins connected to input circuitry to be output, or you can ' damage the Basic Stamp. ' Commands used below: ' ' SHIFTOUT outputpin, clockpin, mode, [data \ bits] ' outputpin = pin to send synchronous data on ' clockpin = pin to send synchronous clock signal ' mode = 0=LSB, 1=MSB ' data = data to send ' bits = number of bits in data field to send (default = 8); ' ' SHIFTIN inputpin, clockpin, mode, [variable \ bits] ' inputin = pin to receive synchronous data on ' clockpin = pin to send synchronous clock signal ' mode = 0=LSB, 1=MSB ' variable = location to store the bits ' bits = number of bits to input (default = 8); ' top: ' first tell the MAX1270 that you want a sample from channel 0 shiftout outputpin, clockpin, msb, [controlbyte \ 8] ' wait 4 clock cycles until the sample is ready to be returned shiftout outputpin, clockpin, msb, [0 \ 4] ' read in the returned sample from the MAX1270 chip shiftin inputpin, clockpin, behindclock, [bytea \ 8] ' finish reading in the data (12-bit sample) shiftin inputpin, clockpin, behindclock, [byteb \ 4] debug dec ? bytea debug dec ? byteb debug cr ' now wait a while before taking another sample pause sleeptime goto top: