pwm filt er art kay & andrew wu ti precision designs ... · pdf filethe pwm output from a...

30
An IMPORTANT NOTICE at the end of this TI reference design addresses authorized use, intellectual property matters and other important disclaimers and information. TINA-TI is a trademark of Texas Instruments WEBENCH is a registered trademark of Texas Instruments TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 1 Copyright © 2013, Texas Instruments Incorporated Art Kay & Andrew Wu TI Precision Designs: Verified Design Microcontroller PWM to 12bit Analog Out TI Precision Designs Circuit Description TI Precision Designs are analog solutions created by TI’s analog experts. Verified Designs offer the theory, component selection, simulation, complete PCB schematic & layout, bill of materials, and measured performance of useful circuits. Circuit modifications that help to meet alternate design goals are also discussed. This design note provides a passive RC filter design for PWM to analog conversion, as well as a test circuit for verifying that the filter meets the design goals. Methods for selecting the passive filter’s order, cutoff frequency, and component values for achieving a targeted resolution are described. The design example shows a 12 bit filter but the method could be used for other resolutions. The test circuit is needed to confirm that the output error (ripple) meets the design requirements because this cannot be directly measured using standard test equipment. Design Resources Design Archive All Design files TINA-TI™ SPICE Simulator OPA2209 Product Folder MSP430 Product Folder Ask The Analog Experts WEBENCH® Design Center TI Designs Precision Library Square wave Signal Generator (PWM 50% duty cycle) 4 th order passive LPF Post Amp ac coupled G = 1024 V/V Scope To Measure Ripple PWM Filter Ripple Measurement Test

Upload: buithien

Post on 30-Jan-2018

220 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

An IMPORTANT NOTICE at the end of this TI reference design addresses authorized use, intellectual property matters and other important disclaimers and information.

TINA-TI is a trademark of Texas Instruments WEBENCH is a registered trademark of Texas Instruments

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 1 Copyright © 2013, Texas Instruments Incorporated

Art Kay & Andrew Wu

TI Precision Designs: Verified Design

Microcontroller PWM to 12bit Analog Out

TI Precision Designs Circuit Description

TI Precision Designs are analog solutions created by TI’s analog experts. Verified Designs offer the theory, component selection, simulation, complete PCB schematic & layout, bill of materials, and measured performance of useful circuits. Circuit modifications that help to meet alternate design goals are also discussed.

This design note provides a passive RC filter design for PWM to analog conversion, as well as a test circuit for verifying that the filter meets the design goals. Methods for selecting the passive filter’s order, cutoff frequency, and component values for achieving a targeted resolution are described. The design example shows a 12 bit filter but the method could be used for other resolutions. The test circuit is needed to confirm that the output error (ripple) meets the design requirements because this cannot be directly measured using standard test equipment.

Design Resources

Design Archive All Design files TINA-TI™ SPICE Simulator OPA2209 Product Folder MSP430 Product Folder

Ask The Analog Experts WEBENCH® Design Center TI Designs Precision Library

Square wave Signal Generator

(PWM 50% duty cycle)

4th order passive LPF

Post Ampac coupled

G = 1024 V/V

ScopeTo Measure

Ripple

PWM Filter

Ripple Measurement Test

Page 2: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

2 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

1 Design Summary

The design requirements for PWM filter are as follows:

Input: 3.3 Vpp square wave to simulate 50% duty cycle PWM

Filter output: DC with 12-bit resolution (Maximum ripple: 403uVpp)

The design requirements for Post Amp are as follows:

Supply Voltage: ±15 V dc (for post amplifier)

Post amplifier gain: 1024 V/V, ac coupled

The design goals and performance for 12bit, system resolution are summarized in Table 1. Figure 1 depicts the measured ripple for 12bit system resolution with 1024 times gain of the RC low pass filter design.

Table 1: Comparison of Design Goals, Simulated Performance, and Measured Results

System Resolution Goal

Max Ripple Simulated

Ideal Components Measured Results

12bit (filter out) 403uVpp 344.48uVpp 347.66uVpp

12bit (post amp out) 412mVpp 396mVpp 404mVpp

Figure 1: PWM Output Ripple Verification for 12 bit System (Gain = 1024V/V)

Page 3: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 3 Copyright © 2013, Texas Instruments Incorporated

2 Theory of Operation

2.1 Design Overview

Pulse Width Modulation (PWM) is a technique where the width of digital pulses is adjusted to generate different average dc voltages. Most microcontrollers have a built-in timer that can be used to generate a PWM signal. PWM outputs can be converted to a dc voltage by using a series of RC low pass filters to average the pulses. Thus, a filtered PWM circuit is a simple low cost method to convert digital to analog (i.e. create a DAC). The main goal of this design is to convert PWM to analog output and achieve a 12 bit resolution with a ripple signal less than one half LSB. A secondary goal is to develop a circuit that amplifies the output ripple (error) to a level that an oscilloscope can measure. A system block diagram is shown in Figure 2.

Square wave Signal Generator

(PWM 50% duty cycle)

4th order LPFPost Amp

ac coupledG = 1024 V/V

ScopeTo Measure

Ripple

PWM Filter Ripple Measurement Test

Figure 2: System block diagram

Page 4: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

4 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

The PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle). The output of a simple RC filter connected to the PWM output will charge to the average voltage of the PWM signal. Figure 3 shows a 10% and 90% duty cycle PWM signal connected to a simple RC filter. Note that the output charges to approximately 90% of the square wave’s amplitude for a 90% duty cycle. In general, the ideal average dc output is PWM amplitude multiplied by the duty cycle (i.e. Vout = VPWM x Duty_Cycle). The charge and discharge of the filter capacitor can also be seen in Figure 3. The peak-to-peak amplitude of the variations caused by the charge and discharge of the filter capacitor is called the ripple. The objective is to convert the PWM signal to a dc voltage so ideally the ripple would be zero. The results shown in Figure 3 are for a single pole RC filter; adding additional filter stages will further minimize the ripple. The ripple can be thought of as an error that limits the resolution of the signal. As a rule of thumb the ripple should be kept to half the voltage resolution. To achieve our resolution objective (12 bits) we will have to determine the number of filter stages and the cutoff frequency required to reduce the ripple to half of the voltage resolution.

Figure 3: PWM Signal and dc Output for 10% and 90% Duty Cycle

T

Time (s)

4.00m 4.50m 5.00m 5.50m 6.00m

Ou

tpu

t

20.00m

1.65

3.28

Duty Cycle 10%Pulse High 10% of cycle

0.33V

150mVpp ripple

Duty Cycle 90%Pulse High 90% of cycle

2.95V

150mVpp ripple

T

Time (s)

4.00m 4.50m 5.00m 5.50m 6.00m

Ou

tpu

t

20.00m

1.65

3.28

Page 5: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 5 Copyright © 2013, Texas Instruments Incorporated

Another factor that controls the resolution is the degree by which the width of the PWM signal can be adjusted. A common method for generating PWM signals it to use a binary counter. Figure 4 shows the generation of two different PWM signals with an 8 bit counter. The counter output remains high until the desired duty cycle is met and then it is reset. The MSP430 microcontroller uses this principle with a 16 bit counter. The number of bits in the counter corresponds to the bits of resolution in the analog output if the signal is properly filtered. For this design our goal is 12 bit resolution, so a 12 bit counter is needed to achieve 12 bits of resolution. Later in this document we will discuss the trade-offs associated with higher resolution systems.

0 1 2 3 4 5 6 7

0 1 2 3 4 5 6 7

1/8 =0.12512.5% duty cycle

2/8 =0.2525% duty cycle

Figure 4: PWM for an 8 Bit Counter

Page 6: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

6 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

Figure 5 illustrates the PWM (counter) output on the MSP430. In this figure the full 16 bit (i.e. 65,536) counter is being used. In Figure 5 the PWM output is configured for the minimum duty cycle (i.e. 1 count in 65,536 or 0.00153% duty cycle). The period of one count is 62.5ns for the MSP430 at a master clock frequency of 16MHz. The period of the entire 16 bit clock cycle is 4.096ms (62.5 ns x 65536). The PWM frequency is 244Hz (TPWM_Cycle = 4.096ms).

0 1 2 3 4 5 6 7

1/65536 = 15.25x10-6

0.00153% duty cycle6

55

35

65

53

46

55

33Tone_clock = 62.5ns

TPWM_Cycle = 4.096ms

fPWM_Cycle = 244Hz

Figure 5: PWM for a 16 bit Counter (Frequency, Period, and Duty Cycle shown)

In the case of this design our resolution objective is 12 bits, so we only need 12 bits of the 16 bit counter in the MSP430. Figure 6 shows the PWM signal where the counter is reset after 12 bits. The resolution is now 1/4096 or a 0.0244% duty cycle. Limiting the counter to 12 bits also affects the period and frequency of the PWM signal. The frequency of the 12 bit PWM signal is 3.91kHz which is substantially higher than the 16 bit PWM frequency (244Hz). The PWM frequency is the frequency by which analog output can be adjusted. The PWM frequency also determines the cutoff frequency of the filter.

0 1 2 3 4 5 6 7

1/4096 = 244x10-6

0.0244% duty cycle

40

96

40

95

40

94

Tone_clock = 62.5ns

TPWM_Cycle = 256us

fPWM_Cycle = 3.906kHz

Figure 6: PWM for a 12 bit Counter (Frequency, Period, and Duty Cycle shown)

Page 7: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 7 Copyright © 2013, Texas Instruments Incorporated

2.2 PWM Filter Design

The PWM signal is a square wave with a different duty cycle depending on the dc output voltage target. The filter will convert the square wave to an average dc voltage. Remember that a square wave is composed of a series of sinusoidal waveforms at odd harmonic intervals. The objective of the filter is to attenuate all of the harmonics in the square wave and leave the dc average. Figure 7 below shows the PWM waveform with a 50% duty cycle in the time domain and in the frequency domain. In this design we will use a series of simple RC low pass filters to attenuate the fundamental and the harmonics.

T

1st harmonic

4kHz

2nd Harmonic

3x4kHz=12kHz

3rd Harmonic

5x4kHz =20kHz

4th Harmonic

7x4kHz = 28kHz

Frequency (Hz)

1k 10k 100k

Am

plit

ude [V

/Hz]

0.00

7.50m

15.00m

4th Harmonic

7x4kHz = 28kHz

3rd Harmonic

5x4kHz =20kHz

2nd Harmonic

3x4kHz=12kHz

1st harmonic

4kHz

T

Time (s)

0.00 250.00u 500.00u 750.00u 1.00m

VG1

0.00

3.00

Figure 7: PWM Signal Fourier Series (Odd Harmonics)

Page 8: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

8 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

Figure 8 below illustrates how a fourth order low pass filter can be used to filter the harmonics in the PWM waveform. Note that the higher frequency harmonics are attenuated to a greater degree. The filter design is covered later in this section.

Figure 8: Attenuation of the harmonics in the PWM with a low pass filter

T

Frequency (Hz)

10 100 1k 10k 100k

Ga

in (

dB

)

-200.00

-180.00

-160.00

-140.00

-120.00

-100.00

-80.00

-60.00

-40.00

-20.00

0.00

T

Frequency (Hz)

10 100 1k 10k 100k

Am

plit

ud

e [V

/Hz]

0.00

8.25m

16.51m

-80dB for 1st Harmonic

-120dB for 2nd Harmonic -137dB for 3rd Harmonic

4kHz

12kHz

20kHz

Page 9: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 9 Copyright © 2013, Texas Instruments Incorporated

As a rule of thumb, the cutoff frequency needs to be at least 1 decade lower than the PWM frequency to achieve good attenuation of the fundamental. Using this rule of thumb the fundamental will be attenuated by 20dB for a first order, and 40dB for a second order. We need to determine the filter order required to minimize the ripple to one half of a least significant bit (LSB). Equations (1) to (6) work towards the derivation of a general formula that finds the required filter order to achieve a given resolution. These equations assume that the filter cutoff frequency is set one decade below the PWM frequency.

(1)

Where:

Resolution is the minimum incremental change in the analog output voltage with a change in PWM duty cycle.

VPWM is the amplitude of the PWM signal

n is the resolution in bits for the analog signal (12 in this case)

(2)

(3)

Where:

Minimum_Ripple is the minimum peak-to-peak amplitude left from the PWM waveform after filtering. Ideally the ripple is zero.

(4)

Where:

Ripple is the ripple out of the filter assuming the cutoff frequency is one decade lower than the PWM frequency (i.e. fcuttoff = fpwm / 10)

order: is the filter order (e.g. first order 1/10 or -20dB, second order 1/100 or -40dB)

Page 10: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

10 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

Substituting (3) into (4), we get Equation (5). Rearranging Equation (5), we get Equation (6). Equation (5) can be used to calculate the required filter order given the PWM resolution. In Equation (7) we determine the order needed for our design (i.e. 4th order filter is needed for a 12 bit PWM).

(5)

(6)

order = 4 round up to next highest integer

to achieve performance better than the goal.

(7)

From Equation (7) we determined that a fourth order filter is required for 12 bit PWM. Now we need to select the component values for this filter. A simple first order low pass RC filter is shown in Figure 9. The equation that sets the cutoff frequency is given in Equation (8).

Figure 9: First Order 391Hz Low Pass Filter

(8)

Where:

fcutoff = fpwm/10 = (3.91kHz) / 10 = 391Hz

R1 and C1 = first stage low pass RC filter

C1 is selected arbitrarily as a standard value. Choose near 1uF as the capacitance in each subsequent stage is divided by 10.

+

Vin

R1 866C

1 4

70

nVout

Page 11: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 11 Copyright © 2013, Texas Instruments Incorporated

The RC filter will load the microcontroller. The load current is at a maximum when the PWM signal makes a logic level transition (i.e. low to high or high to low). The transient current can be estimated by Equation (9). Using the initial filter values calculated in Equation (9) the transient current is 3.8mA. This is a reasonable load for the MSP430.

(9)

To obtain a higher order filter we can cascade additional stages of the filter. However, it is important to ensure that subsequent stages do not load the initial stage. A simple approach to prevent the loading is to increase the impedance of each subsequent stage by a factor of ten. Equation (10) and (11) show the calculation of the second stage. Subsequent stages follow the same procedure. The final filter is shown in Figure 10.

(10)

(11)

Figure 10: Cascading four RC Filters for 4th

Order LPF

+

Vin

R1 866

C1

47

0n

Vout R2 8.66k

C2

47

n

R3 86.6kC

3 4

.7n

R4 866k

C4

47

0p

Page 12: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

12 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

Finally, consider the noise contribution of the resistors in the filter. The noise density plot shown in Figure 11 can be used to determine the noise for the filter resistors. The expected noise is 16uVpp, from Equation (12) and (13), which is significantly less than the required minimum ripple 403uVpp, so noise is not an issue for this design. However, in other designs (e.g. higher order filter) the noise may be significant.

Figure 11: Noise Spectral Density vs. Resistance

(12)

Where:

Enpp is total p-p noise

6 is the factor that converts rms to peak-to-peak

en is noise spectral density

Kn is the brick wall correction factor (1.57 for 1st order filter)

f3db is the filter cutoff frequency

(13)

Resistance (ohms)

Vo

ltag

e N

ois

e D

ensi

ty (

nV

/rtH

z)

Page 13: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 13 Copyright © 2013, Texas Instruments Incorporated

2.3 Filter Post Amplifier Design

The purpose of this design is to filter the PWM signal to a dc voltage that has a ripple that is less than one half the LSB of the required analog output resolution. Equation (14) calculates the minimum ripple to be 403 Vpp for this design. Most oscilloscopes have a minimum resolution of 1mV/div and cannot directly measure the filter output ripple. The post amplifier amplifies the ripple to a level where the oscilloscope can measure the ripple to allow confirmation of filter performance.

(14)

Figure 12 shows the filter post amplifier used to amplify the ripple to a level where it can be easily read by an oscilloscope. The first stage (U1a) has a dc gain of 1 if you consider the capacitor (C5) acts as an open to dc. C5 was selected as a large capacitance (100uF) so that it would act as a short (negligible reactance) at very low frequencies. The cutoff frequency for C5 and R5 is 0.159Hz. So for frequencies above 0.159Hz you can consider C5 a short. For frequencies above 0.159Hz the gain of U1a is 32 (R6/R5 +1). At high frequencies R6 and C6 will attenuate the gain (for f > 513kHz). In summary, U1a amplifies the ac ripple from the filter by a factor of 32 but only amplifies the dc by a factor of 1. This topology was used because the high input impedance of the non-inverting amplifier does not affect the filter.

The filter, C7 and R7, between U1a and U1b is used to ac couple the two stages (i.e. eliminate the dc output of U1a). U1b is a non-inverting amplifier with a gain of 32 (Gain = R9/R8 +1). Thus, the total ac gain of the cascaded amplifier (U1a and U1b) is 1024. In this example we should expect to see less than 412mVpp of ripple on the oscilloscope (403 Vpp x 1024 = 412mVpp).

Figure 12: Post Filter Amplifier for Ripple Verification

+15V

-15V

Vo_U1a

R7

10

kC7 100u

R8 1k R9 31k

Vout_scope+

-

+

U1b OPA209+

-

+

U1a OPA209Vin_U1b

R6 310kR5 10kC5 100u

V1 2.5

+

VG1

C6 1pC9 10p

+15V

-15V

Page 14: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

14 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

3 Component Selection

3.1 Passive Component Selection

Standard 1% 100ppm/C resistors and are sufficient for the accuracy required. The capacitors used should be 5% COG or NP0 type for best accuracy and lowest distortion.

3.2 Amplifier Selection

Use a low noise op amp for the post filter amplifier (U1a and U1b) to insure that the noise contributed by the amplifier should be minimal compared to the ripple signal. The OPA2209 (dual OPA209) was used for this design.

4 Simulation

Figure 13 shows the forth order filter used to filter the PWM signal. Figure 14 shows the response of each stage in the filter. The fourth stage has the expected attenuation of 80dB at the PWM frequency.

Figure 13: 12 bit PWM filter design (fcutoff = 391Hz, 4th

order)

Figure 14: Frequency Response for PWM filter (80dB attenuation for 3.91kHz)

R1 866

C1 4

70n

1R

R2 8.66k

C2 4

7n

2R

R3 86.6k

C3 4

.7n

R4 866k

C4 4

70p

4R3R

+

VG1

T

4R

-80.2dB @ 3.9kHz

Frequency (Hz)

10 100 1k 10k

Ga

in (

dB

)

-120.00

-100.00

-80.00

-60.00

-40.00

-20.00

0.00

4R

-80.2dB @ 3.9kHz

1R

2R

3R

Page 15: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 15 Copyright © 2013, Texas Instruments Incorporated

Figure 16 shows the ac frequency sweep for the circuit shown in Figure 15. In Figure 16 the Monte Carlo analysis option was also used to show that the gain is reasonably accurate at 3.91kHz (i.e. gain variation is 1020.9 to 1025.6V/V, Ideal Gain = 1024 V/V).

Figure 15: Post Filter Amplifier for Ripple Verification (simulation circuit)

VDD

VSS

VDD

VSS

VDD VSS

VDD 15 VSS -15

C7 100u

R8 1k R9 31k

Vout_scope

R6 310kR5 10kC5 100u

R7 1

0k

+

VG1

C1 1p C2 10p

-

++

U1a OPA209

-

++

U1b OPA209

(1024 x VG1)

Page 16: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

16 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

T

Frequency (Hz)

10m 100m 1 10 100 1k 10k 100k 1M 10M

Gain

(dB

)

0.0

10.0

20.0

30.0

40.0

50.0

60.0

70.0

T

60.22dB (1025.6 V/V)

@ 3.91kHz

60.18dB (1020.9 V/V)

@ 3.91kHz

Frequency (Hz)

1k 10k

Gain

(dB

)

60.1700

60.1800

60.1900

60.2000

60.2100

60.2200

60.2300

60.18dB (1020.9 V/V)

@ 3.91kHz

60.22dB (1025.6 V/V)

@ 3.91kHz

Zoom inTo See

Gain variation

Figure 16: Monte Carlo Analysis for Post Amplifier Frequency Response

Page 17: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 17 Copyright © 2013, Texas Instruments Incorporated

Figure 17 shows the total noise for the post amplifier (7.18mVrms). The peak-to-peak noise, at Vout_scope, can be estimated as six times the rms (6 x 7.18mVrms = 43mVpp). The expected ripple amplitude can be calculated from Equation (3) and the post filter amplifier gain to be 412mVpp (403 Vpp x 1024 = 412mVpp). Since the output signal is 412mVpp, the 43mVpp of noise should not be a significant error source.

Figure 17: Total noise (Vrms) at the output of the Post Amplifier

T

Frequency (Hz)

1.00 10.00M

Tota

l nois

e (

V)

0.00

3.59m

7.18m

Page 18: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

18 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

Figure 18 shows the TINA-TI™ SPICE circuit used to simulate the entire circuit. Figure 19 shows the expected result out of the filter (386uVpp) and out of the post amplifier (396mV). The post amplifier properly amplifies the ripple with minimal error (see Equation (15)).

Figure 18: TINA-TI™ – Schematic for 12bit system

+15V

-15V

+15V

-15V

-15V

+15V

PWM

Vduty

Vfreq

GND

Voh

Vout

Vol

U3 PWM

Vduty 50

Vfreq 3.9k

Vol -1.65

Voh 1.65

R1 866

C1 4

70n

R2 8.66k

C2 4

7n

R3 86.6k

C3 4

.7n

R4 866k

C4 4

70p

4R1R 2R 3R

VEE 15

VCC 18

-

++

4

3

25

1

U1 OPA209

-

++

4

3

25

1

U2 OPA209C5 100u

R5 1

0k

R6 310k

C6 1p

R7 31k

C7 10p

R8 1kR9 10kC8 100u

Vout_scope

Vpw m

VF1 VF2

Duty cycle

1V = 1%

Frequency

1V = 1Hz

(1024 x 4R)

Page 19: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 19 Copyright © 2013, Texas Instruments Incorporated

Figure 19: TINA-TI™ – Schematic for 12bit System Simulation

(15)

T

Time (s)

250.00m 250.25m 250.50m 250.75m 251.00m

1R

-256.91m

256.94m

2R

-20.21m

20.01m

3R

-2.03m

2.01m

4R

-197.38u

189.74u

VF1

-5.12m

7.31m

VF2

-1.78m

10.68m

Vout_scope

-57.17m

341.97m

Vpwm

-1.65

1.65

386µVpp

396mVpp

Page 20: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

20 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

4.1 Simulated Results Summary

The simulation results are shown in Table 2 as below.

Table 2: Comparison of Design Goals, Simulation Performance, and Measured Results

System Resolution Goal

Max Ripple Simulated

Ideal Components Measured Results

12bit (filter out) 403uVpp 344.48uVpp 347.66uVpp

12bit (post amp out) 412mVpp 396mVpp 404mVpp

Page 21: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 21 Copyright © 2013, Texas Instruments Incorporated

5 PCB Design

The PCB schematic and Bill of Materials can be found in Appendix A.

5.1 PCB Layout

The general guidelines for precision PCB layout were used on this design. For example, trace lengths are kept to minimum length especially input signals.

Figure 20: PCB Layout

Page 22: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

22 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

6 Verification & Measured Performance

6.1 Low Pass Filter Ripple Measurement

The ripple of the low pass filter output is in level of uV which cannot be read directly with an oscilloscope. Therefore, the post amplifier is used to amplify the signal to a milivolt level. The test results are shown in Figure 21 as below.

Figure 21: 12bit system resolution with 1024 times gain output ripple

Page 23: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 23 Copyright © 2013, Texas Instruments Incorporated

6.2 Post amplifier Filter Frequency Response

Figure 22 illustrates the frequency responses of the post amplifier.

0.01 0.1 1 10 100 1k 10k 100k 1M 10M

-10

0

10

20

30

Frequency (Hz)

Post Amp Out vs. Frequency (Hz)

