Wave Player Using DMA
Introduction
This project uses a common Wave Player library and a micro SD card library to play a song that is located on a micro SD Card. Instead of just reading the file byte by byte this library includes an improvement by using the MODDMA library to transfer an entire buffer from the micro SD card to the DAC.
Wiring Information
Micro SD Card Module
micro SDCard module pin | MBed pin |
---|---|
CS | 8 |
DI | 5 |
VCC | VOUT |
SCK | 7 |
GND | GND |
DO | 6 |
CD | any Digital Out pin (10 was used) |
Class D high-efficiency audio amp
This module is optional instead of using this amp the speaker can be used with a simple transistor as shown in:
.
The amp that was used was the TI TPA2005D1 class D audio amp chip (250Khz PWM) sold by Sparkfun: TI TPA2005D1.
AMP pins | MBed pin |
---|---|
PWR - | GND |
IN - | GND |
PWR + | VOUT(3.3V or 5V) |
IN + | p26 |
PWR + | VOUT(3.3V or 5V) |
S | Any Digital Out(optional) |
AMP pins | Speaker Pins |
---|---|
OUT + | + |
OUT - | - |
Code
Below is the code for the Wave Player example. You can see that it is the same as before all of the DMA code has been included in the background in the play method. Below is the link to the library with play method using DMA
#include "mbed.h" #include "SDFileSystem.h" #include "wave_player.h" SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card AnalogOut DACout(p18); wave_player waver(&DACout); int main() { FILE *wave_file; printf("\n\n\nHello, wave world!\n"); wave_file=fopen("/sd/sample.wav","r"); waver.play(wave_file); fclose(wave_file); }
Import programwave_player_DMA_mbed
Wave Player with DMA
Please log in to post comments.