|
Here is the original MIDI circuit, designed to send static rhythms to a MIDI synth. It took a while to get the output working properly using Tom Igoe's notes. Tetsu Kondo was a big help in finally debugging the circuit; one would do well to follow a few of his suggestions:
- Try removing Tom's suggested twin capacitors from oscillator to ground;
- Make sure that pin 8 is grounded (for the PIC16F876, at least);
- Don't forget the 220 ohm resistor into the MIDI power input.
Once that circuit was up and running, I attached a basic bank of eight switches to simulate a single row of squares on my percussion chessboard. The PIC scrolls through each switch and based on whether it is on or off plays a conga beat or a different percussion sound.
The potentiometer at left was attached to control the tempo. It is read after each beat to determine the wait until the next beat. Anything less than 200 seemed to clog the PIC, so I made that value a base threshold. Obviously, some optimization will have to be done before I can attach eight banks of sensors to the chip.
Circuit Schematic
Pic Basic Pro Code
According to Tom, there is a way to call port registers with variables using the format PORTA.x or the like. This returned a lot of "bad variable modifier" errors, so I tackled the loop with a more direct approach. The Pic Basic Pro manual seems to indicate that the proper format for variable modifiers is PORTA.0[x] instead, but I haven't had a chance to check that yet.
INCLUDE "modedefs.bas"
define OSC 20
define HSER_TXSTA 20h ' enable the transmit register
define HSER_BAUD 31250 ' set the baud rate
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 10
tempo VAR WORD
TRISA = %11111111
ADCON1 = %10000010
TRISB = %11111111
pause 500
main:
if PORTB.0 = 1 then
gosub playNote
else
gosub playLowNote
endif
if PORTB.1 = 1 then
gosub playNote
else
gosub playLowNote
endif
if PORTB.2 = 1 then
gosub playNote
else
gosub playLowNote
endif
if PORTB.3 = 1 then
gosub playNote
else
gosub playLowNote
endif
if PORTB.4 = 1 then
gosub playNote
else
gosub playLowNote
endif
if PORTB.5 = 1 then
gosub playNote
else
gosub playLowNote
endif
if PORTB.6 = 1 then
gosub playNote
else
gosub playLowNote
endif
if PORTB.7 = 1 then
gosub playNote
else
gosub playLowNote
endif
goto main
playNote:
hserout [$99, $40, $40]
gosub setTempo
pause tempo
hserout [$89, $40, $000]
return
playLowNote:
hserout [$99, $4C, $40]
gosub setTempo
pause tempo
hserout [$89, $4C, $000]
return
setTempo:
ADCIN 0, tempo
tempo = (tempo + 100) / 2
if tempo < 200 then
tempo = 200
endif
return
Next Steps: Try outputting eight MIDI tones at once from the PIC. Work out a strategy for attaching eight banks of sensors to a single chip, and investigate which sensors are best for the job. Build a single row interface. Experiment with different mappings for sounds.
|