Po

st

Am

p O

ut

(dB

)

(0.1Hz, -6dB) (400kHz, -6dB)

Figure 22: Post Amplifier Bandwidth Measurement

6.3 Measured Result Summary

The measurement results are shown in Table 3 as below. Note that the output ripple and cutoff frequencies are close to the goal. The accuracy of the cutoff frequencies is not critical. The main goal is to ensure that the PWM frequency (3.91kHz) is in the passband.

Table 3: Comparison of Design Goal and Measured Performance

System Requirement Goal Measurement

Output Ripple 412mVpp 404mVpp

Lower Cutoff Freq (-6dB) 0.125Hz 0.2Hz

Upper Cutoff Freq (-6dB) 513kHz 400kHz

Page 24: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

24 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

7 Modifications

This design is for a 12 bit PWM system. The same design methods can be used for higher resolution system; however, you will be confronted with several limitations.

The higher resolution PWM requires a lower peak-to-peak ripple. This will require an additional filter stage. If you use the same passive filter design, the additional filter stage will have an 8.6M resistor in it. The 8.6M resistor adds excessive intrinsic noise and increases extrinsic noise pick-up. An active filter approach may be a better choice for higher order filters.

Assuming you are using the same clock for both the high and low resolution PWM signal, the higher resolution PWM signal has a lower PWM frequency than the lower resolution PWM signal. In this example the 12 bit PWM signal had a frequency of 3.91kHz. A 13 bit PWM signal would have a PWM frequency of 1.955kHz (3.91kHz / 2), and a 16 bit PWM frequency would be 244Hz (3.91kHz / ( 2

4 ) ).

In this example, we set the cutoff frequency of the PWM filter one decade below the PWM frequency. Additional filter attenuation could be achieved by moving the filter cutoff frequency even lower. If we move the filter two decades below from the PWM frequency the attenuation in decibels will double compared to the current filter. For a fourth order filter the attenuation will change from 80db to 160dB. This is a huge improvement but it makes the PWM update rate very slow (2.4Hz for a 16 bit system).

Page 25: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 25 Copyright © 2013, Texas Instruments Incorporated

8 About the Authors

Arthur Kay is an applications engineering manager at TI where he specializes in the support of amplifiers, references, and mixed signal devices. Arthur focuses a good deal on industrial applications such as bridge sensor signal conditioning. Arthur has published a book and an article series on amplifier noise. Before working in applications engineering, he was a semiconductor test engineer for Burr-Brown and Northrop Grumman Corp. Arthur received his MSEE from Georgia Institute of Technology (1993), and BSEE from Cleveland State University (1992).

Andrew Wu ([email protected]) is a Signal Chain FAA from South China who rotation in the Precision Analog Linear group at Texas Instruments. Prior to joining Texas Instruments, Andrew received his Master and Bachelor from Guilin University of Electronic Technology, major in Communication and Information System.

9 Acknowledgements & References

1. A. Kay, Operational Amplifier Noise: Techniques and Tips for Analyzing and Reducing Noise. Elsevier, 2012.

2. Special thanks to John Caldwell, Collin Wells, and Tim Green for their insight and consultation on PWM operation.

Page 26: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

26 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

Appendix A.

A.1 Electrical Schematic

Figure A-1: Electrical Schematic

-IN

_A2

+IN

_A3

OU

T_A

1

V+8

V-4

U1A

OP

A21

88-I

N_B

6

+IN

_B5

OU

T_B

7

U1B

OP

A21

88

C2

47n

C3

4.7n

C4

470p

C5

NU

C6

NU

C1

470n

R2 86

6

R3 8.

66k

R4 86

.6k

R5 86

6k

R6 N

U

R7 N

UR

150

1

2345

Inpu

t

V+

GN

D1

V-

AV

DD A

VS

S

GN

D

+15

V

-15V

GN

D0

C9

0.1u

C10

10u

C7

0.1u

C8

10u

AV

DD

AV

SS

GN

D

GN

D

12

34

56

78

910

1112

J1

GN

DG

ND

GN

DG

ND

GN

DG

ND

GN

D

R8 31

0k

R9 10

k

C12 1p

C11

100u

GN

D

C13

100u

R10

10k

GN

D

R12 31

k

R11 1k

C14 10

p

GN

D

1

2345

Out

put

GN

D

GN

D

S1_

OU

TS

2_IN

S1_

IN

S2_

OU

T

1 P

OLE

2 P

OLE

S3

PO

LES

4 P

OLE

S5

PO

LES

6 P

OLE

S

GN

D

GN

D4

GN

D5

GN

D2

GN

D

GN

D3

GN

D6

GN

D7

Page 27: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 27 Copyright © 2013, Texas Instruments Incorporated

A.2 Bill of Materials

Item # Quantity Value Designator Footprint LibRef

1 6 5000 +15V, -15V, S1_IN, S1_OUT, S2_IN, S2_OUT Keystone5000 5000

