Teensy 4 - 4.1 Good quality PWM audio

fabrizio carraro

New member
I need to transmit medium/good quality audio (taken from the analog audio input of an audio board with a sgtl5000 chip) far away using a laser beam. In order to do that I send a PWM signal to the laser. The light beam is received by a photosensor far away. The photosensor exactly follows the signal if the PWM carrier frequency is below 100-150 Khz (there are no differences between the signal sent to the laser and the signal received, and the audio quality is the same). To test the project at this time I'm reading audio from a SD memory.
Using this simple code:

#include <Audio.h>
// other #include here
AudioPlaySdWav playSdWav1;
AudioOutputPWM pwm1;
AudioConnection patchCord1(playSdWav1, 0, pwm1, 0);
AudioControlSGTL5000 sgtl5000_1;
/+ some other obvious code here */

the PWM frequency is automatically set at 44100 Hz (maybe because of sgtl5000_1.enable() call?)
which is a good PWM carrier frequancy for my purpose. Unfortunately the PWM resolution is 8 bits only, so that high level audio passages are ok but low level passages are noisy because of the quantization error.

If I increase the PWM resolution using analogWriteResolution(10) I just have a lower output level (2 bits lower, that is 12 dB lower) but still with the same 8 bit quality. Setting the resolution at more bits (11, 12 or more) I have just a reduction in level.

What I'm missing here? I can I properly set the PWN resolution at at least 10 or 11 bits ? At 44100 Hz the Teensy 4.1 should cope well with that!

Sounds like a job for the MQS feature. It uses noise-shaping to improve resolution and reduce quantization noise.
I just tried MQS. The audio quality is much better than single pin PWM. The signal looks like PWM but at a carrier frequency of about 350 Khz. Playing with the internal registers it may be possible to lower it below 150KHz maybe. However rebuilding the laser driver for a lower impedance it worked very well for my purpose. Thanks Mark! Anyway since the range 200-400 Khz Khz is a carrier used by many class-D amplifiers, I can use one of them (without the output filter) and save the teensy for more high level signal processing tasks.