simple sound player: PWM audio output, with DMA, without timer interrupt
stevestrong Sun Oct 29, 2017 9:20 am
To output PWM audio, current solutions use timer interrupt to update the new value in the compare output register.
This version uses the DMA (channel 7) triggered by timer (4) update event to do the same, so the processor has now plenty of time to do other tasks.
Speaker out on PB6 (timer 4 ch 1).
No interrupts are used, although one could use the DMA transfer end IRQ to do some stuff.
EDIT: – I added the possibility to use DMA interrupt. For this just enable the define in line 10.
This example uses a half second long WAV file (converted to C code) with 8 bit resolution, 16 kHz sampling rate, stored in the flash (~8kB data).
The timer prescaler and preload registers are optimized in order to have a maximum peek to peek output range for 0-255 PWM values.
Have fun.
Needed patches:
https://github.com/rogerclarkmelbourne/ … 2/pull/366
https://github.com/rogerclarkmelbourne/ … 2/pull/367
