Re: programming: midi via game port and PIC/mplab

[ Follow Ups ] [ The MIDIWORLD Forum ]

Posted by Luke Palmer on November 05, 2002 at 23:44:13:

In Reply to: programming: midi via game port and PIC/mplab posted by Matt kammet on April 24, 2002 at 10:01:46:


I've done some massive projects with a PIC and audio hardware before. Here is some stuff I picked up along the way.

Generating a sine wave- seems like it should be easy, right? Wrong. All the commercial sinewave generator chips out there get their frequency from a potentiometer. Not at ALL accurate for synthesizer work. I have seen some appnotes out there that tell you to hook a DAC up to the PIC and control the sine wave generator from that- what a TERRIBLE idea.

It is possible to generate a sine wave directly from a digital signal. Look at the Fourier transform of a square wave- it's made up of a series of sine waves, with the first harmonic at well away from the fundamental frequency. So, all we have to do is use a low pass filter to remove all the higher harmonics from a square wave, and we will have a perfect sine wave.

Not just a low pass filter, but a GOOD one, and a tuneable one. Maxim (www.maxim-ic.com) makes clock tuneable, 8th order (yup, that'll do it!), switched capacitor low-pass filters in an 8 pin package. The frequency of the filter is continuously varied by a clock you give it, divided by 50. Very cool chips.

So here's what you do- set one of the PWM outputs on your PIC to a frequency and give it 50% duty cycle (a square wave). You can have the PIC go do other things, and it will keep on generating this signal as long as you want. Run the output of this into two things: the clock on the maxim filter, and a frequency divider that will divide by 60 or so. Run the output of the frequency divider into the input of the filter. The output of the filter will be a CLEAN sine wave at your initial clock frequency divided by 60.

Now for the attenuation. National semiconductor (national.com) makes digital audio attenuators. They are also in an 8 pin package. Hook one of those straight up to the SPI serial bus built into the PIC, and you're in business.

I might have a schematic of this lying around if you want it.

Good luck.

Follow Ups: