1
\$\begingroup\$

I need to convert a PWM signal with varying duty cycle from the arduino to an analog voltage from 0-5V. I used a RC filter with a time period of 3.9ms. The PWM output has a period of 2ms. I experienced loading effect at the output and therefore I used an op-amp as a buffer. However, I am still experiencing the same problem. My output is ranging from 1.2-5V. I need the output to vary across the entire range of 0-5V. Can anyone suggest a solution for this?

schematic

simulate this circuit – Schematic created using CircuitLab

The op-amp is LM358N.

\$\endgroup\$
  • 1
    \$\begingroup\$ Use an op-amp with a negative supply, usually called Vee. Use a quality op-amp like the TL071, which has offset trim. The output voltage cannot always match the supply voltage due to internal design. \$\endgroup\$ – Sparky256 Feb 6 '18 at 8:06
  • \$\begingroup\$ Apart from supply rail issues mentioned by others, RC filter Tc must be substantially longer than PWM period. You can make an up to 3 pole Low Pass filter withe 1 opamp stage if desired. Note Vcommonmode for LM358 is about 1.5V below Vdd. Son you are lucky to get 5V out!. +/- say >= 7V and <= -1 V should be OK. \$\endgroup\$ – Russell McMahon Feb 6 '18 at 12:42
4
\$\begingroup\$

I used a RC filter with a time period of 3.9ms. The PWM output has a period of 2ms.

You need a longer time period for your filter I would suggest. I would also suggest that you simulate this to see what the output looks like and notice that some artefacts of the PWM signal are still present on the DC level: -

enter image description here

The above uses your numbers and yes, adding a load will alter the filter characteristics and give different results (more ripple voltage). If you have decent bipolar supplies you should be able to use an op-amp but remember, an op-amp can only usually supply loads of up to 20 mA. If you are looking for a more powerful current delivery system you need a power amplifier or the adddition of a transistor.

\$\endgroup\$
3
\$\begingroup\$

What supply voltage are you using? If it is a single 5 V supply then don't expect the LM358 to be able to make 0 to 5 V at its output. Especially when the output is loaded, it will be unable to take the output to the supply rails.

Either give the LM358 more "headroom" so give it a -2 V (or less) and +8 V (or more) supply. For example, use a -10 V / + 10 V supply.

But a much easier solution is to use an opamp with rail-to-rail input and output, for example the MCP6001. Also with this opamp you cannot load the output too much if you want it to be able to reach the supply rail voltages.

\$\endgroup\$
  • \$\begingroup\$ I have tried using a +15V / -15V dual supply as well as a single supply of 12V. None of that worked. I'll try using a different op- amp and try again. Thanks for the answer. \$\endgroup\$ – Devansh Mittal Feb 6 '18 at 9:07
  • 1
    \$\begingroup\$ What is your load? If it's still happening with a+/-15V is it possible you're trying to drive something an op amp can't cope with? Also, what are you actually getting at the input of the op amp? Have you looked with your scope? \$\endgroup\$ – DiBosco Feb 6 '18 at 9:34
1
\$\begingroup\$

You can always make a capacitive voltage booster and then feed that into mosfet's in follower mode. Keep in mind that capacitive voltage boosters are not efficient, they are always less efficient than 50%.

It would look something like this:

enter image description here

I've made arrows that shows which nodes the graph's represent.

The first graph, the one on the left, is the duty cycle of your PWM.
The second graph is the PWM the circuit actually sees.
The third graph is the filtered output of your PWM.
The fourth graph is the output of this circuit, which coincides with the voltage over the first LP filter and the duty cycle of the PWM. If you are actually trying to drive some small motor or something else, then you might as well remove the 1 kΩ at the output.

The 1 kHz sawtooth and the 3 V going into the op-amp to generate the PWM is not an actual part of the circuit, that is a model for the PWM coming out from your MCU.

The output from the first LP enters a P-MOS that is in a follower configuration. The voltage at its source will be the voltage threshold of the MOSFET, so in order to remove this offset I add a N-MOS as the final stage, also in follower configuration.

If the node that says 7.67 V would've been 5 V instead, then the output would only have been able to swing between 0V and 5 V minus the threshold of the N-MOS. In this example the threshold voltage is 1.5 V, so as long as we're feeding it with 6.5 V then the output can swing between 0 V and 5 V.

The "Some oscillator" could be a pin on the MCU or some other oscillating circuit.

I also added another LP filter for extra filtering.


However, you could also just ignore the MOSFET's in follower configuration and just hook up the 7.67 V supply to your LM358 and be done with it. I just wanted to share the MOSFET solution first to show that you don't have to throw op-amps at everything to solve every problem.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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