Raspberry Pi Pico PWM audio output circuit – Integrated processing design

By Jeremy S. Cook

Freelance Technical Journalist / Technical Writer, Technical Consultant

Jeremy Cook Consulting

June 27, 2023

Blogs

Original positive GPIO signal (yellow), positive and negative oscillating shifted audio line signal (blue)

As discussed in class 7 of my Developing with Pi series, Sound and Music Output with Raspberry Pi RP2040 Pico, and Raspberry Pi Pico/RP2040 is a pretty impressive sound source. Not only can it generate beeps and program boops as you might expect from an Arduino Uno and the like, it can also play uncompressed WAV files, as well as compressed MP3s. The big restriction is that the Pico only has 2MB of Flash memory, although the RP2040 can run on up to 16MB, allowing for a little more space depending on the card.

In the class mentioned earlier, I connected the output pin and grounded a small speaker to produce audio and used an I2S amplifier. The direct GPIO connection method produces an audio output. However, it is a DC signal, varying between 0 and 3.3V.

Line-level corrected audio signals are AC, ranging from ±1.736 in professional applications to much lower for consumer equipment. While I haven’t done any apparent harm using this DC setup in my limited testing, I don’t exactly trust it either.

Fortunately, there is a ready-made solution found on page 23 of the Raspberry Pi RP2040 hardware design guide, shown in Figure 22:

Caption: PWM Audio Circuit from the RP2040 Hardware Design Guide / Image Credit: Raspberry Pi

Through a configuration of capacitors and resistors, the circuit transforms GPIO27 and GPIO28 into stereo AC signals which are fed into an audio jack. The configuration uses a dedicated 3.3V audio supply with a logic buffer to mitigate digital noise from the main supply. It’s a simple enough circuit as it is, but I’ve distilled it further to eliminate external power for a mono output:

Caption: Simplified Circuit / Image Credit: KiCad screencap

This simplified circuit produces the desired mono AC audio output. By binding the tip and ring segments of the 3.5mm jack together, sound is output simultaneously from the left and right speakers of the headphones. Here’s the circuit laid out on a breadboard, with GPIO15 used in place of GPIO20:

Caption: Simplified circuit on breadboard / Image credit: Jeremy Cook

I’ve also made a variation of this circuit on a project I’ve been working on. Here I used a 2k resistor I had on hand instead of the 1.8k component specified by the design guide. Both produced audio in much the same way.

Caption: PCB circuit. Replaced 2K resistor with 1.8K resistor. 220 ohm resistor near Pico not shown. / Image credit: Jeremy Cook

Listening with decent headphones, the clips sound good when played at full volume. However, there is noticeable hiss when the volume is turned down. Whether this is a result of not using a separate power supply, or if it’s due to another hardware and/or software issue, I’m not sure. This setup is now capable of sending a suitably alternating audio signal, and I wouldn’t (much) hesitate to connect it to unfamiliar audio equipment.

Since implementing this type of audio output is a matter of component pennies compared to simply connecting an output to a GPIO, I would consider it an appropriate audio solution in a number of situations. At the same time, we would like to explore different filtering methods to eliminate low-level hiss in production. You might also consider using an I2S booster like the MAX98357A as an alternative, although this will require the use of three GPIO pins and some different programming.

Jeremy Cook is a freelance technical journalist and technical consultant with over 10 years of experience in factory automation. An avid creator and experimenter, you can follow him on Twitter or watch his electromechanical feats on Jeremy S. Cook’s YouTube channel!

More from Jeremy

#Raspberry #Pico #PWM #audio #output #circuit #Integrated #processing #design
Image Source : embeddedcomputing.com

Leave a Comment