Hey all, trying to build a low-pass filter for an e-bike project. I have a throttle that basically is just a variable resistor. I want to use the arduino and a torque sensor in place of that throttle. My problem is that I can't just put in a PWM'd signal into the system, it's expecting an analog voltage. I want to build a simple low-pass filter to turn my PWM'd signal into an analog voltage. I just don't know the math and how to figure out what size of resistor and capacitor to use. Anyone? Thanks.
Try looking here http://sim.okawa-denshi.jp/en/CRlowkeisan.htm scroll down a little to "RC Low-pass Filter Design for PWM"
Excellent. That helps quite a bit. Thanks.
Now let me see if I can’t get another question answered:
I’m looking at the difference between a filter using a 1uF capacitor versus a 0.1uF capacitor (47k ohm resistor in both cases). I get a 33.8 Hz cutoff frequency with a 0.1uF, and a 3.38 Hz cutoff with 1uF.
In trying to turn my PWM’d signal into an actual analog voltage, I’d just have to make sure that my PWM wasn’t going faster than the cutoff, yeah? I mean, I’m using a low pass filter but I don’t really need to filter any frequencies out (everything I send to it I want back out), but simply to condition the PWM’d signal to make it analog, right? I have a 0.1uF but not a 1uF capacitor. Is there something I’d need to watch out for if I did use one over the other?
Actually if you trying to convert a PWM signal to DC you want the PWM frequency to be above the cut-off frequency.
Using a larger capacitor (having a lower cut-off frequency) will result in less ripple, however it reduces responsiveness.
Basically 3Hz cut-off means you can go from zero to full back to zero in a third of a second or from the time you command full on it takes 1/6 of a second for the output to respond.
If you don't have 1uF capacitor just increase the resistor. A 0.1uF paired with a 470Kohm resistor has the same cut-off frequency as a 1.0uF paired with a 47Kohm resistor.
The problem with a simple RC filter is the ripple, that is voltage variations at the PWM frequency that are small. To minimize this you need a high PWM frequency and a low cut off frequency. Note that cut off is some what of a misleading term, it should be called roll off, as it is the frequency where attenuation has reached half. For a discussion on PWM filters see:- http://www.thebox.myzen.co.uk/Tutorial/PWM.html
Alright, I'm back. Thanks guys for the assistance. What I found out when I did run a RC low-pass with a 47K resistor and a 1uF capacitor was that the 47K dropped the voltage so far that I wasn't getting anything out on the other end. I had to go clear down to a 1K, but then it still wasn't getting all it needed.
Next step: try the 47K, 1.0uF RC low-pass again, but with a voltage follower on the end of it. I'll be using a 741 op amp, it'll have so much impedance that it should keep my current flow to a tiny tiny amount, thus my voltage will stay where it needs to be and I'll pick up the filtered analog signal voltage on the other side of the opamp and be good to go. At least that's the theory. I have to try it this weekend and see what I get. 8-)
I'll be using a 741 op amp,
They are not so good as their outputs can't get close to the rail. That means you have to feed them with greater than 5V and that can cause problems if you are feeding it into an arduino. Look for an amplifier that has a rail to rail output.
By the 'rail' you're talking about the +Vcc and -Vcc values? I'm powering it with +/-9v and am getting 4.98v back out of it when I throw 5v into the 741.
Actually, this is strange. I'm actually only putting 4.72v into the V+, but getting 4.98v back out...
Can you post a schematic? I'd like to see the design of this energy creating circuit :-)
Yea, I'll see what I can do. Lemme' dust off this copy of Eagle that I downloaded a long time ago and never used...
I know it ain't pretty, but here you go:
TestPoint 1 (junction at C1) is where I get my 4.72, TestPoint 2 is where I get 4.98
Uploaded with ImageShack.us
Try adding a resistor, 22K, something like that, from op amp pin 2 to ground, will give it a good reference point. Gain will still be 1.
Good call. Thanks for the suggestion, I'll give it a shot later today.
I would try putting it to pin 3 to ground rather than pin 2.
Isn't the classic voltage follower with feedbackR from output out to vin- and then to ground? With Gain of 1+ (Rfeedback/Rground) =1 with Rfeedback of 0
Are you thinking with a R across the cap to ground it will help keep the cap from just charging up indefinitely? Where I would have said the output going to 0 during the PWM off times would have addressed that, unless Rout was too big to effect much current draw back into the uC.
On the otherhand, is easy enough to try either way while breadboarding.
Isn't the classic voltage follower with feedbackR from output out to vin- and then to ground?
Just google images for voltage follower, you will see both types. I have always used just the feedback with no other connection.