The question that arises in the design of a simple PWM DAC is what the low-pass filter pole frequency should be relative to the PWM frequency. This question is addressed by deriving the design equation.

Microcontrollers typically have PWM outputs that can be used as D/A converters when speed is not a constraining design criterion. A simple RC integrator following the output from the ÎĽC averages the PWM, where the average voltage is

and *D* is the duty ratio (or duty cycle) of the PWM output; *V* is the high-level and full-scale (fs) voltage. For lightly loaded CMOS outputs, it is the supply voltage, *V _{CC} * . The PWM square-wave from the ÎĽC and the RC-integrated waveforms are sketched below with exaggerated ripple.

The voltage ripple is

And the full-scale fractional ripple is

For *n* bits of resolution, the fractional ripple (as a fraction of fs) is required to be

The exponential *v _{H} * and

*v*waveforms follow from basic circuit analysis. The

_{L}*v*(t) waveform during the off-time begins at the peak ripple voltage of

_{L}*v*and exponentially decays toward 0 V, the logic low-level voltage of the PWM output. The time of the minimum

_{H}*v*value is at

_{L}*t*= (1 â€“ D)â€˘

*T*. Substituting this value for

_{s}*t*, the value of

*v*is

_{L}

And for *v _{H} * , the rising exponential begins initially at

*v*and rises over a voltage range of

_{L}*V*â€“

*v*toward a target voltage of

_{L}*V*. The value of

*v*is that at

_{H}*t = Dâ€˘T*:

_{s}

Substituting *v _{L} * into the expression for

*v*and simplifying,

_{H}

Then

For *T _{s} /Ď„* << 1, in general, using the first two terms of the Taylor-series expansion of the exp function,

Then the fs fractional ripple and its approximation are

For *D* = 0 and 1, the ripple is zero and is greatest at *D* = 0.5. Then

A more convenient ratio than that of time is that of frequency for RC integrator design. The RC integrator pole or break frequency is its bandwidth; *Ď‰ _{bw} * = 1/

*Ď„*and

Also,

Combining these and solving for the ratio,

For *n* -bit resolution, substitute Î”*v/V* = 2^{â€“n } . The result is

If solved for the number of bits required, the design formula becomes

From this design formula, for which *Ď„ = Râ€˘C = 1/2â€˘Ď€â€˘f _{bw} * and

*f*is the PWM frequency, the following table gives the calculated values for an even number of bits of resolution. The numerical pattern is simply that

_{s}*f*changes by an octave for every bit of change in n.

_{s}/f_{bw}

A mnemonic for remembering the formula is that, for 6 bits, the PWM frequency must be 100 times higher than the integrator pole frequency. Then scale by 2 for every bit difference; 7 bits requires about 200 times, and 5 bits requires 50 times.

Depending on the resolution of PWN, RC value might be changed. PWM frequency is dependent upon clock frequency of microcontroller. I think that determining RC value could be relaying on what type microcontroller is used in the board in order to capture the correct analog information. In addition to that, DAC chip could accomplish the PWM DAC design, or output of microcontroller feeds back to it again, if this contains both ADC and DAC module.

The purpose of the article is to show what the value of the RC time constant or its corresponding pole should be for n bit resolution – that is, for PWM ripple that is less than 1 LSB for n bits. It does not matter what uC is used. Many CMOS uCs have PWM output capability and within the resolution of the uC PWM resolkution, the output voltage can be generated with a simple RC integrator.

The question then for a designer is: how low does the RC integrator pole have to be below the PWM frequency for ripple that is less than n bits in resolution?

@DaeJ: Can the temperature be controlled here ? I saw an article where a device which allows the user to control the temperature as wand when required. It also had the customizing facility too. Â

The problem I have always had with this method is that you lose your upper and lower bits. That is, when the PWM value is low, the filter sort of stops working (just reads at 0%) and when the PWM value is high, it also stops working (just reads as 100%). Â At the end of the day, it is a nice solution if you do dot have a DAC in house or you are VERY tight on space.Â

