Question about PWM Low Pass Filter

I am experimenting to make a basic low pass filter to do a simple DAC (for the purpose of digitally driving a LM317), now I calculated out a resistor value of 180k, and cap of 0.22uf, this SHOULD according to the calculations give me roughly .1v of ripple, however my question is do I need a diode between my pwm pin and the low pass filter? Also to test it is it safe to just wire the low pass filter output to my multimeter (monitoring volts), and ground to ground to measure the output from the filter? Once I know the filter is working properly I am going to hook up an op-amp and set it up for a gain of about 2.2 (I am hoping to get an output range of roughly 0 to 12.2v from the op amp) which will get hooked up to an LM317, when I am ready to test that addition of the circuit can I again put the multimeter in series from the op amp output to ground to see the voltage the opamp is actually producing?

I experimented anyway and hooked up my multimeter to the circuit, it produces from 0.02v to 4.20v with PWM output from 1 to 255, so I hooked up the opamp to the circuit to test it out, I factored 4.7k / 2.2k resistors for a gain of roughly 3 times, and this equation works up until a certain point but I do not know why... With pwm output of 1 (0.02) the opamp puts out 0.06, with pwm set to 58 opamp puts off 3.54, at 59 it outputs 3.6, however at 60 it should be 3.66, however it is only 3.63, and 61 (should be 3.72) also only says 3.63 volts, and it stays at 3.63 volts for any pwm output from 60 all the way to 255, how can I figure this out?

I am giving 5v to the Vcc of the opamp from the arduino 5v bus, I do not know if the vcc voltage makes a difference in the equation at all? Ultimately I am expecting the opamp output to go to 12.6v at the high range.

The opamp cant output above the voltage rails. In other words, it can't magically generate 12.6v from a 5v power supply.

You also have to take into account that it may not (depending on the part) be able to reach its power supply rail - it will have some internal limit, and 1.4v sounds about right for some I have seen. Without knowing how you have wired the circuit, and what part you are using, this is just speculation - could you post a diagram.

If you were to give it a +15v supply to VCC of the op-amp, you wouldn't have an issue.

Current Diargram is:

Low Pass Filter: Pin 9 PWM to 180k R1 to .22uf cap (negative to ground), positive to OP Amp + in

Op Amp (LM324 using op amp #1): vcc is connected to arduino 5v rail, ground connected to ground, -in is connected to Op Amp Output via a 4.7k resistor, and grounded via a 2.2k resistor (Should produce roughly 3x gain), op amp output to multimeter for voltage reading

Yeah, for the LM324, essentially Vout max = Vcc - 1.5v, which means that your supply needs to be at least 1.5v above the maximum required output - explaining why it maxed out at 3.6 (~5v - 1.5v).

For 12.6v, you will need at least a 14v supply the Vcc.

Awesome, I am rigging up an old 19v 4a laptop supply to use as a power supply for now, (Do you think they are clean enough to not have to put a cap on it?), ultimately it tells me that I did all my math right on this thing hehe :). Ultimately my plan is to turn this into a 4 channel digital adjustable power supply, I figure I can use all 4 opamps in the 324 (Will doing this take 1.5vx4?) to make 4 adjustable channels. Once I get it working basically and properly I will replace the low pass filters with a real DAC that will produce good clean dc from the pwm to drive the lm317s at desired voltage. Given that they supply 1.5 amps, and probably a bit more (based on some research) if cooled properly, that could make it a great little power supply ;). Once I have all of it working how I want it to, I will make a shield. The shield will support the 4 rails, as well as a single pass through rail, and a 5v rail. The shield will have an attiny chip programmed to manage the rails, and offer control and communication to other arduinos. I will also probably put some sort of basic control system on the shield for easy use without another arduino, just some way to indicate each rails voltage, and a way to change them (Probably 2 buttons), I am still trying to figure out the best solution for displaying, I want to keep this thing relatively small and light weight (Eventually going to be used in a UAV).

