My microprocessor does not have a DAC, it does, however, have a PWM output. I am wondering if there is a simple circuit I can use to convert the PWM output to an analog DC voltage. It does not need to be terribly accurate, a ripple of around 50mV would be good.
The PWM output is 0-5V, and I can control the frequency from around
1kHz to around 20kHz.
Can anyone tell me specifically what type of filter I need, and what the configuration of the filter is? Also, how to select values? I am willing to read on the topic if someone can point me in the right direction!
What is the maximum frequency at which you wish to wiggle the *filtered* output, and how much attenuation can you put up with at that frequency?
That determines the filter passband parameters. Then you can figure what filter bandwidth and cutoff slope will reduce the PWM 5 Vpp to the desired 50mV. Probably best to run the PWM at the highest possible freq., in this case 20kHz. For example, a simple 20db/decade 1-pole filter, -40dB at 20kHz would require a cutoff at about 200Hz, so you would get a -3dB system bandwidth of that much. More sophisticated filters would give higher possible system bandwidth.
Answer the first question and we can spell out the required circuit in more detail.
Good day!
--
_______________________________________________________________________
Christopher R. Carlen
Principal Laser/Optical Technologist
Sandia National Laboratories CA USA
crcarleRemoveThis@BOGUSsandia.gov
NOTE, delete texts: "RemoveThis" and "BOGUS" from email address to reply.
If your microprocessor has an ADC, you can use that as feedback. Take ADC readings as fast as you can of the filtered output of the PWM pin. If the filtered output is less than the target voltage, increase the duty cycle. If it's less, decrease the duty cycle.
Microchip has technotes on this particular technique, along with sample code, I believe.
Without feedback, a 10k resistor into a 0.1u cap will work for a 20kHz PWM. That will give you about a 40mV ripple, but allow the circuit to follow changes to the duty cycle fairly quickly. The output will be approximately equal to D*Vcc, where D is the duty cycle. Buffer the output with a rail-to-rail opamp. The output will only be as accurate as the pwm steps you can generate. However, since you specify a 50mV ripple, having output that is more precise is pointless.
--
Regards,
Robert Monsen
"Your Highness, I have no need of this hypothesis."
- Pierre Laplace (1749-1827), to Napoleon,
on why his works on celestial mechanics make no mention of God.
Microchip has their own SPI DACs, one of which is the MCP4921. Sadly, it's too slow to do any kind of useful waveform. I guess those SPI DACs are targeted towards things like auto-calibration, or being programmable gain amplifiers.
--
Regards,
Robert Monsen
"Your Highness, I have no need of this hypothesis."
- Pierre Laplace (1749-1827), to Napoleon,
on why his works on celestial mechanics make no mention of God.
I would look at the application notes on Microchips site. Since they never provide a real D/A output (heavy sigh), they do document how to filter the PWM.
--
Luhan Monat (luhanis 'at' yahoo 'dot' com)
"The future is not what it used to be..."
http://members.cox.net/berniekm
Bessel filters aren't the only option - I've used a "synchronous" filter where minimum settling time was all-important, and an equi-phase-ripple approximation to the linear phase Bessel filter where I needed a low-Q first stage.
Neither of them is all that different from the classic linear phase filter.
First you have to analyze what order of filter you need: We have 20dB/decade attenuation for a first order filter and can multiply this with the order for higher order filters. If your PWM-frequency is 10kHz and you want 40dB of attenuation, the low-pass filter frequency should be less than
100Hz for a 1st order filter, 1kHz for a second order or 3.3kHz for a 4th order filter.
If you use this voltage for control purposes, you have to consider the phase angle at unity gain control loop. Only a first order filter will be appropriate if the frequency response of the system to be controlled is close to the filter frequency.
Another consideration is the impedance of the output load. If there is a buffer, you can as well make a second order filter with the opamp, or with the addition of another opamp a 4th order. Use Bessel filters, which do not ring with the steps from the input square wave. There will be also a delay of about 1/3 of the filter wavelength for a second order filter.
If you want passive filtering, for more than 1st order quite chunky chokes are needed.
Please specify the application a bit more precisely, so somebody could come even up with a diagram or some good links.
As the other contributers did already point out, you need a filter with a sufficient high damping at the pwm's repitition rate. If you are out for something better than the processors built in pwm, you should look out for the "sigma-delta-dac" principle, which can be very easy modelled in software. It does also pwm on a single output. The difference is that with sigma-delta the on- and off- periods of the output are not evenly spaced as with simple pwm. Instead on and off change with a high frequency in a kind of pseudorandom manner but with exact the on-off ratio that is needed. With this the time constant of he filter can be reduced by orders of magnitude or, given a certain time constant, the filtrered output will have significant less ripple. If you do even a bit more and do not feed the pin directly into the filter but use the pwm output to let a precision analog switch change it's output between Gnd and a precision voltage reference you will be able to dac a signal with up to 14 bits of precision with ripple < 1 LSB.
Regards Ulrich
"Andrew" schrieb im Newsbeitrag news: snipped-for-privacy@z14g2000cwz.googlegroups.com...
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.