PIC code

Code The flow diagram on the right summarized operation of the PIC microcontroller code. After an initialization routine, the program enters its main operation loop, in which it sequentially processes routines for the breath pressure, the keyworks fingering, the articulation signals (gate and note-on) and the jaw and bender sensors.

The loop pacing is based on a 2.5 ms timer. Upon entering "Main" the processor waits for the next timer cycle (unless that cycle has already occurred before loopback, in which case processing proceeds immediately). The processor then reads the analog breath signal and sends a corresponding MIDI message to either MIDI breath (CC2) or MIDI aftertouch, depending on the setting of the corresponding configuration switch. Data for this transducer as well as for the other analog signals are only sent if a change has occurred since the previous reading.

Next the processor enters a rather complicated routine for handling the keyworks. Initially, the routine simply scans the keys and checks for a fingering change. Once a change is detected, the routine sets a loop-counter variable that is then decremented on successive cycles around the main loop. (Key scanning is omitted during this phase). This produces a "deglitching" delay that allows the keyworks to settle upon a fingering change. After the appropriate number of delay cycles, the keyworks are read again and a MIDI new-note-on / old-note-off sequence is sent, provided that a note change has really occurred. As a further twist, the keyworks routine also checks whether the fingering change involves a change of the octave keys, in which case the delay time is increased. It should be emphasized here that the kind of "note change" detected by the keyworks routine is a pitch change without articulation, i.e., a legato note change.

At this point in the program, if new note data were sent then program execution is sent back to the top of the loop (dotted line) in order to maintain tight timing for the breath and keyworks routines. Otherwise execution continues with the articulation routine.

The articulation routine is somewhat similar to the keyworks routine. Initially, the routine simply checks for a Port B interrupt signalling an articulation event. After detecting an event, the routine does nothing for a number of passes through the main loop, in order to implement a "capture" delay. This delay allows the breath force to build up after the start of the attack, so that an appropriate MIDI velocity value can be sent with the MIDI note-on message corresponding to the articulation. After the delay time has expired, the processor reads the gate and note-on lines, analyzes what kind of articulation has occurred and sends the appropriate MIDI message(s). Again for emphasis, the kind of "note change" detected by the articulation routine is an articulation without a pitch change, i.e., a staccato note change.

After the articulation routine, the program checks on how many MIDI messages have been sent so far in the loop cycle. If it is more than one, then execution is again sent to the top of the loop to keep the timing tight (second dotted line). Otherwise there is time to check the jaw or bender signal within the 2.5 ms timing window.

The jaw and bender signals have relatively slow changes, so they don't need to be monitored too frequently. The program checks them alternately every three times through the loop. In other words, each is normally updated every 6 x 2.5 = 15 ms. This rate is reduced slightly because of the early loopbacks when the keyworks and articulation data are dense, but overall these are infrequent events. The MIDI destinations of the jaw and bender signals can be set with the configuration switches. The choices currently available are one of them to MIDI pitch bend and the other to MIDI modulation.

The software routine seems to me to be very smooth and responsive. The most critical parameter is the deglitching delay. Including the extra delay for octave changes helps enormously in playing without excessive extra in-between notes. Two of the configuration switches have been dedicated to setting different values for the deglitching time and the capture delay time. I found that it was possible to run the system faster -- with a 2.0 ms loop time-- but both my sequencer and synthesizer module clogged up at this higher data rate. Thus it seems that the setup as described is about as fast as can be handled by typical commercial gear.


Back   Home