Low pass filter RC values for varying PWM duty cycle

Discussion in 'General Electronics Chat' started by mdylanmst20, Jun 12, 2017.

  1. mdylanmst20

    Thread Starter New Member

    Jun 5, 2017
    19
    0
    Hello, I have a circuit that outputs a digital signal. The signal is PWM signal whose duty cycle is constantly changing. I want to be able to read the analog output of the circuit with as little power loss as possible. I'm thinking that I should use a Low Pass filter but I'm lost as how to calculate what my values for my resistor and capacitor would be. Any help or input would be much appreciated.
     
  2. crutschow

    Expert

    Mar 14, 2008
    22,119
    6,406
    You determine how much ripple you can tolerate in the signal from the PWM frequency and then calculate the filter value to give less than that.
    What are the PWM and modulation frequencies?
    Depending upon the difference between those two frequencies you may need to go to a higher order active filter to get the results you want.
     
  3. mdylanmst20

    Thread Starter New Member

    Jun 5, 2017
    19
    0
    Sorry I am very new to electronics/circuits and am not as familiar with the terminology as I would like. So I would like to measure the circuits current output as an analog rather than digital signal. What I know thus far is that ripple is the variation in voltage of the signal after it passes the filter? I'm not really sure how the magnitude of the ripple will effect my current measurements so I would assume I would want it to be fairly low? Also when you say modulation frequencies, what do you mean? My PWM signal is running at 1 kHz but the duty cycle is changing over time any where in it's full range of zero to one hundred percent through my raspberry pi, as I've coded it that way. The point of my circuit is to emulate the current draw of a dc motor which is in a food pump and to hook the circuit into the pump and trick it into thinking it's got the motor attached and running. The pump takes current readings of the motor to monitor it and I believe that whatever the means the circuit uses to measure the current it takes an analog signal.
     
  4. crutschow

    Expert

    Mar 14, 2008
    22,119
    6,406
    There is a tradeoff between the ripple from the filter due to the PWM frequency and the rolloff of the maximum signal frequency.

    What is the fastest rate that the simulated duty-cycle will change (modulation frequency). In other words what is the shortest time it will it take to go from one duty cycle value to another (how fast is the simulated motor current changing)?
    That will determine the type and order of filter you need.

    The amount of ripple allowed depends upon how much the food pump circuit can tolerate.
    For example, if 1% ripple can be tolerated then it should be a least a factor of 100 (40dB) below the maximum signal level, so the filter would need to rolloff the 1kHz PWM frequency by at least -40dB.
     
  5. mdylanmst20

    Thread Starter New Member

    Jun 5, 2017
    19
    0
    So my PWM duty cycle changes by 1% every 25 ms so if it went from 0 to 40 percent duty cycle it would take around 1 second. If i was to say that the food pump circuit could only handle 1% ripple, how would that affect my circuit? Due to my ignorance of circuits I'm really not sure what your meaning when your talking about the roll off frequency. Does that relate to the frequency i'm running my PWM at or am I totally off? Do they relate (PWM frequency and roll off frequency). Thanks for your help thus far.
     
  6. crutschow

    Expert

    Mar 14, 2008
    22,119
    6,406
    Rolloff frequency refers to where the filter response is -3dB down from the in-band frequencies.

    So if it takes 1 second to go from 0 to 40% duty-cycle, then the frequency of interest is quite low, in the neighborhood of a few Hz, thus we can use a filter with a low rolloff frequency to get good PWM ripple suppression.

    Below is the LTspice simulation of a 500Hz PWM signal with a 1 second ramp modulation, V(mod_in), and the output, V(out) from a simple RC filter with a 3Hz rolloff that gives about a 1% ripple.
    The bottom trace is the output expanded to show the ripple detail which is about 45mVpp.
    If you need less ripple, then we could go to a better (active) filter using an op amp.

    upload_2017-6-12_16-23-2.png
     
  7. mdylanmst20

    Thread Starter New Member

    Jun 5, 2017
    19
    0
    Could you do me a favor and relate the characteristics of a PWM signal to the required RC filter to give good ripple suppression? I'm just still not understanding how you got a few hertz for the roll off frequency and how that relates to which components I should choose to use for my filter. I do believe I understand what your meaning when your talking about an active filter. I should use it if the simple RC filter isn't cutting it because it can boost the output of the circuit in comparison to the RC filter which cannot. Thanks for bearing with me.
     
  8. mdylanmst20

    Thread Starter New Member

    Jun 5, 2017
    19
    0
    I've also tried to read a lot about RC filters online and I get the basic concepts, but am lost on how to apply that to PWM. Does the cut-off frequency relate to what the frequency of my PWM is at all?
     
  9. OBW0549

    Distinguished Member

    Mar 2, 2015
    2,860
    2,626
    Yes, it does; the lower the filter cutoff frequency, the less ripple you'll get at the PWM frequency. However, the lower the filter cutoff frequency, the more sluggishly the filter output will respond to rapid changes in the PWM value. Choosing an appropriate filter amounts to finding an acceptable compromise between those conflicting needs-- removing the PWM ripple, yet responding quickly enough to a change in PWM value.

    That isn't the reason for an active filter's superior performance; the main reason is that active filters can implement what's called a "higher-order" filter which can do the same job as cascaded RC filter sections, but without the sloppy roll-off characteristics you'd get with a passive filter. In other words, an active filter will do a better job at making the compromise I mentioned above.
     
  10. mdylanmst20

    Thread Starter New Member

    Jun 5, 2017
    19
    0
    So what cutoff frequency would be appropriate for a PWM signal at 1kHz that changes it's duty cycle constantly? What is the relation between the power that is input into the filter and the power you get out? I've been testing out different capacitor and resistor values and have found voltage drops (power loss) across the filter. It's not that I'm not expecting a voltage drop, I'm just wondering if there is any way to minimize the power loss. I also am not getting the clean voltage i would expect. The voltage on my scope is showing a fuzzy range of voltages instead of a more precise dc voltage that I would expect to appear as a line when I change the range of the time to seconds. Right now when I zoom in on the scope the square waves have turned into what looks like tidal waves or shark teeth. Thanks for your input so far.
     
  11. crutschow

    Expert

    Mar 14, 2008
    22,119
    6,406
    Are you trying to extract power from the PWM signal or just voltage?

    The voltage you get out of the properly designed filter is the average of the PWM signal (the duty-cycle times the peak voltage).

    Telling me you have a fuzzy image on the scope doesn't help much.
    If you want good answers I need good data.
    What is the amplitude of these "shark teeth" (which is the ripple I mentioned)?
    What PWM frequency and filter were you using?

    The higher the PWM frequency you use, the lower the ripple voltage for a given filter.
    How high a PWM frequency can you generate?
     
  12. OBW0549

    Distinguished Member

    Mar 2, 2015
    2,860
    2,626
    I'm not sure what you mean here by "power loss." We don't normally try to deliver power per se through a filter (except in the case of a low-loss LC filter such as in switchmode power supplies), nor do we characterize filters as having a "power loss."

    If you mean the DC voltage you're getting out of the filter is less than you expected it's most likely because you're feeding the filter output into some load resistance, in which case the load resistance and the filter resistor are forming a voltage divider. Operate the filter without a load on its output, and you should get the expected DC output. (NOTE: I don't know what RC values you are using, but if your resistor is very large, the scope input resistance alone could be loading down the filter output and reducing the observed voltage.)

    I think in your case, just to keep things simple and avoid going into the complexities of active filters, a simple multi-section RC filter might suffice. Try making a simple four-section RCRCRCRC filter (four RC sections, with the output of each section feeding the input of the next section) with 10kΩ resistors and 0.1μF capacitors. My simulations indicate such a filter will give you about 3 millivolts of 1 kHz ripple max., and a response time of about 20 milliseconds. From what you've said, I suspect that will be good enough.
     
    crutschow likes this.
  13. crutschow

    Expert

    Mar 14, 2008
    22,119
    6,406
    Below is the simulation of the PWM circuit for a 1kHz, 5Vpk PWM signal with OBW0549's four section output filter.
    The output closely follows the input modulation (duty-cycle variation) with a ripple of ≈3.5mVpp.

    upload_2017-6-13_10-17-49.png
     
    OBW0549 likes this.
Loading...