Sound on the MSP430

Originally posted May 30, 2009. Updated May 11, 2019 - what a decade it’s been.

Generating sound with the MSP430 is fairly easy. I was originally using an MSP430F2618 because it has an internal DAC. Nowadays (2019) I’d probably use an MSP430FR2355 or MSP430F5338 because these have internal DACs. The choice between these two depends on whether you’re into FRAM or not. You can also use any microcontroller and just use an external DAC. A couple of notes:

  • The circuit: the DAC output feeds a Sallen-Key filter to reduce noise and then drives a TI TPA721 300mW Class-AB amplifier which drives a little toy speaker. If you want higher efficiency but more noise, then you could use a Class-D amplifier.

  • Generating good quality white noise is harder than it sounds. The ear can very easily discern repeating patterns. After several tries, I ended up using a Linear Feedback Shift Register, specifically a Galois LFSR. See WikiPedia.

  • For sine waves, I made a wave table with 72 points (every 5 degrees from 0 to 355 degrees). You can then output these at equal time intervals to generate a tone. Change the interval to alter the frequency.

  • To get volume levels I ended up making ten wave tables, one for each 10% volume level. You could of course compute this on the fly but it took too many clock cycles for my implementation. It’s just as easy to precompute. Besides, it’s only 72 bytes of flash per volume level.

  • To prevent "zippering" at the start of the code I compute intermediate wave tables (5%, 15%, etc)

  • Learned the hard way that the "rail to rail" op amp ain't. Needed to recompute the wave tables with an offset to keep the bottom of the DAC output above the 100mV floor of the op-amp. So if your rails are 0 to 3V, keep the output between 100mV and 2.9V.

  • If you’re really good then you can forego the DAC and use a timer with PWM as a poor mans DAC. Obviously you’ll need a filter to suppress the PWM frequency, and a PWM frequency much higher than your desired output frequency.