7
\$\begingroup\$

I'm feeding a 250KHz PWM audio signal from an ATtiny85 into a second order active low pass filter:

enter image description here

The output is then fed into a decoupling capacitor and then into an LM324 amplifier. The output of the LM324 is then fed into a decoupling capacitor and then into an LM386 audio amplifier. The audio generally sounds good but there is some distortion. When I view the waveform on OUT1 I get this (the yellow trace is OUT1, the blue trace is after the decoupling capacitor):

enter image description here

What are the strange "drops" I'm seeing? The top of of the waveform looks ok, but the bottom half has these drops. This is some type of distortion, yes? What causes this? How can this be eliminated?

UPDATE 1: Here's the PWM from the ATtiny85:

enter image description here

UPDATE 2: I stated above that

The output is then fed into a decoupling capacitor and then into an LM324 amplifier.

This is not correct. What I should have said was the output of the LM324 is fed into a decoupling capacitor and then fed into an LM386 audio amplifier.

UPDATE 3: Here's 12ms of the 250KHz PWM input:

enter image description here

UPDATE 4: Here is the complete schematic:

enter image description here

Addressing some of the comments and the suggested solution:

  1. I moved the Vcc for the LM324 from the regulated 3.3V supply to the +6V supply. This did clean up the signal coming from the LM324 (i.e. the recovered audio from the PWM input), but significant distortion can still be heard. I still need to test to see if the LM324 is failing at specific frequencies.

  2. I added a 1K resister from the output of the LM324 to ground. Originally I did this to address a comment suggesting that having the output float was not a good idea. The proposed answer says (if I understood it correctly) that this 1K resister tied to ground should force the LM324 output stage into a class A amplifier, thus avoiding a crossover problem. However, at the time this was suggested to resolve any crossover problem, it was already in place.

Is it possible that the LM324 is just a very bad choice for audio? I've heard it has a relatively slow slew rate that causes distortion. Should I be looking at another op amp (that works with a single +6V supply)?

UPDATE 5:

Here are the traces from the current circuit. Yellow is the output from the LM324. After moving the power supply for the LM324 from the +3.3V regulated to the +6V, you can see that there are no more drops (which technically resolves this question). The blue trace is the output from the LM386 audio amplifier. There is distortion on the bottom of the wave and it's pretty audible. I think if I can resolve this distortion I'm good to go. And this pretty much proves that the LM324 is "good enough" for this audio application.

enter image description here

UPDATE 6:

I stated earlier that the LM324 was "good enough" for my application, and this is true. If you examine the output waveform from the LM324 at higher resolution it can be observed that the signal is "noisy" (I did not include a trace of this). Simply unplugging the LM324 and plugging in an MC34074APG (with no other changes), substantially cleaned up the output waveform. This may become my new favorite single source op-amp.

\$\endgroup\$
22
  • \$\begingroup\$ You need to reference the + terminal to ground somewhere (through some impedance). Your whole circuit is not included, but if you just have a floating decoupled input, that is probably not suitable. \$\endgroup\$
    – Daniel
    Commented Jun 17, 2016 at 23:20
  • 1
    \$\begingroup\$ What does the output of the MCU look like? I suspect that you have a firmware problem. \$\endgroup\$
    – Mark
    Commented Jun 17, 2016 at 23:46
  • 1
    \$\begingroup\$ And what is the \$\text{V}_\text{cc}\$ and \$\text{V}_\text{ss}\$ of the LM324 in your circuit? \$\endgroup\$
    – rdtsc
    Commented Jun 18, 2016 at 0:10
  • \$\begingroup\$ @rdtsc 6V and 0V respectively, using 4 AA batteries in series. \$\endgroup\$
    – mbmast
    Commented Jun 18, 2016 at 0:53
  • 1
    \$\begingroup\$ And one more comment: you are using "high voltage" OP AMP on its lowest (extreme) supply range: 0 / 3.3 V. You have to use special low voltage OP AMPs, for example, rail-to-rail OPA365. I would never use high voltage OP AMP on 3.3 V supply. \$\endgroup\$
    – Master
    Commented Jun 18, 2016 at 10:13

3 Answers 3

7
\$\begingroup\$

The LM324, while a brilliant achievement with 1970s transistors, has one well known bug - actually documented in its datasheet. This answer is based on a guess that you are running into this bug.

Some people sneer at it because of limitations like this - but it is still a fine opamp if you design to its limitations.

Its Class B output stage is specifically designed for low power but it is asymmetric : that is, it can pull up (towards V+) quite strongly, but cannot pull down very effectively. This avoids excessive current consumption where both output transistors might be momentarily turned on together (as in the bipolar 555) - a possibility given the relatively low speed of these transistors.

(See Table 6.5, page 6, Output Current section, in the datasheet - at 5V it can source 20mA but only sink 8 uA, so the pullup is 2500 times stronger)


