[sdiy] Mixing PWM audio from 2 different devices. Ouch!

rburnett at richieburnett.co.uk rburnett at richieburnett.co.uk
Thu Jul 20 19:08:27 CEST 2023


I agree with Tom.  Try to low-pass filter both of the PWM signals first 
before mixing them.  You'd think that adding together two pulse trains 
would be an easy and safe thing to do, however...  Even if the carrier 
frequencies for the two PWM outputs are both above 20kHz, it only takes 
a small amount of non-linearity (distortion) in the mixing device to 
result in unwanted frequency components being created at the sum and 
difference of the two PWM carrier frequencies.

Sharp-edged PWM outputs can have significant content way up into the MHz 
range.  An op-amp used to do the mixing might exhibit low distortion in 
the audio range but it might not be so linear up in the MHz range!  So 
it's better to filter the PWM streams to remove as much as possible of 
the switching harmonics and just leave the baseband audio.  Then the 
op-amp should do a better job of mixing the band-limited signals 
together without generating "intermodulation products."  Also check that 
combining the two sources doesn't result in an output that gets near to 
clipping because that will compromise linearity too.

I second Tom's comment that the MFB filter arrangement is better for PWM 
filtering than Sallen-Key.  The tool he linked for a 3rd-order LPF using 
a single op-amp is my go to method too.  (For what it's worth, it also 
makes a good ADC anti-aliasing filter where you can get a cheap 
4th-order LPF with a single op-amp by placing another 1st-order RC 
filter between the op-amp output and the input of the ADC!)

-Richie,


On 2023-07-20 16:17, Tom Wiltshire wrote:
> If the tone is the result of beating between the two PWM frequencies,
> then better filtering to remove the PWM clock will help.
> 
> I'm betting both of the individual synths use the PWM at such a high
> frequency that they probably don't bother with much filtering. You
> can't hear it anyway, so what's the problem?! That's fine until you do
> something like you've done, and then the problems begin.
> 
> I'd run the audio from each synth through a lowpass filter set for
> 20KHz before mixing them together, and see if that helps. If the
> frequencies are really high, a simple 2nd or 3rd pole filter would do
> it. A MFB filter is to be preferred in this situation for the better
> high frequency response - it continues to roll off, whereas a SK
> doesn't.
> 
> Here's a page with tools to design one for you - scroll down:
> 
> http://sim.okawa-denshi.jp/en/MultipleFB3Lowkeisan.htm
> 
> HTH,
> Tom
> 
>> On 20 Jul 2023, at 15:49, Benjamin Tremblay via Synth-diy
>> <synth-diy at synth-diy.org> wrote:
>> 
>> I had this idea I would use one of my dusty old DSP-G1
>> synth-on-a-chip modules as a mono synth engine for the shell of my
>> Muppet Babies EP-10 keyboard.
>> I desoldered the original CPU chip and used an Arduino Mega Pro (the
>> tiny one) to scan the matrix. I can get decent-ish synth sounds of
>> the DSP synth.
>> 
>> Then I got ambitious. I added the Mozzi library and put in a sample
>> player to play back the legacy Casio VL-style rhythm sounds (po, pi,
>> sha).
>> Everything in theory works. I can run Mozzi at a decent rate, scan
>> the keyboard, and control the DSP chip with TTL-level MIDI. I chose
>> Mozzi HIFI mode and it does sound a little better. I don’t want it
>> to sound too good, it’s a Casio.
>> 
>> However, I am getting a loud high frequency tone when I try to mix
>> the outputs of Mozzi PWM and the DSP G1 PWM. I suppose this is a
>> beat frequency. It is present when both devices are idle.
>> 
>> Adding oversized lowpass capacitors (47nF) to the inputs of my opamp
>> take the squeal down, but it’s still there.  Fading down either
>> signal stops the squeal.
>> 
>> Is there anything I can do about this? Add individual buffers to
>> both? Lower the gain on my opamp (I am using a 100K resistor in the
>> loop and 15K mixer inputs capacitively coupled) ? The opamp is an
>> LM324 running off the 5V supply, so I certainly can improve its
>> power supply.
>> 
>> I am hoping I can get this combination to work and move onto
>> refinement of the firmware. Otherwise I will just punt and use a
>> Teensy. But that would be too easy.
>> 
>> The take-away from this seems to be, do not combine 2 different PWM
>> audio sources running at 2 different clock speeds from 2 different
>> MCUs. (Or don’t use PWM audio at all if you can avoid it!)
>> 
>> Benjamin Tremblay
>> btremblay at me.com
>> Carlisle, MA
>> 
>> _______________________________________________
>> Synth-diy mailing list
>> Synth-diy at synth-diy.org
>> http://synth-diy.org/mailman/listinfo/synth-diy
>> Selling or trading? Use marketplace at synth-diy.org
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at synth-diy.org
> http://synth-diy.org/mailman/listinfo/synth-diy
> Selling or trading? Use marketplace at synth-diy.org


More information about the Synth-diy mailing list