Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Re: Using a capacitor to convert PWM to a voltage

2012-08-21 by Bernd Felsche

On Tue, 21 Aug 2012 06:14:40 Don Kinzer wrote:
> --- In AVR-Chat@yahoogroups.com, Philippe Habib <phabib@...> wrote:
> > Can someone provide some guidance about how to size the capacitor
> > and what type of capacitor is best suited for this type of thing?

> You need a resistor in addition to the capacitor.  The values for
> the R and C to get good filtering will vary depending the chosen
> PWM frequency and the impedance of the load.  (The PWM signal puts
> charge into the capacitor during the on time and draws it out
> during the off time; the load draws charge out of the capacitor.)

> In order to calculate acceptable values for R and C, one would
> need to know the PWM frequency, the load impedance, the desired
> responsiveness and the allowable error voltage.  For a one-off
> project, it may be simpler to try some values and determine what
> works well enough.  For example, for a 1KHz PWM signal you might
> start with 100 ohms and 10uF.  An oscilloscope would be useful to
> be able to "see" the resulting signal.

Other than PWM into an RC network, another method is to use a
capacitor that is fed from a high supply via a resistor and "bled"
via a FET driven from a digital output of the AVR. The 0-10V output
is realized via a small resistance into smoothing cap; the voltage
on that being the 0-10V.

If the output voltage is scaled (high-impedance R-divider), then
that can be fed into an ADC pin as a feedback for driving the pin to
the FET gate. Software closes the control loop. i.e. the measurement
of the output voltage is used to adjust e.g. the PWM ratio to achieve
the desired voltage. That's basically how a DAC works inside a
package so this is a "Superman-DAC"; wearing its underpants outside
of the suit.  :-)

NB: When the AVR is stopped, the output voltage can rise up to the
high supply's voltage.

-- 
/"\ Bernd Felsche - Innovative Reckoning, Perth, Western Australia
\ /  ASCII ribbon campaign | For every complex problem there is an
 X   against HTML mail     | answer that is clear, simple, and wrong.
/ \  and postings          |  --HL Mencken

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.