AN296094 Method For Converting A PWM Output To An Analog Output When Using Hall Effect Sensor ICs

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Application Information

Method for Converting a PWM Output to an Analog Output


When Using Hall-Effect Sensor ICs
By Ryan Metivier
Allegro MicroSystems, LLC

D = tON / TPWM
A current sensor with PWM output is a very useful type
of device. Traditionally, the device can serve in a digital tON 1 / fPWM
application where the host microcontroller can determine
VPWM
the ratio of the on-time to the off-time of the sensor output
signal. Another useful way to use a PWM sensor is to
convert the PWM output signal into an analog output signal.
The goal of this article is to briefly introduce a simple way
to convert the PWM signal into an analog signal, along with time
some examples and important design constraints.
Figure 1. Basic PWM Definitions

How PWM Output Sensors Work


Before getting too deeply into designing a filter, the first
step is to quickly review what the output signal of a PWM D = tON / TPWM
sensor looks like. The PWM waveform is basically a square
wave, with a frequency we will define as fPWM , and an tON TPWM
amplitude that is 0 V for logic low, and VCC for logic high. VPWM
From here forward, we will refer to the amplitude as VPWM .
The ratio of the signal high time, tON , to the period (TPWM
= 1 / fPWM ) is the duty cycle, D. These relationships are
diagrammed in figure 1.
The duty cycle for a PWM output Hall IC is proportional time
to the sensed magnetic field. As the input field increases in Figure 2. PWM for an increasing field
strength, so does D (figure 2). Conversely, as the input field
decreases, so does D (figure 3).

How Analog Output Sensors Work D = tON / TPWM


Now that we reviewed how a PWM output works for a tON TPWM
Hall-effect IC, it is time to briefly discuss how an analog
output works for a sensor. The premise is nearly identical as VPWM
that for the Hall IC with a PWM output. Except, instead of
a constant switching of the output to generate a signal, the
output asserts an analog voltage that is proportional to the
sensed magnetic field. For example, when the PWM duty
cycle would increase due to a rising input field, the analog time
output would simply rise to a higher DC voltage, and vice Figure 3. PWM for a decreasing field
versa for a decreasing field.

296094-AN
Passive Filters using known filters, it is most useful to compute this attenuation
factor in dB:
Now we come to the interesting part of the process, where we
create an analog DC voltage from the PWM output signal. The VRIPPLE
AdB = 20 × log (1)
simplest method for this is with a passive low pass filter. For the VPWM
purposes of this guide, and for simplicity, the focus will be on where AdB is attenuation, and must be a negative number!
passive, first and second order, low pass filters. Passive filters
Remember that VPWM is simply the output voltage swing of the
can be realized very simply with resistors and capacitors. The
PWM sensor.
concepts presented here can be applied to more advanced filters.
For the purposes of this document, we will be focusing on ana- Once the attenuation factor is known we can apply our
lyzing and designing circuits that use passive low pass filters with knowledge, that the slope of a first order low pass filter is
attenuation roll-off factors of –20 dB / decade for first order filters –20 dB / decade and the slope of a second order low pass filter is
and –40 dB / decade for second order filters. In some cases, a –40 dB / decade, to determine the required 3-dB frequency (f3dB )
first order filter will work fine. However, some applications may for the filter:
require a faster response time. In these cases, a second order filter fPWM
may be necessary. It is up to the end user to evaluate the tradeoff AdB = Slope × log (2)
f3dB
between cost of the filter and the filter performance. The order
of the filter can be increased by simply cascading more and more What this equation is telling us is that the attenuation, AdB , is
stages. For each additional order of the filter, the roll-off rate equal to the slope (dB / decade) of the low pass filter, times how
becomes steeper, by an additional –20 dB / decade. many decades are between the 3-dB frequency (f3dB) and the
There are a couple of ways to compute the filter response to PWM frequency (fPWM). Since we already know AdB , we will
an input signal: time analysis and frequency analysis. I prefer solve the following equation for what we want to know, f3dB :
back-of-an-envelope frequency analysis, and will be focusing on A3dB

