Class D amplifier usage with PWM driven audio signal

Thread Starter

crys17p

Joined Aug 24, 2017
9
I am working on a project that involves a simple device that plays a 5 second audio track (consisting of a man speaking) when a switch is turned on. I am using an Atmega328 chip with an Arduino bootloader to read a WAV file from an SD card and stream that audio data as a PWM signal to a LM386 audio amplifier set for 200 gain and the whole thing powered by 5x1.5V batteries . The application works however the outputted volume is a little low for the purpose of the application (this device will be placed in a open outside pedestrian area and is supposed to be clearly audible to a person sitting right next to it). I have added more batteries all the way up to a total of 12 v and increased the volume a bit more but it is not quite satisfactory and i would also want to avoid using more than 5 or six batteries on it.

I was thinking i can use a Class D amplifier since i understand that they are great for low power portable applications. Since i see that these amplifiers take analog signals as inputs my question is how can i interface the pwm audio signal that i have with it? Do i use a simple low pass filter, do i need a DAC or is there a simpler way to do this. Can the volume be increased noticeably this way or is it strictly dependent on how much juice i put through it in the end.

Thank you in advance for your response.
 

dendad

Joined Feb 20, 2016
3,721
I would think gain should not be a problem. the PWM signal would be able to have a peak to peak signal swing of 5V, and the LM386 will only need a few mV input. What is the audio output level from the PWM?
Also, the LM38s is not a high power amplifier. You may do better to go to something else.
Even one of these may be better, and it could run on 5V I think...
http://www.ebay.com.au/itm/PAM8403-...210103&hash=item544d6ceca9:g:Hb4AAOSw~OVWxaRH
 

Thread Starter

crys17p

Joined Aug 24, 2017
9
I would think gain should not be a problem. the PWM signal would be able to have a peak to peak signal swing of 5V, and the LM386 will only need a few mV input. What is the audio output level from the PWM?
Also, the LM38s is not a high power amplifier. You may do better to go to something else.
Even one of these may be better, and it could run on 5V I think...
http://www.ebay.com.au/itm/PAM8403-...210103&hash=item544d6ceca9:g:Hb4AAOSw~OVWxaRH
Yeah i looked at that amplifier and it is an option but can i use the pwm signal directly on it or do i need something in between them. Also i was thinking of actually going for a monochannel one: https://www.digikey.dk/product-detail/en/BOB-11044/1568-1025-ND/5140790
 

BobTPH

Joined Jun 5, 2013
2,866
How did you send rhe signal to the LM386? It also takes an analog input, as opposed to a PWM signal. Both it, and your class D amp would require a low pass filter to use a PWM signal.

Bob
 

Thread Starter

crys17p

Joined Aug 24, 2017
9
How did you send rhe signal to the LM386? It also takes an analog input, as opposed to a PWM signal. Both it, and your class D amp would require a low pass filter to use a PWM signal.

Bob
For the LM386 i used a 10 K potentiometer as instructed in the application not in the data sheet. If i am not mistaken i think the PWM signal should be 32 KHz. What should be the cutoff frequency in this case for the filter?
 

BobTPH

Joined Jun 5, 2013
2,866
For voice, you could use a cutoff of 4KHz.

I still question your circuit though. If you are using the PWM output of the Arduino, the output voltage should be half the supply voltage. That would be at least 1.5V. Running a 1.5V signal through a 200 gain amplifier would produce 300V, if it could. Instead you should get a very highly clipped (distorted) signal, unless you have your 10K pot turned almost to zero. Your amplifier should have a gain in the single digits, even 10 would be too much.

Bob
 

BobTPH

Joined Jun 5, 2013
2,866
On second thought, I see what is happening here. the PWM signal is being amplified by the LM386 and clipped, but since it is just a square wave with a variable duty cycle, the clipped signal faithfully reproduces the original signal. The speaker itself is a low pass filter that makes the audio signal come out okay.

And you are correct in saying that this may not work with a class D amplifier.

A simple RC filter with a cutoff of 4KHz should do the trick though. But now that you have an analog signal, it will likely overdrive the amp, so you will need to attenuate it before going into the amp.

Also, a 1.5W amp will not sound much louder than your LM386 which is a 1W amp. For an outdoor application, you probably want something more like 10W.

Bob
 

Thread Starter

crys17p

Joined Aug 24, 2017
9
For voice, you could use a cutoff of 4KHz.

