Many simple MCUs do not provide DACs despite having PWM output. For low clock frequencies like 8MHz, PWM does provide very poor quality if used for audio purposes. E.g., TI mentions in application notes that 32kHz PWM with 8 bit timing resolution would result in an analog signal quality compared to 4-5 bit resolution DAC.
I wonder if one would be better off using UART TX at the highest possible baud rate – e.g. some MCUs would push out up to 400kBit/s at 16MHz.
Compared to the PWM method with its 8 or 16 MHz time base, we have only 400kHz timing resolution for each bit, but on the other hand, we may do far more level switchings in some given interval.
-
32kHz PWM does 64k switches per second with an 16Mhz timing resolution.
-
400kBaud UART allows for 400k switches per second with 400k timing resolution.
If we convert 50k samples per second to 50k 8-bit dithering patterns, what effective audio signal quality can be expected?
Best Answer
This is a little bit confusing, but I'll try my best to answer.
I think you are confusing the number of discrete combinations of bits, with the average level.
Let's start with your last question:
If we do this, we would have to be able to generate 28=256 different voltage levels after filtering. To do this, we must have room for 256 bits, meaning that you must generate a bitstream of 50k*256=12.8 Mbps. Far more than your 400 kbps.
This is because with 8 bits, there are 256 different combinations, but because you are oversampling and filtering, it's only the number of bits that counts, and that will be from 0 to 8.
0xAA
has the same average level as0x55
, and0xF0
etc.A PWM with a faster rate will always generate a "better" signal. It's the raw bit rate that counts. Your raw PWM bit rate for a 32 kHz PWM signal with an 8 bit timing resolution is closer to 8 Mbps.