using frequency analysis techniques to design first and second f3dB = fPWM × 10 Slope (3)
order low pass filters. In general, most folks without an electron-
ics background understand frequency methods better than time Now we have everything we need to design a passive low pass
domain methods when designing simple filters. filter. While this may seem a little complicated, trust me, it is
easier than solving second order time domain equations.
Back of the Envelope Filter Design
Another interesting exercise is to set equation 1 equal to equa-
While there are many detailed ways to compute filter require-
ments and filter output ripple voltage, I prefer to keep things tion 2 and solve for VRIPPLE . This will give us an equation that
simple in such a way that I can easily draw up and design a sim- expresses voltage ripple as a function of f3dB :
ple filter on the back of a small envelope and make calculations Slope × log
fPWM

with a cheap scientific calculator (or smart phone app). The first VRIPPLE = VPWM × 10 20
f3dB
(4)
term you have to define is how much ripple voltage, VRIPPLE ,
is acceptable in the analog output. The second necessary term is While this equation is a little more complicated than the previous
the PWM frequency, fPWM , of the sensor. Once the acceptable three equations, it has pretty simple mathematics that allow us to
VRIPPLE and fPWM are defined, the required attenuation can be plot ripple voltage versus 3-dB frequency for determining known
computed. Because we are working in the frequency domain and slope, PWM voltage, and PWM frequency.

Allegro MicroSystems, LLC 2


115 Northeast Cutoff
296094-AN Worcester, Massachusetts 01615-0036 U.S.A.
1.508.853.5000; www.allegromicro.com
Figure 4 plots approximate VRIPPLE versus f3dB for first and illustrate this point.
second order filter slopes, given fPWM = 8 kHz and VPWM = 5 V.
Example:
This chart can be used as a guide for designing a filter. Simply
select the required amount of ripple on the vertical axis, and then Let us say that we have a sensor with an fPWM of 8 kHz, a VPWM
find where the two lines intersect this horizontal line. These inter- of 5 V, and we are targeting LSB / 2 of ripple for our 10-bit
sections are where the filters will achieve the target requirements. A-to-D converter. For this case, LSB / 2 corresponds to about
It should be noted that these calculations will have some error 2.4 mV of voltage ripple. So, the first thing we need to do is cal-
in them when compared to actual measured ripple voltage. One culate the attenuation factor we need. Using equation 1:
source of error is due to the fact that the corner frequency of the 0.0024 (V)
AdB = 20 × log = –66.375 (dB)
filter is not a perfect corner. It is in fact rounded. This means that 5 (V)
the attenuation of the filter near the corner does not follow our
Now that we know the attenuation factor, the next step is to com-
20 dB/decade approximation perfectly. The story is the same for
pute the bandwidth of the filter we need to design, using equa-
higher order filters as well.
tion 3. We will do this twice, once for a first order filter:
Another source results from computing the amplitude of our –66.375 (dB)
ripple by focusing on the fundamental frequency of the PWM. In f3dB = 8000 (Hz) × 10

–20
= 3.84 (Hz)
reality, the PWM will have higher frequency content because it
is a square wave. More specifically, we are omitting the odd har- and again for a second order filter:
monics of the fundamental (3 × fPWM , 5 × fPWM , 7 × fPWM , …). –66.375 (dB)

Fortunately for us, the attenuation of those higher frequencies f3dB = 8000 (Hz) × 10 –40
= 175 (Hz)
from our filter is even greater than for the fundamental. For the
most part, they can be ignored for the first iteration of the filter So if we use a first order low pass filter, we would need to
design. As for our back-of-the-envelope calculation, we get very design a filter with an f3dB of 3.84 Hz. This may not be attrac-
close to the actual value without unnecessarily complicated com- tive depending on the rest of the system requirements. A second
putations. Oftentimes the first order filter pole must be adjusted order filter would require an f3dB of 175 Hz. This may be a more
downward a little bit to achieve the target ripple, due to the attractive option for some applications that require faster tran-
shallower roll-off of –20 dB / decade. The simulations below will sient response.