Ok I just put an 18v power supply on the rail, interestingly this changed the gain slightly, pwm of 1 set voltage from op amp to 0.09v, and at 255 it set it to 15.50v, I need to adjust my resistor ratio to cap it out at 12.6, though I think when I put this together on shield I will make the ratio adjustable (So the max can be set to 32v).

Now my next trick is to hook in the lm317 and make sure output voltage is nice and stable at the desired voltage.

Well I just tried to attach the 317 into the circuit to set and see if it would give me adjustable voltage, it only gave out stable voltage equal to the main supply rail (18.3v), So I am missing something, but I need to get sleep so hopefully it can be figured out by the morning :).

So, you iron out the PWM into a "stable" DC via the LPF/op-amp.

Once I know the filter is working properly I am going to hook up an op-amp... which will get hooked up to an LM317,...

How does that go?
You're putting the op-amp output to the 317 input? (Hope not.)
Or are you trying to use the op-amp output at/as the 317 Adj?

Why not a power amp on the op-amp output? [See "common collector", a/k/a "emitter follower"]

The collector would go the main supply voltage. D1 and R1 would be omitted. The op-amp output would go to the base via a suitable resistor (so as not to exceed IBmax or IOmax)

Yes the op amp output to the adjust pin of the 317, I was under the impression the adjust was supposed to be equal to the voltage you wanted?

I believe that the output will be VAdj + 1.25V.
[So, it'll never be < 1.25V.]

Well at either rate it is putting out equal to the vIn at the moment... :frowning:

Unfortunately it is not quite that simple. The LM317 output voltage is adjusted using feedback from a resistor divider. Without that feedback loop (i.e. what you are doing) it wont adjust.

This is a simplified example of what the LM317 is:

You can however use this circuit directly. Notice that all it is is an op amp and a potential divider? Why not just ditch the LM317 and get an NPN transistor.

You can connect the output of your opamp to the base of the transistor. The collector goes to Vin and the emitter to Vout.
Your pwm signal goes to the + terminal of the opamp via your Low Pass Filter, and then you complete the feedback loop by using two calibrated resistors as shown in that diagram.

You select your resistors such that there is 5v on the - terminal of the op amp when the output voltage is at its highest.

The opamp VCC should be connected to Vin.

You may notice there are two transistors. This is because a BJT transistor works by using a small current through the base to drive a larger current from collector to emitter. However to drive a large current, say 1A, you need something like 50mA to 100mA on the base. This is more than the opamp can source, so we build what is called a darlington pair.
In this configuration, a small current of say 10mA on base of the intermediate transistor allows something like 100mA to flow from its collector to emitter. As the emitter is connected to the main transistor that means there is 100mA flowing into the base, allowing 1A to flow from its collector to emitter.

You can get transistors which are already darlington pairs, such as the TIP121, or TIP122 for larger currents.

That is interesting but I want to get this LM317 to work properly as it should!

I attached a schematic of where I am at sofar, hopefully someone can give me an idea on what I am missing...

schemeit-project.png

I just noticed I put a ground on the output in schematic, actually that would be test lead for mutlimeter, not ground!

I have just explained why it won't work. There is no feedback loop.

The LM317 doesn't regulate based on the voltage on its adjust pin. It regulates based on comparing the output to a reference.

Try connecting 1.25v to the + terminal of an opamp, and a varying voltage on the other pin, what do you get on the output? The same is happening with the LM317

What op-amp are you using?
Also, a resistor between the op-amp out and V_adj would be prudent.

The output of a 7805 can be adjusted, "up", by placing a diode between its Ground terminal and circuit ground - making its output then 5.8V
If the Adj terminal of a 317 is GNDed, then it's a 1.25V regulator (a "7801.25")

-0-0-0-0-0-

The circuit I suggested in Reply #8, like Tom Carpenter's later reply, is the how an op-amp's output is amplified: a power amplifier.

This however will work:

(Your diagram modified)

alternative.png

Op AMP is a 324 (quad op-amp), I do not have any tip transistors on hand, I know others have gotten the 317 to work this way and I want to get it to work :).