2 1 470n C1 1210 Capacitor

3 1 47n C2 1210 Capacitor

4 1 4.7n C3 1210 Capacitor

5 1 470p C4 1210 Capacitor

6 2 NU C5, C6 1210 Capacitor

7 2 0.1u C7, C9 0603 Capacitor

8 2 10u C8, C10 1210 Capacitor

9 2 100u C11, C13 1210 Capacitor

10 1 1p C12 0603 Capacitor

11 1 10p C14 0603 Capacitor

12 6 5001 GND0, GND3, GND4, GND5, GND6, GND7 Keystone5001 5001

13 4 108-0740-001 GND1, GND2, V+, V- Johnson_108-0740-001 108-0740-001

14 4 NY PMS 440 0025 PH H1, H2, H3, H4 NY PMS 440 0025 PH NY PMS 440 0025 PH

15 2 901-143 Input, Output Amphenol_901-143 901-143

16 1 TSW-106-07-G-D J1 TSW-106-07-G-D TSW-106-07-G-D

17 1 50 R1 0603 Resistor

18 1 866 R2 0603 Resistor

19 1 8.66k R3 0603 Resistor

20 1 86.6k R4 0603 Resistor

21 1 866k R5 0603 Resistor

22 2 NU R6, R7 0603 Resistor

23 1 310k R8 0603 Resistor

24 2 10k R9, R10 0603 Resistor

25 1 1k R11 0603 Resistor

26 1 31k R12 0603 Resistor

27 1 OPA2209 U1 D0008A_M OPA2209

Page 28: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

28 Microcontroller PWM to 12bit Analog Out TIDU027-July 2013-Revised July 2013 Copyright © 2013, Texas Instruments Incorporated

Appendix B.

B.1 Adjustable PWM Signal Source

To test our final design we will create an easy to adjust and use PWM signal generator shown in Figure B-1. This generator has adjustable frequency, duty cycle, Voh (output high voltage level), and Vol (output high voltage level). This will allow us to easily test all corner conditions of our specification for our final circuit implementation compliance. Figure B-2 shows the subcircuits used inside of the PWM Macromodel. VCO is a SPICE standard voltage-controlled-oscillator out of which we will use the triangle wave output scaled for 0V to 1V. Frequency is scaled for 1V=1Hz. External to the macromodel, duty cycle is scaled 0V to 100V for 0% to 100% respectively. Internally we scale this from 0 to 1V by VCVS2. An ideal comparator, VCVS1, compares the triangle waveform (0V to 1V) to the duty cycle setting (0V to 1V). The output high and low limits, Voh and Vol, are set externally and become the limit values of U2, a voltage-controlled-voltage source with clamp limits.

Figure B-1: Transient Analysis PWM Source

PWM

Vduty

Vfreq

GND

Voh

Vout

Vol

U3 PWM

Vduty 40

Vfreq 2k

Vol 0

Voh 5.25

V_PWM

Duty cycle

1V = 1% High

Frequency

1V = 1Hz

1

2

3

4

For ease of Test Simulations:

1) Duty Cycle Control

2) Frequency Control

3) Voh Control

4) Vol Control

Page 29: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

www.ti.com

TIDU027-July 2013-Revised July 2013 Microcontroller PWM to 12bit Analog Out 29 Copyright © 2013, Texas Instruments Incorporated

Figure B-2: PWM Macromodel Details

VCO+

-Gnd

Sin

TriSqr

U1 0 R1 1k

R2 1k

Vin Vout

Vp

+V

p-

U2 VCVS_EXT_LIMIT

-

+

-

+

VCVS1 1M

-

+

-

+

VCVS2 10m

GND

Voh

Vol

Vout

Vfreq

Vduty

R3 1

k

R4 1

k

R5 1

k

R6 1

k

Duty cycle

1V = 1%

Frequency

1V = 1Hz

Comparator

0 to 100V External

Converted to 0-1V Internal

0V to 1V Triangle

Voltage Clip

*Voltage Controlled Source with Limits.subckt VCVS_EXT_LIMIT Vin Vout Vp+ Vp-

*

.param Gain = 1

E1 Vout 0 VALUE={LIMIT(Gain*V(Vin,0),V(Vp+,0),V(Vp-,0))}

.ends VCVS_EXT_LIMIT

Page 30: PWM Filt er Art Kay & Andrew Wu TI Precision Designs ... · PDF fileThe PWM output from a microcontroller is a square wave that has a programmable pulse width (duty cycle)

IMPORTANT NOTICE FOR TI REFERENCE DESIGNS

Texas Instruments Incorporated ("TI") reference designs are solely intended to assist designers (“Buyers”) who are developing systems thatincorporate TI semiconductor products (also referred to herein as “components”). Buyer understands and agrees that Buyer remainsresponsible for using its independent analysis, evaluation and judgment in designing Buyer’s systems and products.