1000

100
1st Order Filter
10
VRIPPLE (mV)

0.1
2nd Order Filter
0.01

0.001

0.0001 fPWM = 8 kHz


VPWM = 5 V
0.00001
1 10 100 1000
Filter Bandwidth (Hz)
Figure 4. Ripple Voltage versus 3-dB frequency; use for estimating
first and second order filters

Allegro MicroSystems, LLC 3


115 Northeast Cutoff
296094-AN Worcester, Massachusetts 01615-0036 U.S.A.
1.508.853.5000; www.allegromicro.com
Building the Filter For the first order filter (f3dB = 3.84 Hz), we can chose a capaci-
tor, CF , value of 10 μF and use equation 6 to compute that the
Constructing a basic passive low pass filter is quite simple. A filter resistor, RF , value:
first order filter uses one capacitor and one resistor, and a second
order filter uses two resistors and two capacitors. The extra resis- 1
RF = = 4.144 (kΩ)
tor, RL , in the schematics (figures 5 and 6) is there to represent a 2 × 10 (μF) × 3.84 (Hz)
typical input resistance of the measurement system. RF should be rounded up to the closest 1% resistor value of
We will build the first order filter first. Building a first order filter 4.22 kΩ, and the corresponding f3dB value would be 3.77 Hz.
is as simple as choosing a starting capacitor value, and then com- The implementation for a second order passive low pass filter is
puting the resistor value. simply cascading two first order filters in series. In this example,
Given: we will create two first order filters, each with an f3dB of 175 Hz
as calculated above using equation 3. For this example, we chose
f3dB = 1 1 μF for CF and computed RF to be 909 Ω (standard 1% value) by
(5)
2 × RF × CF substituting into equation 6:
and 1
RF = = 909 (Ω)
1 2 × 1 (μF) × 175 (Hz)
RF = (6)
2 × CF × f3dB

PWM Out RF = 4.22 kΩ


Sensor System Input

CF = 10 μF R L ≈ 50 kΩ

Figure 5. First-Order Low Pass Filter for 3.77 Hz

PWM Out RF = 909 Ω RF = 909 Ω


Sensor System Input

CF = 1 μF CF = 1 μF RL ≈ 50 kΩ

Figure 6. Second-Order Low Pass Filter for 175 Hz

Allegro MicroSystems, LLC 4


115 Northeast Cutoff
296094-AN Worcester, Massachusetts 01615-0036 U.S.A.
1.508.853.5000; www.allegromicro.com
Simulated Results
The following several figures illustrate simulation results of the
two filters designed in this article. The PWM output was con-
figured such that fPWM = 8 kHz, D = 50%, and VPWM = 5 V, as
shown in figure 7. This figure represents the unfiltered input
signal. Remember that we will be applying a much slower filter
to this waveform, so many of the following graphs are at a differ-
ent time scale.
Figure 8 illustrates the output transfer function of the waveforms
in figure 4 for both the first order (green trace) and the sec-
ond order (blue trace) filters. It is obvious to see that the lower
frequency f3dB of the first order filter causes a much slower
response. It is also apparent that the series resistance of the filter
does impact the voltage of the output signal, as there is indeed
a resistor divider that reduces the voltage at the system input Figure 7. Input PWM signal (fPWM = 8 kHz)
(4.22 kΩ for the filter and 50 kΩ for the approximated input
resistance of the system). Overall, the response of the curves is
what was expected from our calculations.
Second Order
Next we need to have a closer look at the ripple voltage of the
settled output waveform. Figure 9 shows the detailed view of the
First Order
ripple of the first order filter output. It shows that the final ripple
value is 3.58 mV for our f3dB of 3.77 Hz. It is a little bit higher
than we were targeting, but as stated before, it was expected that
we may be off by a little bit, based on our assumptions. How-
ever, our filter is definitely performing in that region and could
be slightly adjusted. Increasing RF or CF slightly will reduce
the ripple. Increasing RF or CF will also lower f3dB. Simulation
experiments will show that moving f3dB down to about 2.57 Hz
by changing RF to 6.19 kΩ will bring the ripple into specification.

