Saturday, May 21, 2011

WAV Player with LPC1768 and SD card

After porting the SD card low-level IO functions that my project team had written for the AVR Atmega 8-bit series about a year ago, integration with elm-chan's FAT FS was seamless. Keeping the connections suggested by Mike, the SD card posed no difficulty at all.

Playing a WAV file with a microcontroller is a "hello world" equivalent when interfacing with the SD card. For this, the motor control PWM peripheral looked ideal since I needed the main PWM peripheral for something else. An RC low pass filter of 330 ohm and 0.1uF is good enough to filter out the PWM frequency and its harmonics while leaving the audio signal intact.

At 100 MHz, LPC1768 can do 8 bit PWM at 390.625kHz. As a rule of thumb, in class D amplifiers, the PWM frequency is chosen to be 10 times the max frequency of the signal of interest so that low pass filtering is easy and effective. The maximum that we hear is 20kHz, we're quite safe with 390.625kHz.

My LPC1768 SD library with FAT FS can be found here. My Test App and WAV Player are here.

But with 16-bit per sample, PWM frequency drops to 1525 Hz, which is completely unacceptable. If that accuracy is needed, putting in a 16 bit DAC chip is a good idea. But if you insist on the cheapo RC filter, there is a hybrid PWM + R-2R DAC method that produces decent results. I'd used this technique to get 8-bit per sample on an atmega16 running at 11.0592Mhz. At that clock frequency, 8-bit accuracy results in a PWM frequency of 43.2kHz, which I had found unacceptable. So I had employed this hybrid technique of using 2 PWM channels each giving 4-bit accuracy. The 2 PWM outputs are combined by a binary weighted DAC. In my case, it was R for the MSB channel and 16R for the LSB channel. This technique is outlined in more detail here.

1 comment:

  1. Hi Sheri, the Asymmetrical twist out looks great. I would like to try that style!!