I still question your circuit though. If you are using the PWM output of the Arduino, the output voltage should be half the supply voltage. That would be at least 1.5V. Running a 1.5V signal through a 200 gain amplifier would produce 300V, if it could. Instead you should get a very highly clipped (distorted) signal, unless you have your 10K pot turned almost to zero. Your amplifier should have a gain in the single digits, even 10 would be too much.

Bob
For most of the positions on the potentiometer the sound is ok though i feel no difference in the volume. its only when i reach one ends of the potentiometer that it cuts off and nothing is audible......... just a small static. At a minimum the gain on the LM386 is set to 20 by default. Should i try a different setup with that amplifier and get better results or is it simply impossible to get more out of it then what i have?
 

BobTPH

Joined Jun 5, 2013
2,866
Yep, that is exactly what I expected. Your amp is simply passing the PWM signal on to the speaker. Sending a PWM signal to a speaker will sound OK as long as the PWM frequency is above the audio range.

But, as I said before, it may be problematic with a class D amp. There would be aliasing between the two different sampling frequencies that might really mess things up.

Another way to get more output is to simply drive a MOSFET bridge with the PWM signal and the speaker across the bridge. I did this for a microcontroller project with audio output. With a 5V supply you can get about 1.5W, which is basically what the class D amp you linked is doing, and is what the class Ds that claim 3W are doing. You can only get 3W from a bridged amp at 5V with a square wave as the signal.

Bob
 

Thread Starter

crys17p

Joined Aug 24, 2017
9
Yep, that is exactly what I expected. Your amp is simply passing the PWM signal on to the speaker. Sending a PWM signal to a speaker will sound OK as long as the PWM frequency is above the audio range.

But, as I said before, it may be problematic with a class D amp. There would be aliasing between the two different sampling frequencies that might really mess things up.

Another way to get more output is to simply drive a MOSFET bridge with the PWM signal and the speaker across the bridge. I did this for a microcontroller project with audio output. With a 5V supply you can get about 1.5W, which is basically what the class D amp you linked is doing, and is what the class Ds that claim 3W are doing. You can only get 3W from a bridged amp at 5V with a square wave as the signal.

Bob
Yeah i was thinking of trying the mosfet bridge thing too but regarding the thing for the Class D amplifier what would i need to do additionally to ensure that it would work apart from the RC filter of course since a 3W amp would be better for battery considerations. Oh an sorry for the hassle i am a noob when it comes to the amplifiers and audio stuff
 

BobTPH

Joined Jun 5, 2013
2,866
You should not use an RC filter if you use a MOSFET bridge, it would defeat the pupose and distort badly. The bridge must be driven by a PWM signal.

Bob
 

Alec_t

Joined Sep 17, 2013
11,878
Whatever amp you use, for a given loudspeaker impedance R and given supply voltage V the peak output will be the same. To increase output you need to increase the supply voltage (preferred) or reduce the loudspeaker impedance (may not be practical).
 

Thread Starter

crys17p

Joined Aug 24, 2017
9
You should not use an RC filter if you use a MOSFET bridge, it would defeat the pupose and distort badly. The bridge must be driven by a PWM signal.

Bob
Yes i know that but what i was asking is if i would use the Class D instead of the MOSFET bridge ......what additional steps would i have to do take ensure that it will work properly.
 

dendad

Joined Feb 20, 2016
3,721
Have you fed the PWM from the Arduino into an RC filter to get audio then fed that audio to the LM386 amp or are you still running the PWM into the amp?
The LM386 should be fed with audio, not PWM.
PWM may produce some audio out of the amp but that is not how they were designed to run.
 

Thread Starter

crys17p

Joined Aug 24, 2017
9
The only thing i do not understand is why it is better since when i measure current consumption it is not
Have you fed the PWM from the Arduino into an RC filter to get audio then fed that audio to the LM386 amp or are you still running the PWM into the amp?
The LM386 should be fed with audio, not PWM.
PWM may produce some audio out of the amp but that is not how they were designed to run.
PWM directly and the sound is clear
 

Thread Starter

crys17p

Joined Aug 24, 2017
9
Also what i don't get is that even though the new speaker is louder the current consumption is the same as before. So i do not see why this one works better?
 

dendad

Joined Feb 20, 2016
3,721
Just out of interest, you could try the other way too and compare the results.
That in itself could be a good test. And measure the currents for each mode of operation at similar sound levels.
A bigger speaker will be more efficient so produce more sound.
 
Top