Low Pass RC Filter to PWM Sound Output doesn't work

Thread Starter

Tadzik

Joined Jan 22, 2017
5
I connected a headphone (32 ohms) to SMT32 F103RB board. There was a sound, but it's modulation was wierd, because to change frequency I had to change PWM prescaler, and pulse didn't do much (changed volume slightly and maybe frequency slightly). Can't even get low frequencies, there was "shooting" instead of bass. That's not how to use PWM to sound output, right? So i made this filter with resistor and capacitor. Resistor was around 25k ohm, capacitor not sure, maybe 15μF, because it's written on it μ15J63 and on other side SM 1J0. I couldn't get any sound from it when i connected it like that, so i connected capacitor differently (+ in place of - and - in place of +). Then i got very quiet, high frequency sound, only when prescaler is in 1-10 range. Again, only prescaler changes frequency, pulse only changes volume slightly. Tried different headphone, with 4 ohms, nothing changed. Changing resistor with a 1,8k ohms one (while still having 4 ohms headphone) made the sound a little louder, and now i can hear sound with a little higher prescaler than 10, it then creates quiet shooting sound.

Is this because of wrong resistor and\or capacitor values? Is this related to too low cut-off frequency? Or maybe low pass filter is wrongly made?
 

MrChips

Joined Oct 2, 2009
34,888
Yes, you have chosen both the wrong impedance and wrong frequency.

If you are driving a 32Ω headphone you want the filter impedance to be lower than this.

The purpose of the low-pass filter is to smooth out the PWM pulses, not kill the audio signal.
Hence you want the cut-off frequency to be above the audio range.
For a filter above 20kHz, you need a time constant of about 50μs.

Hence, put 10Ω in series with the headphone, followed with 5μF across the headphone.
 

Thread Starter

Tadzik

Joined Jan 22, 2017
5
Ok, 1μF, it's 16 kHz, not full hearing range, but enough.
I found this equation
prescaler = CPU clock / (PWM frequency * PWM resolution) – 1
Is this correct?
My CPU clock is 64 000 000 Hz and I want 10 000 PWM resolution (it's a range of values I can pass to the PWM pin, meaning I can have 10 000 different frequencies of sound, right?) so if PWM frequency is 10 000 Hz, then prescaler is -0.36. Which is wierd to set up, because prescaler should be integer... And chart ripples looks nice at like 600 000 Hz with those rc values.
 

MrAl

Joined Jun 17, 2014
13,722
I connected a headphone (32 ohms) to SMT32 F103RB board. There was a sound, but it's modulation was wierd, because to change frequency I had to change PWM prescaler, and pulse didn't do much (changed volume slightly and maybe frequency slightly). Can't even get low frequencies, there was "shooting" instead of bass. That's not how to use PWM to sound output, right? So i made this filter with resistor and capacitor. Resistor was around 25k ohm, capacitor not sure, maybe 15μF, because it's written on it μ15J63 and on other side SM 1J0. I couldn't get any sound from it when i connected it like that, so i connected capacitor differently (+ in place of - and - in place of +). Then i got very quiet, high frequency sound, only when prescaler is in 1-10 range. Again, only prescaler changes frequency, pulse only changes volume slightly. Tried different headphone, with 4 ohms, nothing changed. Changing resistor with a 1,8k ohms one (while still having 4 ohms headphone) made the sound a little louder, and now i can hear sound with a little higher prescaler than 10, it then creates quiet shooting sound.

Is this because of wrong resistor and\or capacitor values? Is this related to too low cut-off frequency? Or maybe low pass filter is wrongly made?
Hello,

Depending on what you intend to get out of this, you may have to move to an actual amplifier chip. The LM386 comes to mind but you may want to look around.
Microcontroller i/o pins dont drive regular audio loads very well because they are so limited in current. A small amplifier chip helps this situation by a long shot mostly because the output impedance of an amplifier chip is much lower and can handle more power without a problem.
There are so many chips out there though it's really up to you to decide how much output power you need and go after a chip that can handle that. The LM386 is a general purpose amp that can output enough power to easily hear the signal in a regular speaker or headphone with i'd say medium audio quality.
 

Audioguru

Joined Dec 20, 2007
11,248
Your "μ15J63" capacitor is 0.15uF/63V. If it is in series then it passes only high frequencies. If the 25k resistor is in series then the capacitor connects to ground then its cutoff frequency where it reduces the level only a little is 43Hz, it passes just deep bass sounds. Higher frequencies are cut at -6dB per octave. This RC filter cannot feed a headphone, it feeds the much higher input resistance of a power amplifier.
But it seems that you do not have a power amplifier.
 

MrAl

Joined Jun 17, 2014
13,722
Your "μ15J63" capacitor is 0.15uF/63V. If it is in series then it passes only high frequencies. If the 25k resistor is in series then the capacitor connects to ground then its cutoff frequency where it reduces the level only a little is 43Hz, it passes just deep bass sounds. Higher frequencies are cut at -6dB per octave. This RC filter cannot feed a headphone, it feeds the much higher input resistance of a power amplifier.
But it seems that you do not have a power amplifier.
Hello,

Yeah it seems that Tadzik does not have any kind of amplifier yet, and also that member did not return since January so maybe they wont come back.

I have run a headphone set from a uC chip but i did not expect much from it. I get minimum volume. I used an electrolytic coupling cap but dont remember the value now. I also used a pot in series for volume control, dont remember the value of that either though.
I ran this off off a wall wart so there would be no problem with using an audio amp chip of some kind for a better output level.
Headphone amps built from raw transistors can work out pretty nice too though. I built one a long time ago for a TV set and it had very low noise and using an audio transformer for electrical isolation from the users headphone set to the TV circuitry. It was a simple two transistor DC coupled circuit.
 

wwuig

Joined Dec 15, 2017
1
Tadzik, the fact that you were able to hear something suggests there's enough signal from your PWM pin. The raspberry pi's audio is also a PWM output from the arm chip and you can see the components used for a simple filter here:
https://learn.adafruit.com/introducing-the-raspberry-pi-zero/audio-outputs

Your PWM freq is only 10KHz (have I understood this correctly?) so you may want to increase the 33nF capacitor to something larger. The article also has an alternative output circuit diagram which uses a buffer to increase the output power. You may find a buffer easier to add than an opamp.
 

Thread Starter

Tadzik

Joined Jan 22, 2017
5
Thanks for replies, but I don't need help anymore. It was a university project that I passed months ago. It finally didn't play any proper sounds, but had nice smooth waves visible on an oscilloscope and an ability to modulate the wave with another wave.
 
Top