This combination of circumstances : Class B output stage, slow transistors, asymmetric strength, gives it a particularly bad case of crossover distortion on high frequency signals, there is a region where both output transistors are off and the output voltage is effectively undefined.

Run a sinewave at a few kHz through this filter (unit testing is as valid in hardware as it is in software!) and you'll see large bites taken out of the output waveform.


The (documented if you look for it ... EDIT ... it's in section 7.4 on page 11, and my memory of the problem is slightly off) fix is to force the output stage into Class A, with a few kilohms of pulldown resistor to V- (I suggest 1K at this low voltage). Now the pulldown transistor never has to turn on at all (though no harm done if it does) and the much stronger pullup transistor is always in control, pulling against the resistor.

Thus the 324 is designed to be used successfully in Class B for low speed low power designs, or Class A for faster designs.

The downside to Class A is obviously increased power consumption - if that matters, nowadays you can choose a better opamp.

\$\endgroup\$
4
  • \$\begingroup\$ Interesting. I was attracted to the LM324 because of its ability to operate with a single power supply. I will test with a sine wave as you suggest. Running into weekend commitments so I may not post till Monday. \$\endgroup\$
    – mbmast
    Commented Jun 18, 2016 at 22:34
  • \$\begingroup\$ It turns out that R17, 1K, has been in the circuit for a while now and this has not resolved any distortion issue. This was what you were suggesting, yes? \$\endgroup\$
    – mbmast
    Commented Jun 21, 2016 at 2:11
  • \$\begingroup\$ Yes. Had you posted the schematic in the first place there would have been no need for my answer. The remaining problem looks like you may be simply asking too much of the LM386 : turn the volume down a bit! \$\endgroup\$
    – user16324
    Commented Jun 21, 2016 at 8:33
  • \$\begingroup\$ While I continued to have distortion problems after passing the output of the LM324 to gnd through a 1K resistor, this resistor solved the problem I asked about in this post. Since then I've eliminated this additional resistor and the pot and replaced the pot with a voltage divider whose total resistance is about 1K ohm, so I'm still forcing the LM324 into Class A operation, as per this answer. Adding additional jumpers between the breadboard's 4 power rails (it's a 3-up breadboard) substantially eliminated any remaining distortion. LM324 and LM386 are noisy, but good enough for this app. \$\endgroup\$
    – mbmast
    Commented Jun 22, 2016 at 4:26
1
\$\begingroup\$

Am I missing something here? The LM324 has a gain bandwith of 1.2 MHz. So, its usefull frquency range is to about 10 kHz on a good day. You wanna feed it a 250kHz square wave? Good luck with that.
I'm thinking you will have better results with passive filtering maybe.

\$\endgroup\$
7
  • \$\begingroup\$ You should edit your comment into your answer. This is indeed a good observation and a critical problem when trying to create analog waveforms from high frequency, low-resolution signals (PWM, delta-sigma modulation). \$\endgroup\$ Commented Jun 21, 2016 at 4:06
  • \$\begingroup\$ Yes, you are missing something here. The PWM signal going into the LM324 is 250KHz. The PWM signal is the result of modulation by 16 bit audio sampled at 44.1Hkz. Basically, is is a Microsoft WAV file. What comes out of the LM324 is audio, mostly around 2KHz (you can see this in the scope traces). The 2nd order active filter, built around the LM324, has a cutoff frequency of around 4KHz (or maybe it was 3KHz...). And the filter output, yellow trace, looks pretty good. \$\endgroup\$
    – mbmast
    Commented Jun 21, 2016 at 4:10
  • \$\begingroup\$ Ignore my last comment. Ok, yes I'm feeding the LM324 a 250KHz signal and apparently it's limited to about 10KHz. But still, the output signal looks pretty good. There's no distortion in the output from the LM324. \$\endgroup\$
    – mbmast
    Commented Jun 21, 2016 at 4:14
  • \$\begingroup\$ Isn't the gain of the LM324 unity (one) in the schematic I supplied? If so, doesn't this give me sufficient bandwidth for a 250KHz PWM signal? \$\endgroup\$
    – mbmast
    Commented Jun 21, 2016 at 5:52
  • \$\begingroup\$ Yes, but this is a strange sort of filter. The filtering is being done by the speed of the op-amp! At least consider something passive. \$\endgroup\$ Commented Jun 21, 2016 at 14:52
1
\$\begingroup\$

The Sallen-Key filter suffers from the fact that it uses a combination of positive and negative feedback - if you are forced to use an amplifier with limited bandwidth then the multiple feedback configuration is often a better choice. See http://www.ti.com/lit/an/sbfa001c/sbfa001c.pdf

\$\endgroup\$
1
  • \$\begingroup\$ This looks like a pretty good tool. It would be better if it could suggest and take into consideration the op amp being used. The text suggests the reader consider the TI UAF42, a very expensive op amp at about $18 for a single unit. As I stated in an update to my question, the MC34074 is pretty good and around $1.36 per unit. \$\endgroup\$
    – mbmast
    Commented Sep 15, 2016 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.