Language: EN

salida-analogica-mediante-pwm-y-filtro-paso-bajo

Analog output via PWM and low pass filter

In this previous entry we saw how to use PWM outputs to simulate an analog voltage output.

However, we made it clear that a PWM output is not an analog voltage signal, but a pulsed digital signal whose average value is the desired value. Ignoring this can lead to unexpected behaviors in the components we connect to the PWM signal, or even damage them.

As we said, having a component expect an analog voltage signal and receiving a PWM is similar to asking for a gentle massage on the head and getting hit with a hammer every 20 seconds (the average will be the same but… it’s not the same).

There are several mechanisms we can employ to improve the response of our PWM, so that it better approximates a true analog signal. One of the simplest is to use a low-pass filter to “smooth” the signal.

In this entry, we will see how to incorporate a low-pass filter into a PWM output to improve its behavior so that the output obtained better approximates a true analog signal.

Incorporating a low-pass filter

A PWM output is a mechanism frequently used by automation systems to emulate an analog signal. It consists of providing a pulsed signal at a certain frequency, whose average value is the desired analog value. But the applied voltage value is, at all times, a digital signal between -Vcc and +Vcc.

For example, if we want a PWM signal of 1V with a Vcc voltage of 5V, a signal will be generated that will be 5V for 20% of the time and 0V for the remaining 80%.

If the system’s response is slow compared to the PWM frequency, the PWM output may be sufficient. Conversely, in other cases, it will not be, and we may even damage the powered component if the Vcc voltage exceeds the maximum allowable voltage for the component.

To improve the analog output response, we have several options, and the simplest is to incorporate a passive low-pass filter using an RC network.

A low-pass filter is a component that removes high frequencies from a signal, allowing low frequencies to pass through.

The electrical schematic is as follows, where we see that we have superimposed the RC filtering network between the PWM output and the filtered signal, which is what the load receives.

arduino-filtro-paso-bajo-pwm-esquema

As we had mentioned, the system’s response is a dampened signal of the PWM signal, but it still is not a perfect analog signal. An example of the response is as follows:

arduino-filtro-paso-bajo-pwm-respuesta

We must observe that the produced signal has two relevant parameters.

  • Response time: The time it takes for the signal to reach steady state (a certain percentage of the desired signal)
  • Ripple: The small oscillation that remains after the filter.

These two effects are “opposite” to each other. That is:

  • If we try to reduce the ripple, we will need very long response times.
  • If we try to reduce the response time, we must accept a greater ripple.

Therefore, there is no single optimal filter and signal. We will have to make a design decision and accept a trade-off between a certain ripple value and a response time.

Adjusting R and C in the low-pass filter

The characteristics of the response will depend on:

  • The PWM frequency
  • The voltages of the filtered signal and the desired signal
  • The chosen values of R and C

To calculate these parameters and visualize the obtained response graphically, we can use the RC network calculator available at this link.

Limitations of a passive filter

The proposed low-pass filter is useful for providing an almost analog voltage value and even powering small loads. However, it is not suitable for powering large loads.

Higher power loads have lower impedances. When this impedance is lower than that of the RC network, the load consumption causes the obtained signal to deviate from the theoretical one.

A simple way to avoid this is to use an operational amplifier to create a voltage follower, which isolates the influence of the load from the operation of the RC network.

arduino-seguidor-tension

However, since we are going to use an operational amplifier, we could unify both components by using an active filter.

arduino-filtro-activo

Finally, another highly recommended option is to directly use one of the many commercial ADC converters available. We will see these solutions in future entries.