The problem I have always had with this method is that you lose your upper and lower bits. That is, when the PWM value is low, the filter sort of stops working (just reads at 0%) and when the PWM value is high, it also stops working (just reads as 100%). Â At the end of the day, it is a nice solution if you do dot have a DAC in house or you are VERY tight on space.Â

Dennis

I have had this issue several times. In the past I have had to dig for a TI or Microchip app note, but none have been as succinct and definitive as this. Thanks.

I think that temperature could be controlled here with other circuit: Temperature is raw analog signal and this data goes into microcontroller through signal condition circuit; and microcontroller will manipulate the data and is requiring the target temperature that user setups in the display screen.

Â

Serial peripheral interface, between PWM output from micro and other chip, could be connected via the pull-up register with VCC (5V or 3.3 V). I am wondering what application could get this benefit by RC formula. DAC chip might be recommended, unless chip is designed. This formula might provide the guideline for the selection of DAC chip.

Thanks for the post Dennis, it will be very useful for many of us.

When I started playing guitar I also got very interested in DIY effects processors. A colleague from the department, also a guitar player, came up with the idea of creating a digital echo/delay using a 64kbit RAM memory chip we had at hand, a comparator, a couple of R-C low pass filters (one for the 1 bit A/D and one for the 1 bit D/A). The results were surprisingly good but selecting the cut-off frequency for the reconstruction low-pass filter was critical. Using the same principle, this colleague created an analog output interface for voice synthesis with a very old IBM XT computer.

I've seen also a low power motor closed loop speed control application where a feedback correction (manipulation?) voltage is generated using one PWM output followed by an R-C low pass filter.

@victor: Is it stable enough ? Im referring to the low power motor

@Gibson: Thank you for the update mate just one query, what sort of a capacity can it carry ? I presume it's a very small gadget where you can squeeze it in. Â

@chirshadblog, The low power motor is a sensorless brushless motor which includes a very rudimentary controller. The motor speed is directly proportional to its power supply voltage and inverselly proportional to a fraction of its current consumption (which depends on the load).

Speed control is accomplished by using a BUCK DC-DC converter for regulating the motor's supply voltage. By injecting a small voltage into its feedback chain it is possible to control the regulator's output voltage (withing a small range).

The closed loop control strategy is implemented using a modified (simplified) PID controller and timing is controlled by the PID tuning parameters.

One timer channel is used for the PWM output and the other for measuring the current motor speed (using a sensor).

The motor mechanical load has a relatively low inertia and never changes abruptly, only when the whole system is started or shutdown. It outperforms the initial specs and keeps the motor speed in the required range. Some of these systems are still working without interruption from their installation more than five years ago.

Target speed and feedback speed might go to OPAMP comparator that generated Error. System is feedback controller. RC low pass filter is for filtering signal. Low pass filter might be the second order filter which is adding extra R/C in serial pattern. I am not sure that filtering the signal is related closely to n bits formula relating PWM frequency and RC frequency in this article.

Gibson,

The “loss of bits” at each end of the PWM range is really no loss at all in that the values are exactly what they should be, and without ripple. It is at midscale that the largest ripple occurs.

If the ripple is constrained to be within a LSB (and assuming the PWM generator is linear, which as a digital device should be very linear in time), then the lack of precision of the PWM DAC is largely caused by the resistance of the CMOS output switches which connect the output to either the supply or ground. If a large R value is used to minimize output loading, then this scheme should be good for as many bits as the digital PWM generator itself. The biggest limitation is that the output frequency is limited, rendering this scheme usefual mainly for setting voltage parameters in uC-controlled analog circuitry.

Dennis,

I would like to know what happens when the frequency chosen is much greater than those factors in the table. For example, I choose a frequency of 200 times for a 10 bit resloution?

Â

Thx

I guess for better operation we need to adjust LPF cutoff frequency such that the residual voltage ripple is less, also increasing PWM frequency can improve DAC response.