TI reference designs have been created using standard laboratory conditions and engineering practices. TI has not conducted anytesting other than that specifically described in the published documentation for a particular reference design. TI may makecorrections, enhancements, improvements and other changes to its reference designs.

Buyers are authorized to use TI reference designs with the TI component(s) identified in each particular reference design and to modify thereference design in the development of their end products. HOWEVER, NO OTHER LICENSE, EXPRESS OR IMPLIED, BY ESTOPPELOR OTHERWISE TO ANY OTHER TI INTELLECTUAL PROPERTY RIGHT, AND NO LICENSE TO ANY THIRD PARTY TECHNOLOGYOR INTELLECTUAL PROPERTY RIGHT, IS GRANTED HEREIN, including but not limited to any patent right, copyright, mask work right,or other intellectual property right relating to any combination, machine, or process in which TI components or services are used.Information published by TI regarding third-party products or services does not constitute a license to use such products or services, or awarranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectualproperty of the third party, or a license from TI under the patents or other intellectual property of TI.

TI REFERENCE DESIGNS ARE PROVIDED "AS IS". TI MAKES NO WARRANTIES OR REPRESENTATIONS WITH REGARD TO THEREFERENCE DESIGNS OR USE OF THE REFERENCE DESIGNS, EXPRESS, IMPLIED OR STATUTORY, INCLUDING ACCURACY ORCOMPLETENESS. TI DISCLAIMS ANY WARRANTY OF TITLE AND ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESSFOR A PARTICULAR PURPOSE, QUIET ENJOYMENT, QUIET POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTYINTELLECTUAL PROPERTY RIGHTS WITH REGARD TO TI REFERENCE DESIGNS OR USE THEREOF. TI SHALL NOT BE LIABLEFOR AND SHALL NOT DEFEND OR INDEMNIFY BUYERS AGAINST ANY THIRD PARTY INFRINGEMENT CLAIM THAT RELATES TOOR IS BASED ON A COMBINATION OF COMPONENTS PROVIDED IN A TI REFERENCE DESIGN. IN NO EVENT SHALL TI BELIABLE FOR ANY ACTUAL, SPECIAL, INCIDENTAL, CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANYTHEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, ARISING INANY WAY OUT OF TI REFERENCE DESIGNS OR BUYER’S USE OF TI REFERENCE DESIGNS.

TI reserves the right to make corrections, enhancements, improvements and other changes to its semiconductor products and services perJESD46, latest issue, and to discontinue any product or service per JESD48, latest issue. Buyers should obtain the latest relevantinformation before placing orders and should verify that such information is current and complete. All semiconductor products are soldsubject to TI’s terms and conditions of sale supplied at the time of order acknowledgment.

TI warrants performance of its components to the specifications applicable at the time of sale, in accordance with the warranty in TI’s termsand conditions of sale of semiconductor products. Testing and other quality control techniques for TI components are used to the extent TIdeems necessary to support this warranty. Except where mandated by applicable law, testing of all parameters of each component is notnecessarily performed.

TI assumes no liability for applications assistance or the design of Buyers’ products. Buyers are responsible for their products andapplications using TI components. To minimize the risks associated with Buyers’ products and applications, Buyers should provideadequate design and operating safeguards.

Reproduction of significant portions of TI information in TI data books, data sheets or reference designs is permissible only if reproduction iswithout alteration and is accompanied by all associated warranties, conditions, limitations, and notices. TI is not responsible or liable forsuch altered documentation. Information of third parties may be subject to additional restrictions.

Buyer acknowledges and agrees that it is solely responsible for compliance with all legal, regulatory and safety-related requirementsconcerning its products, and any use of TI components in its applications, notwithstanding any applications-related information or supportthat may be provided by TI. Buyer represents and agrees that it has all the necessary expertise to create and implement safeguards thatanticipate dangerous failures, monitor failures and their consequences, lessen the likelihood of dangerous failures and take appropriateremedial actions. Buyer will fully indemnify TI and its representatives against any damages arising out of the use of any TI components inBuyer’s safety-critical applications.

In some cases, TI components may be promoted specifically to facilitate safety-related applications. With such components, TI’s goal is tohelp enable customers to design and create their own end-product solutions that meet applicable functional safety standards andrequirements. Nonetheless, such components are subject to these terms.

No TI components are authorized for use in FDA Class III (or similar life-critical medical equipment) unless authorized officers of the partieshave executed an agreement specifically governing such use.

Only those TI components that TI has specifically designated as military grade or “enhanced plastic” are designed and intended for use inmilitary/aerospace applications or environments. Buyer acknowledges and agrees that any military or aerospace use of TI components thathave not been so designated is solely at Buyer's risk, and Buyer is solely responsible for compliance with all legal and regulatoryrequirements in connection with such use.

TI has specifically designated certain components as meeting ISO/TS16949 requirements, mainly for automotive use. In any case of use ofnon-designated products, TI will not be responsible for any failure to meet ISO/TS16949.

Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265Copyright © 2013, Texas Instruments Incorporated