Digital Music Programming II: flex sensor continuous controller
This lab demonstrates how to read a variable resistance and extract continuous control data from a sensor using an A/D converter. In this case a flex sensor is used as the sensor. The flex sensor was first used commercially in the Power Glove (1989) by Mattel for Nintendo games where the sensors were used to monitor the positions of the human hand for display in realtime on a TV screen.
In the rcfsr you learned how to use an RC circuit to measure the resistance of a potentiometer (in that case, a force-sensing resistor). The measurement was done by measuring the discharge time of the capacitor after charging it for 1 millisecond.
A more sophisticated and faster method for measuring the resistance of a potentiometer is to use an A/D converter. In this case we will use the Maxim MAX1270 8-channel, 12-bit A/D converter, although most any will work, depending on your application criteria.
The MAX1270 takes a measurement of the voltage on each channel in 3 microseconds or less, and has a maximum sampling rate of 110,000 samples per second (which is faster than the Basic Stamp and MIDI can process). The input voltages can range between +/- 16.5 volts, and the expected voltage range can be programed to: -10/+10, -5/5, 0/10 or 0/5.
Here is a schematic of the circuitry connecting the MAX1270 A/D converter to the Basic Stamp IIsx for use with this program:
The Basic Stamp and the MAX1270 chip use serial communication to talk to each other. To read a sample, you send a control byte to the MAX1270 telling it which channel to measure, and what voltage range to use. The Basic Stamp then receives the measured data from the MAX1270 chip.
Communication between the Basic Stamp and MAX1270 is done synchronously. The MAX1270 is a slave to the Basic Stamps clock which is sent out on P11 from the Basic Stamp and received on pin 5 of the MAX1270. Any clock speed up to 2.0 MHz can be used to communicate with the MAX1270.
Multiple MAX1270 chips can all share the same three wires of clock, digital input and digital output. Each must have a separate Chip Select connection to the Basic Stamp. When the Basic Stamp wants to use a particular MAX1270 chip, it sets the Chip Select connection to 0 volts. This activates that particular chip for use on the other three wires. In this way, you can (easily) hook up 8 MAX1270 chips (64 sensor inputs total), plus one MIDI output on one Basic Stamp.