PWM + Sound Generation Conversation II
So here're some basic definitions I think need to be covered (which we have in previous posts, but let's do it again for posterity's sake).
Duty Cycle = Ratio of time on to overall time
RC Filter = This is a low pass filter made with a resistor and capacitor. Depending on what you choose for these components it allows for charging of the capacitor and discharging of the capacitor. When the PWM signal from your MCU goes through this filter, you get an analog wave on the other side.
Notes on the RC Filter courtesy of mgburr and raivisr:
So before the RC filter, no matter the frequency of the pulse widths (how often pwm signal repeats), duty cycle determines the effective voltage. That is to say, 90% voltage from 1 second out to 10 years is still 90% of voltage.
Once you put them THROUGH the RC filter, then the rate of charge and discharge in this filter determines how much is let through. If you set up the charge/discharge to be longer than the pulses, then it's slower to build up and slower to reduce. If the charge/discharge is less than the smallest duty cycle, then you get the straight effective voltage through.
The only time the number of repetitive cycles comes into play is if the charge/discharge time is slow enough to not completely discharge before the next pulse starts. The effective voltage out will still never be more than the input source.
So in a 0-5v pulse, @90% duty is still only 4.5 and after the 4.5 is reached, the rate of charging to 5v is much slower. It may take 20 cycles to reach the 4.5 but 4.5-5v could take 80-90 cycles. Which is why it's important to know what the RC time is, in order to properly gauge what pulse widths will give you the best shape.
Varying the PW is like taking the DC power source and slowly changing the output voltage on the dial up and down. The RC circuit takes those changes and smooths them out to form a more even sine wave.
And an example:
The simple on/off PWM signal modulating a carrier wave:
After putting this signal through a low pass filter (RC circuit):
You see the wave superimposed on the original PWM signal.
And next, some of my thoughts/clarifications.
@atdiy/@tymkrs
