For a switching frequency greater than that given by the table or equation, the ripple is less than an LSB. In other words, the result improves.

DF

Â

For a given set of RC values, if the frequency selected is higher than specified, would it have an effect on the response time of the resultant analog signal. Will there be a latency between the PWM change and analog signal.

Vasanjk,

In my previous post, I was referring to the PWM frequency and its effect on the DAC output waveform ripple, though as you noted, the waveform dynamics are also affected by both PWM and DAC output waveform frequencies.

Although the article did not address DAC dynamics, the DAC will have the usual zero-order hold (ZOH) transfer function. The output waveform will be delayed by half the PWM period and as the waveform frequency increases, will roll off (magnitude will decrease) until it is zero at the Nyquist frequency of half the PWM frequency.

The PWM DAC is not known for its dynamic performance yet is a valuable means for minimizing circuitry when a static or near-0 Hz waveform is required, such as setting analog parameters.

DF

That was an extensive reply. Thanks. By the way, one of my colleagues tells me to use a current source to drive the RC while the PWM waveform is used to switch the current source accordingly. He claims that output voltage linearity would be much improved. Any thoughts on this?

Vasanjk,

First, there is no point in driving an RC integrator with a current source; the R in series with the source has no effect on circuit behavior because the current source is already an infinite resistance.

As I understand the advice you've been given, the scheme is to switch a current source into (let us say) a capacitor. This resuls in triange-waves instead of the exponential-waves in the article. It would be a good exercise for you or your advisor to work out the equations for this scheme; it is easier than the derivation presented in the article but you can use the article as a kind of template in doing it. (Then submit the result for publication, perhaps.)

I have not done this particular derivation but I think you'll find that the result is not much different than what is in the article. The reason is simple: the exponential ripple is intended to be small and the exponential waveforms are much less than a time constant. This makes them nearly linear, like the triangle-waves of the switched-current scheme. Consequently, I think you can apply the equations of the article as being closely approximate for the suggested scheme.

Hi Dennis, I must admit that this information proved to be quite useful especially the derivation of the design equation. With everything lined out and well explained, modelling of a simple PWM DAC has been reduced to a simpler task.

@ DaeJ, that is well explained in brief and concise format.

@ Victor Lorenzo, I was just wondering the maximum number of years an installation based on

your explanation would go for.

@SunitaT0, according to customer's requirement, the electronics part is required to work without interruption for at least 10 years. The mechanical part allows routine maintenance (cleaning, oil, etc) once every five years.

I reviewed the given derivation and noticed that the denominator was approximated by 1 instead of the exponential approximation. When it is used instead, then the result is

D*(1-D)*(Ts/tau) = 2^-n

and (Ts/tau) is not squared because the one in the denominator cancels one of them in the numerator. Then the result is that the x100 ratio for fs/fbw applies to 6 (not 8) bits and this number scales by 2 times per bit. For 7 bits it is x200 and for 5 bits, x50. These more conservative numbers show even more why this is not a fast DAC!

Â

I realize there is more than one way to skin a cat. Â Such is the case with DACs. Â You can use fully digital Â techniques to create precise voltages with respect to a reference by working out the on –off ratios mathematically and implementing them digitally — with simple digital blocks. Â

A simple way that I use, and uses less overall silicon is to work out binary area ratios of devices and use resistors, capacitors, and even devices — components one have to use anyway to Â create and implement any useful device/product. Â For example, a simple string of resistors — equal weighted resistors with a simple switching matrix can create without trims, and without complex error correction up to 10Bits (~1024 levels) and with minor complication to ~20Bits. One can even throw in error correction algorithms — especially non-linearity correction–simply and in a very straight forward manner. Â The correct design of the basic DAC can be fully monotonic as well so the only need for error correction is the inevitable non-linearity as the design goes beyond 16Bits.

Mixed signal analog-digital design is probably the most powerful design methodology of any that I personally know. Â It can create machines of any complexity/intelligence. Â By the way, all can be fully computer simulated so one knows for certain that whatever idea you may have created will work first time and every time.