Monday, January 13, 2014

Arduino: High Quality Audio Modulated PWM

This project shows how to increase the clock speed of the Arduino UNO's ADC Analog pins to allow for a 77KHz sampling rate (up from the default ~10KHz), and increase the PWM carrier frequency on the PWM Digital Output pins to 64KHz on pins 5 and 6, or 32KHz on the other PWM outputs. This sampling rate is higher than your PC's audio card inputs!

This allows one to use an arduino UNO as a high quality audio PWM modulator. For the purpose of demonstration I have terminated the PWM output into a Low Pass filter to show the demodulated data, but in practice one would feed the output from the arduino to a Class-D type amplifier for amplification, and then feed that output into a Low Pass filter for data/signal recovery. This lends itself well to audio modulating a flyback transformer, as most flybacks perform well around 60KHz. One could simply feed the arduino output to a BJT totem or MOSFET gate drive chip like the TC4420 or UCC37322/UCC37321 pair or the dual inverting/non-inverting UCC37325 to attain the needed voltage and current amplification for driving power transistors (MOSFETs or IGBTs). Such an implementation of Arduino -> UCC37325 -> Half-Bridge Inverter -> Low Pass Filter is the basis for a super simple high powe audio amplifier. In this way the arduino emulates such chips as the SG3525 or TL494 without the complicated wiring needed to actually use one of these chips, as most of the work is done natively on the arduino.

The only components needed to get high quality audio modulated PWM out of the arduino UNO are two (2) 10k ohm resistors and one (1) capacitor. For the capacitor the higher the capacitance the better, and if you can get a nonpolar one all the better. The reason for nonpolar is that depending on what audio source you are hooking the arduino up to you need to know which has a higher DC bias; the arduino's 2.5V DC offset bias formed by the 10k resistors or the output of your audio source in order to properly install a polarized capacitor. If you can find a nonpolar capacitor, it doesn't matter which way you orient it. The larger the capacitance the better the bass response.

Example 1: iPod audio source.
Your iPod has no DC offset on its output so the arduino's 2.5V DC Offset Bias is higher, thus the positive terminal of the capacitor has to go towards the arduino, and not towards the iPod.

A -+2Vpk (4Vp-p) maximum audio signal can safely be input into the arduino, and the software is built around this. The code is dead simple though so it can easily be tweaked in software to allow for stronger or weaker modulation, but it is even simpler to just turn up or down the volume of the audio source.

Here is the input/output schematic detailing the resistor divider and DC-blocking capacitor on the arduino input, and the Low Pass filter on the output needed for signal/data recovery. You will find that this filter attenuates frequencies within the normal range of hearing. To get a better high end response simply reduce the value of R3 in the schematic. I experimented with values between 100Ohms and 1Kohms but found that too much carrier frequency (actually lower sidebands) was present for my liking below about 300Ohms.

Here is the arduino code for this program. Most of the magic happens in the void setup() block, as this is where the I/O speeds are increased. The void loop() block just has some basic signal processing math and feeds the processed data to the output pins.
Here is a video I uploaded showing it all in action. Forgive the poor audio quality shown; it is an artifact of the audio amplifier used, not the arduino. I didn't have a spare speaker or amplifier laying around other than my 1928 Dual Triode Vacuum Tube Audio Amplifier I built, which has a nasty 60Hz hum and nonlinear frequency response.

The nice thing about using a real SG3525 or TL494 is that you can easily set the carrier frequency with external components. In the case of the SG3525/KA3525 you have a range of up to 400KHz. The arduino emulation works great for when the carrier frequency doesn't really matter (other than being high enough to easily filter out) like with audio amplification. 


  1. Hi Matt,
    I've built the circuit according to yr guidelines and it works :-), I've a couple of questions... do you have an email address where I can contact you?
    Thx, Simone.

    1. Hello Simone,
      Glad to hear you were able to replicate it! Feel free to email me at with any questions you might have. Best wishes!