# Eliminate hiss and noise

ATTiny is generating PWM based tones with 32kHz sampling rate. Then I've created R-2R DAC and then trying to amplify it for the speaker.

I need to make low pass RC filter, to cut PWM hiss during playback and some white noise during silence. I have tried to make use of bypass pin but no difference.

So where should I place RC filter and what values in order to filter out PWM hiss and noise during silence?

Update(without scope, I've tried to describe the problem as much as I can):

This is captured on DAC output using sound card, to describe the signal.

Since my sound card is not able to capture the white noise I hear from speaker, I've tried to record voice using my phone.

Sec 22 I turn off speaker pin. Sec 31 turn on again.

• Are you PWMing at 32khz, or a higher frequency? – pjc50 Dec 15 '12 at 13:14
• At 32kHz, similar to this project elm-chan.org/works/mxb/report.html – Pablo Dec 15 '12 at 15:25

You can use the DAC itself as the R part of the filter, and put a C from the DAC output to ground. The DAC appears as a 10k resistor.

What value of C? That depends on the highest frequency you want to generate. I'm going to assume 3dB attenuation at 4kHz is OK, so R = 1/(2*pi*f*C) where R=10000, f=4000, solve for C.

I get 4 nF.

(Incidentally the electrolytic cap C6 is shown wrong way round, + is connected to approx 0V)

I believe you also need to attenuate the input to the amp, it must be clipping at the moment. That attenuation will also reduce the hiss, and allow a second stage of filtering. For example, 20K in series with C6, 10K and 4nf in parallel from pin 3 to ground. Add this if the first filter isn't enough.

• I will update my post with the useful signal characteristics shortly. thanks – Pablo Dec 15 '12 at 12:02
• The issue with doing this is that is causes different bits in the DAC to have different time-constants. – Connor Wolf Dec 15 '12 at 12:05
• with a 2-bit DAC, is that going to be a significant problem? – Brian Drummond Dec 15 '12 at 12:14
• @FakeName: No, that's incorrect. The DAC has a fixed output impedance of 10K. It doesn't vary from bit to bit. If you don't believe me, work out the Thevenin equivalent circuit for yourself. – Dave Tweed Dec 15 '12 at 12:22
• @DaveTweed - Derp, You're correct. I was thinking that the pins driving the DAC were either high or high-impedance for some bizarre reason (or I wasn't thinking at all). – Connor Wolf Dec 15 '12 at 13:22

You have not addressed the fact that you have far, far too much gain.

The LM386 has a fixed minimum gain of 20.

Your R-2R DAC has a output range of 0V-3.75V

With a gain of 20, your theoretical output voltage range would be 0-75V

Basically, you have a 2-bit DAC, with only one-bit of effective resolution.

You need to use a better amplifier. An more common op-amp, such as a TL081 or similar, would work a lot better. Just use it as a unity-gain buffer.

• Not if he's driving an 8 ohm speaker! The 386 is fine; it's easy to attenuate the input once the other problems are under control. – Brian Drummond Dec 15 '12 at 12:44
• @BrianDrummond - He'd have to attenuate before the amp, then. As drawn, it will rail the output. As such, you can't get meaningful results by measuring the output. I don't see how he can get his problems under control , as they're all tied directly to the LM386, which you can't test when railed. – Connor Wolf Dec 15 '12 at 13:19
• @fake_name : of course! Attenuate the input = before the amp. – Brian Drummond Dec 15 '12 at 13:31
• @Fake Name: if possible I would like to use 1 IC, either LM386 or TL081. As far as I understood, with TL081 I have to use 2 ICs, buffer and final amp. correct? – Pablo Dec 15 '12 at 23:52

I would think that placing the filter (assuming you're talking about a simple 1-stage RC filter) between your coupling cap (C6) and the opamp input would be best to get rid of the PWM hiss. The values will depend on the filter characteristics you want (i.e. how much you want to attenuate the 32kHz).