I have a PWM signal on pin 3 from an UNO. It is naturally 5V at around 480Hz.
I would like 0 to 100mV DC out, depending on the duty cycle (0-100%) of pin 3.
I have two RC filters of 330R/1uF in series feeding into one OpAmp (LM324), with the negative looping into out... and then I am stuck. (see attached image)
Do I use the OpAmp out and use a voltage divider (one R a poti) to adjust Vout between 0-100mV? Or can this Vout regulation be done differently / better?
There are 3 out of the 4 OpAmps unused. Not sure what to do with it.
The reaction time of the RC filter is not important; as in: it can take a few hours to go from 50-100mV.
The changes will be only 1mV per time interval and usually increases during the day, and decreases during the night.
I have a PWM signal on an analog out (A4) from an UNO. It is naturally 5V at around 480Hz.
I don't think you have. You can't get a PWM signal on A4.
Anyway-
What you have is two first order filters, but the cutoff frequency is at the same frequency as you are trying to get rid of. The cut off frequency of a filter is just the point where the output drops to half. You need to make the cut off frequency ten or twenty times less that the frequency you want to eliminate. So up the R and C values.
Then put the output of the op-amp across a variable resistor and adjust for 100mV at the wiper.
MaxG:
b) aha, I am learning... got it. 330R/10uF works
Unless there is a compelling reason to stick with ~500 Hz you could increase the PWM frequency. If you want to keep the 8 bit granularity the maximum frequency is 62500 Hz.
I have a voltage divider on the OpAmp out; R1 = 400k, R2 = 10k poti hoping for 120mV over R2.
The voltage is a bit spiky; and plan to put a cap parallel to the voltage divider.
Should the cap have a R in front of it to limit initial current?
Which V does the Vcc of the OpAmp go? 5V?
Having a voltage divider at the output of the opamp defeats the purpose of an opamp buffer.
A varying load will sag the output voltage.
What is the "load" going to be of that 0-100mV signal.
You already said that settle time was not important.
Just use a voltage divider to drop 5volt PWM to 0.1volt PWM (49:1).
That could be 4k7:100ohm.
Then use a big cap across the 100ohm resistor to drop the ripple to what you think is acceptable.
100uF, 2200uF, whatever.
Use 47k:1k if the load is "high impedance". The cap value can be 10x smaller.
Use 470ohm:10ohm if the load is low impedance. The cap value has to be 10 bigger.
Leo..
If you build a simple noninverting amplifier with an opamp, you can put a capacitor in parallel with the feedback resistor from output to negative input. The consequence of this is that as the frequency goes up, the capacitor impedance goes down, so the feedback resistance decreases, decreasing the amplification. I've found that in the past to create excellent low pass filters, and if you want higher rolloff than one such arrangement can give, feed the output to a similar second amp stage.
Wawa:
a) Having a voltage divider at the output of the opamp defeats the purpose of an opamp buffer.
b) A varying load will sag the output voltage.
What is the "load" going to be of that 0-100mV signal.
c) Just use a voltage divider to drop 5volt PWM to 0.1volt PWM (49:1).
That could be 4k7:100ohm.
Then use a big cap across the 100ohm resistor to drop the ripple to what you think is acceptable.
100uF, 2200uF, whatever.
a) I think I am a bit in over my head
b) the load is a shunt input 0-100mV to regulate the charger (in this case)
c) done that, and the ripple is simply gone, negating the 2 RC filters, or at least the second one.
What do I need to do to get the 0-100mV DC coming out of the OpAmp? In relation to the input duty cycle (0-256)?
Remove R2 and everything to the right (no opamp).
The voltage on R3 should be enough if the load doesn't suck away too much.
If you insist on using the opamp, remove R1, R2, C1, C2, and connect R3 directly to the +input.
You might not be able to reach 0mV on a single 5volt supply.
With the opamp, R3, R4 can be 10x, and C3 can be 1/10 of the value.
Leo..
Wawa:
a) Remove R2 and everything to the right (no opamp).
The voltage on R3 should be enough if the load doesn't suck away too much.
b) If you insist on using the opamp, remove R1, R2, C1, C2, and connect R3 directly to the +input.
c) You might not be able to reach 0mV on a single 5volt supply.
a) done... V out is now 1mV to 103.7mV in the simulation
b) done... V out is now 33.37mV to 103.8mV in the simulation
c) I won't by the looks of it... how can I offset the negative V
Also, (OpAmp or not), how can I make the V out precisely match the 0-255 step input range to 0-100mV. It cannot be >100mV or <0mV?
I see and understand that the no OpAmp solution works as good, but I had hoped the OpAmp would bring precision. But this is where I am out of my depth.
Also, do I need some caps in the pos and neg of the OpAmp supply?
c) I won't by the looks of it... how can I offset the negative V
Well it is not a negative voltage it is an offset from zero. Unless you are just simulating it and the simulation has a negative split supply but there is nothing to say this is the case.
There are two ways round this:-
Use a true rail to rail op amp
Use a split supply op amp and have a zero offset adjustment.
Also, do I need some caps in the pos and neg of the OpAmp supply?
Yes always.
Also, (OpAmp or not), how can I make the V out precisely match the 0-255 step input range to 0-100mV. It cannot be >100mV or <0mV?
With opamp it is harder to go to 0mV.
I you add a -5volt supply, it would be easier.
Then you would only have the opamp's offset to deal with.
Without opamp, 100mV (PWM 255) depends on the resistor ratio and the load.
And the peak output voltage of the Arduino.
The 5volt supply could be 4.75volt or 5.05volt.
USB supply could be worse than an external supply on the DC jack.
If you want exactly 100mV, replace the 4k7 resistor with a smaller value and a trim pot in series.
Same story for the opamp version.
Bottom line.
For an output voltage that low it's best to not use an opamp.
That is, if the load is constant.
Leo..