microchip pic 16C73A The following is an example of a typical microcontroller application used by Richard Prince in "The Aurora on All Three Channels". The microcontroller is used to convert light collected by photodiodes into a voltage proportional to the light intensity. This voltage is sampled by an analog-to-digital converter in the Microchip PIC 16C73A microcontroller. In response to the changing input levels, a program running on the microcontroller sets the duty cycle of a 78 kHz pulse-width modulated output which is filtered by an RC filter into an audio-frequency waveform. This audio signal is amplified and drives headphones. An LM324 quad op-amp is used to buffer the photodiode signals. software The behaviour of the light-to-sound converter is defined by a computer program. Every 125 microseconds the program reads the three analog inputs and computes the corresponding value of the sound output. The sound is generated by adding three sine wave signals. The frequency of the first signal varies with the level of light 2 and ranges from 520 to 720 Hz. The frequency of the second signal is offset from the frequency of the first by a frequency difference that varies between -10 and +10 Hz depending on the level of light 1. This frequency offset produces a "beating" effect. The first two signals are summed and scaled by a value, set by the level of light 3, between 0.5 and 1.5. The frequency of the third signal varies from 260 to 360 Hz and is also controlled by the level of light 3. In addition, its frequency is varied by +/- 65 Hz by a slowly-changing pseudo-random (noise) value. The software is optimized so that the microcontroller can generate an output sample every 125 microseconds: the oscillators use pre-computed cosine tables, the noise is generated using a 15-bit maximal-length pseudo-random bit sequence (PRBS) generator, and almost all multiplications are converted to combinations of shifts and adds (which the microcontroller can do more efficiently than multiplication).
circuit Each of the three photodiodes is connected in series between +5 V and a 1 M ohm potentiometer to ground. The potentiometer forms a voltage divider that allows the current-to-voltage gain for each photodiode to vary from 0 to 1 volt/microamp. The voltage divider output is buffered by unity-gain op-amp circuit and is connected to one of three analog inputs on the microcontroller. The +5V supply limits the LM324 op-amp buffer output to about 3.8 V maximum. The A/D voltage reference input (VREF) is set by a voltage divider consisting of a 3.3k resistor in series with a 10k potentiometer. This sets the maximum reference voltage to about 3.8 V. The microcontroller's pulse-width modulated output is filtered by an RC (R=500k, C=0.47uF, RC=0.24s) low-pass filter and buffered by a unity-gain op-amp. The buffer output is AC-coupled to the (high-impedance) audio output. An external low-pass filter should be used to reduce aliasing noise. An LED is connected in series with a 150 ohm current-limiting resistor to microcontroller pin RB7. This active-low output indicates over-range output. It is set low for 200ms whenever an A/D conversion generates the maximum possible result (255).
software The source code describes how the sounds are produced. The C program can be compiled to run in the microcontroller or to run on a general-purpose computer (to generate samples of the audio output). The code was cross-compiled with the Hi-Tech HPDPIC C cross-compiler (compiler output: assembly language). adjustments Turn all lights off and set master gain to minimum (fully CW); turn all photodiode gains to maximum (fully CCW) for each of the three lights: turn the light on (to maximum intensity), if the LED does not turn on, increase the master gain (turn CCW) until the LED is on and then reduce the master gain until the LED just goes off; turn the light off. For each of the three lights: turn the light on (to maximum intensity); if necessary, reduce that light's photodiode gain until the LED just goes off; turn the light off. The above has been excerpted from http://www.ee.ubc.ca/home/comlab1/edc/etc/www/aurora |