Interrupt Service Routine

The PCSYNTH program is divided into two major sections, the main loop and the interrupt service routine (ISR). The ISR is invoked by the Programmable Interrupt Timer interrupt (44,000 times per second) and will contain the code that computes the next DAC value and presents it to the DAC. It will also poll and buffer any data that appears on the MIDI interface serial port. Since the ISR rate will be more than 10 times faster than MIDI data can appear, servicing the MIDI port this way is more than adequate. Note that the MIDI port is an I/O port and therefore will require (on this machine) 1.5 uS to read the status register and 1.5 uS to read the data port when data is ready. This means that we must sacrifice 3 uS of the 22 uS available to make sure there is always enough time to both poll the port and to read its data. However, this is far better (13.6%) than using the LPT port (41%). A total of 19 uS will be available for DAC computation on every cycle. This time and the speed of the CPU will determine how many and what kinds of features can be programmed.

The PIT (programmable interrupt timer) is used to generate an interrupt at a rate the is close to 44 KHz. This time may be adjustable to trim performance, such as running slightly slower to accomodate more synth features.

Code will be added to implement a flag that detects if the ISR is being invoked again while it's still running from the previous timer interrupt indicating that either the timer is interrupting too fast or the code inside the ISR is taking too long to execute. This flag will cause a display change to indicate to the user that this condition is present. The way to alleviate this condition is to remove code from the ISR, run the timer slower or use a faster machine.

Note that this program will use the programmable interrupt timer which normally keeps the system clock updated. This program "steals" this interrupt which normally runs at about 18.2 Hz and resets the timer to interrupt at a rate of approx. 44,000 Hz. It is to be understood that the system's clock will be wrong after using PCSYNTH. This was a sacrifice made to use an interrupt method that offers reliable timing and easy programming. It is not expected that the time of day clock being inaccurate will be important to any user since the targetted hardware is "junk" to start with.

Main Loop

The main loop portion of the program will monitor the buffered MIDI data, when there is a complete message, the main loop will compute and set any synth data parameters that changed as a result of MIDI data (such as pitch wheel or continuous controller, note start, note end, etc.). The new parameters will be used starting with the next ISR invocation.