'{$STAMP BS2SX} '' '' Programmer: Craig Stuart Sapp '' Creation Date: Mon Oct 16 15:52:44 PDT 2000 '' Last Modified: Mon Oct 16 16:13:52 PDT 2000 '' Filename: midi8.bsx '' Based On: midi1270.bsx, max1270.bsx, cout.bsx '' Syntax: Basic Stamp IIsx '' '' Description: This program is a variation on midi1270. Data from all '' 8 channels of the Maxim 1270 are sampled and sent via MIDI using the '' command 0xA0. The first parameter MIDI byte specifies the channel number '' (0-7) and the second parameter byte gives the sampled data variable. '' sleeptime con 10 ' time in milliseconds to wait between sensor samples ' Data Variables: channel var byte ' for holding first MIDI parameter byte (sensor chan.) bytea var byte ' for holding first 7 MSBs of 12-bit sample byteb var byte ' for holding 5 LSBs of 12-bit sample (ignored) ' MIDI output variables midicommand con $A0 ' use MIDI aftertouch command to send sensor data midioutpin con 7 ' output pin on which to send MIDI data midirate con 60 ' baude mode for serout: (2500000/31250)-20 msec ' note that this value should be 12 for BS2. ' Serial rate for MIDI is 31,250 data bits/sec. outpause con 0 ' pause time in units of 0.4 millisec between bytes. ' On the BS2, units are 1.0 millisec. A value of ' zero means do not pause between successive MIDI ' bytes when sending arrays of MIDI data. ' Maxim 1270 chip variables clockpin con 11 ' synchronous clock pin to control MAXIM 1270 chip cspin con 10 ' chip select pin for MAXIM 1270 (only needed if more ' than one chip) outputpin con 9 ' for sending the controlbyte to the MAX1270 chip inputpin con 8 ' for reading data from MAXIM 1270 chip 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: basiccontrol con %10000001 controlbyte var byte ' variable for adding channel to basiccontrol ' 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: for channel = 0 to 7 gosub ReadSensorData ' take a sensor reading on specified channel gosub SendSensorData ' send reading out via MIDI next ' wait a while before taking another sample pause sleeptime goto top '''''''''''''''''''''''''''''' '' '' ReadSensorData -- sends a command to the A/D converter chip '' requesting data. Then reads the returning data and stores '' the 7 most significant bits in bytea variable and the 5 '' least significant bits in the byteb variable. '' ReadSensorData: ' create the control byte with the specified channel to sample controlbyte = basiccontrol ^ (channel << 4) ' clear the storage bytes for sensor data bytea = 0 byteb = 0 ' first tell the MAX1270 that you want a sample 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 \ 7] ' finish reading in the data (12-bit sample) shiftin inputpin, clockpin, behindclock, [byteb \ 5] ' debug dec ? bytea ' debug dec ? byteb ' debug cr return '''''''''''''''''''''''''''''' '' '' SendSensorData -- send sensor data via a MIDI command through '' a TTL (5 volt) serial line at 31.25 kBit speed. '' SendSensorData: serout midioutpin, midirate, outpause, [midicommand, channel, bytea] return