Figure 8. Output Response of first and second order filters

3.58 mV

Figure 9. Detail of output ripple for first order filter simulation,


ripple = 3.58 mV

Allegro MicroSystems, LLC 5


115 Northeast Cutoff
296094-AN Worcester, Massachusetts 01615-0036 U.S.A.
1.508.853.5000; www.allegromicro.com
Figure 10 shows a zoomed in version of the output ripple for the
second order low pass filter. Here we can see that we were even
closer with our original design estimate. This filter achieved a
2.86 mV
ripple voltage of 2.86 mV. Not bad since we were shooting for
2.4 mV. Once again, this ripple value can be reduced by modify-
ing the filter slightly and lowering f3dB in a similar manner as the
first order example.

Lab Data
A filter design and simulation exercise would not be complete
until the filter has been constructed and tested in the lab. The last
two figures (11 and 12) are oscilloscope images of the output
ripple for each of the two filters. The filters were constructed with
the original design components earlier in a solderless breadboard.
The input PWM and the output analog voltage were measured Figure 10. Detail of output ripple for second order filter simulation,
using an oscilloscope. The two figures illustrate that our filters ripple = 2.86 mV
performed very close to the original design targets.

Figure 11. First-order filter output lab results, VRIPPLE = 4.0 mV

Allegro MicroSystems, LLC 6


115 Northeast Cutoff
296094-AN Worcester, Massachusetts 01615-0036 U.S.A.
1.508.853.5000; www.allegromicro.com
Conclusion
This article briefly summarized a simple method for converting response fast enough, and to maintain the use of small compo-
the output of a PWM sensor to an analog voltage. The methods nents. Increasing the order of the filter increased the number of
shown use a fairly straightforward method for designing a filter passive components required to realize the filter. In this case, we
as well as documenting the caveat for using the simple method. went from two total passives to realize a first order filter, to four
The primary goal of showing how to realize a passive low pass total passives to realize the second order filter.
filter was illustrated with a first order filter, and a second order
Although every system is different, the methods in this document
filter. The reader can extend the order of the filter in order to
can be used for many different systems. Some PWM signals have
increase the response time of the signal while maintaining accept-
a different fPWM . By using the equations documented above, a
able ripple. Note: A third order filter rolls off at –60 dB / decade,
filter can be designed around a different system. Slower fPWM
but requires 2 more passives.
will require lower f3dB , while faster fPWM can get away with
The worked examples show that unless a very slow response higher f3dB . In closing, with a little bit of creative filter design, an
time is acceptable, most typical applications will want to pursue a off-the-shelf PWM output sensor can be designed into a system
second order (or higher) low pass filter in order to keep the filter that requires an analog voltage.

Figure 12. Second-order filter output lab results, VRIPPLE = 2.8 mV

Allegro MicroSystems, LLC 7


115 Northeast Cutoff
296094-AN Worcester, Massachusetts 01615-0036 U.S.A.
1.508.853.5000; www.allegromicro.com
Copyright ©2013, Allegro MicroSystems, LLC

The information contained in this document does not constitute any representation, warranty, assurance, guaranty, or inducement by Allegro to the
customer with respect to the subject matter of this document. The information being provided does not guarantee that a process based on this infor-
mation will be reliable, or that Allegro has explored all of the possible failure modes. It is the customer’s responsibility to do sufficient qualification
testing of the final product to insure that it is reliable and meets all design requirements.

Allegro MicroSystems, LLC 8


115 Northeast Cutoff
296094-AN Worcester, Massachusetts 01615-0036 U.S.A.
1.508.853.5000; www.allegromicro.com

You might also like