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

AN2236

PIC16F Full-Bridge Class D Audio Amplifier

Author: Willem J. Smit This application note provides an example of using a


Microchip Technology Inc. PIC16(L)F1769 device together with several core inde-
pendent peripherals (CIPs) to implement a low-cost,
low-power, full-bridge, Class D audio amplifier. It uses
INTRODUCTION minimal components and was designed to be
This application note focuses on how to use a PIC16F implemented in a small and compact form factor.
microcontroller (MCU) for implementing a low-cost,
Class D full-bridge audio amplifier. CLASS D TOPOLOGY
The basic operation of the class-D amplifier is to con-
A Class D amplifier requires several main components
vert an analog input signal into a pulse-width modulator
to be functional. They are listed below:
(PWM) output. The PWM output is used to drive a pair
of pMOSFET and nMOSFET, which provide amplifica- • Input Signal
tion. The amplified signal is then externally filtered via • Triangle Waveform Generator
an X-order low-pass LC filter, which reproduces the • Comparator
original analog signal with the exception being • PWM Output Stage
amplified. • Amplification
• Low-pass Filter
Because MOSFET operates by being either fully OFF
or fully ON, the efficiency of a Class D amplifier is sig- Figure 1 demonstrates the basic operation of a Class D
nificantly higher than that of a linear amplifier. This is amplifier.
due to fact that less power is dissipated as heat in the
amplifier circuit.
By comparison, the efficiency of a Class D amplifier can
easily be greater than ~90%, whereas a typical linear
class-A amplifier has a theoretical maximum efficiency
of ~50%, due to the designed operation of being always
ON.

FIGURE 1: CLASS D AMPLIFIER BLOCK DIAGRAM

VCC LPͲFilter VCC


Speaker

TriangularWave

AnalogAudio

AnalogAudio

 2016 Microchip Technology Inc. DS00002336A-page 1


AN2236
The input signal, triangular waveform, and comparator
(CMP) are used in combination to generate the PWM
signal, which is later amplified.
The duty cycle of the PWM is directly proportional to
the magnitude of the analog signal. As the magnitude
increases or decreases, the PWM duty cycle also
increases or decreases, equivalently. The resulting out-
put of the comparator is a PWM digital representation
of the original analog input signal. Figure 2
demonstrates this output.

FIGURE 2: PWM PROPORTIONAL TO ANALOG SIGNAL MAGNITUDE

When amplifying the PWM output, either a half- or full- provide an optimal performance using a 1st or 2nd order
bridge amplifying stage can be used. As shown in LC filter. In other cases, Class D amplifier applications
Figure 1, this application of a Class D amplifier is imple- can simply rely on the speaker’s coil capacitance and
mented using a full-bridge amplifying stage, which inductance to act as a LC low- pass filter. In many
means it differentially drives the speaker. A full-bridge cases, depending on the quality of audio needed in the
topology offers greater performance over a half-bridge application, the speaker itself is a sufficient low-pass
topology by lessening rail voltage fluctuations on the LC filter.
power supply, due to the energy being fed back into it
by the amplifier.
With a full-bridge stage, there are two complementary
half-bridge stages, thus either side provides a path to
ground. Consequently, less energy is fed back to the
power supply. In addition, a full-bridge can also be
helpful at canceling out DC offsets and harmonic distor-
tion. A full-bridge topology also offers an increase in
maximum power output versus a half-bridge topology
by producing twice the swing on the speaker, because
it is being driven differentially.
The filtering stage of Class D depends on how closely
the user wants to reproduce the original input analog
signal or audio signal. The trade-off is represented by
the number of components versus retaining the original
analog signal and the resulting quality of the audio out-
put. The recommended filter for a Class D amplifier is
a low-pass LC filter.
An LC filter has no internal resistance, so it is not wast-
ing energy – which can result in lower audio volume
and reduced efficiency. Many Class D amplifiers can

DS00002336A-page 2  2016 Microchip Technology Inc.


AN2236
IMPLEMENTING A FULL-BRIDGE
CLASS D AUDIO AMPLIFIER USING A
PIC16(L)F1769
In order to implement the Class D amplifier in Figure 1,
a PIC16(L)F1769 MCU is used, featuring its CIPs and
other on-board peripherals. The following peripherals
are need:
• Master Synchronous Serial Port (MSSP)
• Digital to Analog Converter (5 and 10-bit DAC)
• Timer2 & Timer4
• Programmable Ramp Generator (PRG)
• Voltage Comparator (CMP)
• Complementary Output Generator (COG)
Figure 3 shows how these peripherals are used and
configured to create a full-bridge Class D audio
amplifier with audio playback using a PIC16(L)F1769
MCU.
In this application, the source of the audio is stored in
digital form in an external EEPROM, which is read back
via the MSSP. It is also possible to modify this applica-
tion to use the UART to stream digital data from a com-
puter to other sources. After the digital audio data is
received, it is converted into analog by feeding it
through the 10-bit DAC. This application can also easily
be modified to bypass the digital input method to pro-
vide an analog signal directly to the positive input of the
CMP.

FIGURE 3: PIC16(L)F1769 MCU FULL-BRIDGE CLASS D AUDIO AMPLIFIER WITH DIGITAL


SOURCE

MSSP DAC
EEPROM SPI/I2C 10Ͳbit Complementary
2 TC4427
SPI/I C OutputGenerator

Programmable
Ramp
Generator
(SquareWave)

Timer DAC
PWM
8Ͳbit 5Ͳbit PIC16F176X

 2016 Microchip Technology Inc. DS00002336A-page 3


AN2236
Figure 4 outlines the analog input method. In addition,
this example demonstrates how the internal opera-
tional amplifier can be used for gaining up the incoming
analog signal in an application that has a low amplitude
input signal.

FIGURE 4: PIC16(L)F1769 MCU FULL-BRIDGE CLASS D AUDIO AMPLIFIER WITH ANALOG


SOURCE

AnalogAudio
Complementary TC4427
OutputGenerator

Programmable
Ramp
Generator
(SquareWave)

Timer DAC
PWM
8Ͳbit 5Ͳbit PIC16F176X

The PRG is used to generate the required triangular


waveform. To do so, one PWM was used as the timing
source for the rise and falling edges of the PRG at a fre-
quency of 128 kHz. A single 5-bit DAC is used as the
voltage source for the PRG.
Before passing the data from the MSSP to the DAC, a
timing factor needs to be taken into account. Because
the audio data is stored in digital form, a certain sample
rate is associated with it. In this case, the data is stored
in RAW (header-less), unsigned, 8-bit form with a sam-
ple rate of 8000 Hz. To get the best representation of
the original analog signal and to playback the audio at
the correct speed, the digital audio data needs to be
read back from the EEPROM every 125 μs (1/8000Hz).
To adequately and easily read data from the EEPROM
every 125 µs, a TMR interrupt was implemented. The
overflow of the TMR interrupt triggers an EEPROM
read, and the retrieved byte is then passed to the DAC,
where it is converted to the appropriate analog level.
The analog level is then compared to the triangular
waveform via the CMP, resulting in a proportional duty
cycle of the PWM in relation to the analog level.
Given that this application makes use of a full-bridge
amplifier, a complementary PWM signal is required to
drive it. To generate these signals, the PWM signal is
passed through a COG which produces two comple-
mentary PWM signals. The complementary PWM sig-
nals are then passed to the full-bridge amplifier for
audio playback and amplification.

DS00002336A-page 4  2016 Microchip Technology Inc.


AN2236
CONCLUSION
With the wide range of both analog and digital periph-
erals on the PIC16(L)F176X device, it provides a com-
plete solution to implement a full-bridge, Class D audio
amplifier on a PIC16F microcontroller.
This design quashes the need to use expensive exter-
nal active components. It also has been optimized to
reduce the number of external passive components
that are needed. This allows the user to implement a
cost-efficient, small and compact form factor,
full-bridge, Class D audio amplifier.

REFERENCES
For more information on how to use and configure the
modules mentioned in this application note, see the
following reference documents:
1. Interfacing Serial EEPROMs with 8-Bit PIC®
Microcontrollers (AN2045)
2. Complementary Output Generator Technical
Brief (TB3119)
3. Operational Amplifier Module of 8-Bit PIC®
Microcontrollers (TB3132)
4. Programmable Ramp Generator Technical Brief
(TB3140)
5. High Efficiency Solutions for Portable LED
Lighting (DS01427A)
6. PIC16(L)F1764/5/8/9 Data Sheet
(DS40001775)

 2016 Microchip Technology Inc. DS00002336A-page 5


APPENDIX A: SCHEMATICS
DS00002336A-page 6

AN2236
FIGURE A-1: SCHEMATICS A

VDD U1 U2A
18 16
VDD RA0/AN0/Vref-/DAC1234REF-/DAC1234OUT1/C1IN0+/C3IN0+/ICSPDAT PGD PIC_LED1
15 2 7
RA1/AN1/VREF+/DAC1234REF+/C1234IN0-/ICSPCLK PGC COG1B SPK2
17 14
C1 C2 VSS RA2/AN2/ZCD/T0CKI/COG12IN/INT COG1A
1
0.1uF 0.010uF RA3/T6CKI/DSM12CH/MCLR/VPP MCLR
20 6 3
10V 25V RA4/AN3/T1G/SOSCO/DSM12CL/OSC2/CLKOUT TX SPK_VDD VDD GND
GND 19
0603 0603 RA5/T1CKI/T2CKI/SOSCI/CLCIN3/DSM12MOD/OSC1/CLKIN BOOST_EN
TC4427A
10 GND
RB4/AN10/OPA1IN0-/SDI/SDA SDO
9 U2B
RB5/AN11/OPA1IN0+/RX SDI
GND 8
RB6/C1IN1+/C3IN1+/SCL/SCK SCK
7 4 5
RB7/C2IN1-/C4IN1+/CK EEPROM_SS COG1A SPK1
TP1 13
RC0/AN4/C2IN0-/C4IN0+/T5CKI COG1B
12 6 3
GND RC1/AN5/C1234IN1-/T4CKI/CLCIN2 RX SPK_VDD VDD GND
11
TP LOOP Black TH RC2/AN6/OPA1OUT/OPA2IN1-/OPA2IN1+/C1IN2-/C2IN2-/RG1IN0/RG2IN1 RHEO_SS
4 TC4427A
RC3/AN7/OPA2OUT/ OPA1IN1-/OPA1IN1+/C1234IN3-/RG2IN0/RG1IN1/T5G/CLCIN0 SW3
3 GND
RC4/RG1R/RG2R/T3G/CLCIN1 SW2
2
RC5/RG1F/RG2F/T3CKI/CCP1 SW1
5 U2C
RC6/AN8/OPA2IN0-/SS HOLD
6 1 8
RC7/AN9/OPA2IN0+ WP NC NC
PIC16F1769-I/ML

LD1 6 3
R9 SPK_VDD VDD GND
J1
PIC_LED1 VDD
TC4427A
MCLR 430R
5 4 3 2 1

BLUE GND
VDD 0603 C3
GND 5% 0.1uF
PGD 10V
PGC 0603
VDD
HDR-2.54 Male 1x5 1 8
EEPROM_SS CS VCC
6 GND
SCK SCK
5 2
SDO SI SO SDI C4
3
WP WP 0.1uF
VDD 10V C5
7 4
HOLD HOLD VSS 0603
R1 U3 DNP
10k GND GND 25V
0603 0603
L1 L2
5% S1 SPK1 SPK2
SW1 10uH 10uH
TACT SPST

1
 2016 Microchip Technology Inc.

GND
C6 C7
0.47uF 0.47uF
VDD 25V SP1 25V
VDD 0805 0805
R2
10k R3 GND GND
0603 10k
5% S2 0603
5% S3
SW2
TACT SPST SW3
TACT SPST
GND
GND
FIGURE A-2: SCHEMATICS B
 2016 Microchip Technology Inc.

R8

DNP
0603
L3 5% D1
SPK_VDD
4.7μH
PMEG2005EH,115
USB2.0 MICRO-B FEMALE R4
J2 U4 510k

1
VDD MCP1661 0805

SW
1 5%
VBUS
2 5 3
D- USB_D_N VDD VIN FB FBA
3
D+ USB_D_P C8
ID
4
C9 BOOST_EN
4
E
EN R5 10uF
5 DNP
GND 10uF 25V

D
GND
0603 FBB
25V 1206

GN
5%

G
0

1206

2
R6
GND 51k
0603
GND GND 5%

GND GND

GND
C10
VDD
0.1uF
10V C11
R7 GND 0.1uF
10k U5 0603
MCP4162 MSOP-8 10V
0603 VDD 16 13
VDD VSS U6 0603
1% 1 12
GP0 D+ USB_D_P
2 11 1 8
GP1 D- USB_D_N RHEO_SS CS VDD VDD
3 10 2 7
RST VUSB SCK SCK SDO SDI
4 9 3 6
TX UART RX SCL SDO SDI P0B FBA
5 8 4 5

AN2236
DS00002336A-page 7

RX UART TX SDA C12 VSS P0W FBB


6 7
GP2 GP3 4.7uF
10V
MCP2221-I/ML GND
0805

GND
Note the following details of the code protection feature on Microchip devices:
• Microchip products meet the specification contained in their particular Microchip Data Sheet.

• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.

• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.

• Microchip is willing to work with the customer who is concerned about the integrity of their code.

• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”

Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.

Information contained in this publication regarding device Trademarks


applications and the like is provided only for your convenience The Microchip name and logo, the Microchip logo, AnyRate, AVR,
and may be superseded by updates. It is your responsibility to AVR logo, AVR Freaks, BeaconThings, BitCloud, CryptoMemory,
ensure that your application meets with your specifications. CryptoRF, dsPIC, FlashFlex, flexPWR, Heldo, JukeBlox, KEELOQ,
MICROCHIP MAKES NO REPRESENTATIONS OR KEELOQ logo, Kleer, LANCheck, LINK MD, maXStylus,
WARRANTIES OF ANY KIND WHETHER EXPRESS OR maXTouch, MediaLB, megaAVR, MOST, MOST logo, MPLAB,
IMPLIED, WRITTEN OR ORAL, STATUTORY OR OptoLyzer, PIC, picoPower, PICSTART, PIC32 logo, Prochip
OTHERWISE, RELATED TO THE INFORMATION, Designer, QTouch, RightTouch, SAM-BA, SpyNIC, SST, SST
INCLUDING BUT NOT LIMITED TO ITS CONDITION, Logo, SuperFlash, tinyAVR, UNI/O, and XMEGA are registered
QUALITY, PERFORMANCE, MERCHANTABILITY OR trademarks of Microchip Technology Incorporated in the U.S.A.
FITNESS FOR PURPOSE. Microchip disclaims all liability and other countries.
arising from this information and its use. Use of Microchip ClockWorks, The Embedded Control Solutions Company,
devices in life support and/or safety applications is entirely at EtherSynch, Hyper Speed Control, HyperLight Load, IntelliMOS,
the buyer’s risk, and the buyer agrees to defend, indemnify and mTouch, Precision Edge, and Quiet-Wire are registered
hold harmless Microchip from any and all damages, claims, trademarks of Microchip Technology Incorporated in the U.S.A.
suits, or expenses resulting from such use. No licenses are Adjacent Key Suppression, AKS, Analog-for-the-Digital Age, Any
conveyed, implicitly or otherwise, under any Microchip Capacitor, AnyIn, AnyOut, BodyCom, chipKIT, chipKIT logo,
intellectual property rights unless otherwise stated. CodeGuard, CryptoAuthentication, CryptoCompanion,
CryptoController, dsPICDEM, dsPICDEM.net, Dynamic Average
Matching, DAM, ECAN, EtherGREEN, In-Circuit Serial
Programming, ICSP, Inter-Chip Connectivity, JitterBlocker,
KleerNet, KleerNet logo, Mindi, MiWi, motorBench, MPASM, MPF,
MPLAB Certified logo, MPLIB, MPLINK, MultiTRAK, NetDetach,
Omniscient Code Generation, PICDEM, PICDEM.net, PICkit,
PICtail, PureSilicon, QMatrix, RightTouch logo, REAL ICE, Ripple
Blocker, SAM-ICE, Serial Quad I/O, SMART-I.S., SQI,
SuperSwitcher, SuperSwitcher II, Total Endurance, TSHARC,
USBCheck, VariSense, ViewSpan, WiperLock, Wireless DNA, and
ZENA are trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated in
Microchip received ISO/TS-16949:2009 certification for its worldwide the U.S.A.
headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona; Gresham, Oregon and design centers in California Silicon Storage Technology is a registered trademark of Microchip
and India. The Company’s quality system processes and procedures Technology Inc. in other countries.
are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping
devices, Serial EEPROMs, microperipherals, nonvolatile memory and GestIC is a registered trademark of Microchip Technology
analog products. In addition, Microchip’s quality system for the design Germany II GmbH & Co. KG, a subsidiary of Microchip Technology
and manufacture of development systems is ISO 9001:2000 certified.
Inc., in other countries.
All other trademarks mentioned herein are property of their

QUALITY MANAGEMENT SYSTEM respective companies.


© 2016, Microchip Technology Incorporated, All Rights Reserved.
CERTIFIED BY DNV ISBN: 978-1-5224-1225-0

== ISO/TS 16949 ==

 2016 Microchip Technology Inc. DS00002336A-page 7


Worldwide Sales and Service
AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPE
Corporate Office Asia Pacific Office China - Xiamen Austria - Wels
2355 West Chandler Blvd. Suites 3707-14, 37th Floor Tel: 86-592-2388138 Tel: 43-7242-2244-39
Chandler, AZ 85224-6199 Tower 6, The Gateway Fax: 86-592-2388130 Fax: 43-7242-2244-393
Tel: 480-792-7200 Harbour City, Kowloon China - Zhuhai Denmark - Copenhagen
Fax: 480-792-7277 Hong Kong Tel: 86-756-3210040 Tel: 45-4450-2828
Technical Support: Tel: 852-2943-5100 Fax: 86-756-3210049 Fax: 45-4485-2829
http://www.microchip.com/ Fax: 852-2401-3431 India - Bangalore Finland - Espoo
support
Australia - Sydney Tel: 91-80-3090-4444 Tel: 358-9-4520-820
Web Address:
Tel: 61-2-9868-6733 Fax: 91-80-3090-4123 France - Paris
www.microchip.com Fax: 61-2-9868-6755 India - New Delhi Tel: 33-1-69-53-63-20
Atlanta Tel: 91-11-4160-8631 Fax: 33-1-69-30-90-79
China - Beijing
Duluth, GA
Tel: 86-10-8569-7000 Fax: 91-11-4160-8632 France - Saint Cloud
Tel: 678-957-9614
Fax: 86-10-8528-2104 India - Pune Tel: 33-1-30-60-70-00
Fax: 678-957-1455
China - Chengdu Tel: 91-20-3019-1500 Germany - Garching
Austin, TX Tel: 86-28-8665-5511
Tel: 512-257-3370 Japan - Osaka Tel: 49-8931-9700
Fax: 86-28-8665-7889 Tel: 81-6-6152-7160 Germany - Haan
Boston Fax: 81-6-6152-9310 Tel: 49-2129-3766400
China - Chongqing
Westborough, MA
Tel: 86-23-8980-9588 Japan - Tokyo Germany - Heilbronn
Tel: 774-760-0087 Fax: 86-23-8980-9500
Fax: 774-760-0088 Tel: 81-3-6880- 3770 Tel: 49-7131-67-3636
China - Dongguan Fax: 81-3-6880-3771 Germany - Karlsruhe
Chicago Tel: 86-769-8702-9880 Korea - Daegu Tel: 49-721-625370
Itasca, IL
China - Guangzhou Tel: 82-53-744-4301 Germany - Munich
Tel: 630-285-0071
Fax: 630-285-0075 Tel: 86-20-8755-8029 Fax: 82-53-744-4302 Tel: 49-89-627-144-0
China - Hangzhou Korea - Seoul Fax: 49-89-627-144-44
Dallas
Tel: 86-571-8792-8115 Tel: 82-2-554-7200 Germany - Rosenheim
Addison, TX
Fax: 86-571-8792-8116 Fax: 82-2-558-5932 or Tel: 49-8031-354-560
Tel: 972-818-7423
Fax: 972-818-2924 China - Hong Kong SAR 82-2-558-5934
Israel - Ra’anana
Tel: 852-2943-5100 Malaysia - Kuala Lumpur Tel: 972-9-744-7705
Detroit
Fax: 852-2401-3431 Tel: 60-3-6201-9857
Novi, MI Italy - Milan
China - Nanjing Fax: 60-3-6201-9859
Tel: 248-848-4000 Tel: 39-0331-742611
Tel: 86-25-8473-2460 Malaysia - Penang Fax: 39-0331-466781
Houston, TX
Tel: 281-894-5983 Fax: 86-25-8473-2470 Tel: 60-4-227-8870
Italy - Padova
China - Qingdao Fax: 60-4-227-4068
Indianapolis Tel: 39-049-7625286
Tel: 86-532-8502-7355 Philippines - Manila
Noblesville, IN Netherlands - Drunen
Fax: 86-532-8502-7205 Tel: 63-2-634-9065
Tel: 317-773-8323 Tel: 31-416-690399
Fax: 317-773-5453 China - Shanghai Fax: 63-2-634-9069 Fax: 31-416-690340
Tel: 317-536-2380 Tel: 86-21-3326-8000 Singapore
Norway - Trondheim
Fax: 86-21-3326-8021 Tel: 65-6334-8870
Los Angeles Tel: 47-7289-7561
China - Shenyang Fax: 65-6334-8850
Mission Viejo, CA Poland - Warsaw
Tel: 949-462-9523 Tel: 86-24-2334-2829 Taiwan - Hsin Chu
Tel: 48-22-3325737
Fax: 949-462-9608 Fax: 86-24-2334-2393 Tel: 886-3-5778-366
Fax: 886-3-5770-955 Romania - Bucharest
Tel: 951-273-7800 China - Shenzhen
Tel: 40-21-407-87-50
Raleigh, NC Tel: 86-755-8864-2200 Taiwan - Kaohsiung
Tel: 919-844-7510 Fax: 86-755-8203-1760 Tel: 886-7-213-7830 Spain - Madrid
Tel: 34-91-708-08-90
New York, NY China - Wuhan Taiwan - Taipei
Fax: 34-91-708-08-91
Tel: 631-435-6000 Tel: 86-27-5980-5300 Tel: 886-2-2508-8600
Fax: 86-27-5980-5118 Fax: 886-2-2508-0102 Sweden - Gothenberg
San Jose, CA Tel: 46-31-704-60-40
Tel: 408-735-9110 China - Xian Thailand - Bangkok
Tel: 408-436-4270 Tel: 86-29-8833-7252 Tel: 66-2-694-1351 Sweden - Stockholm
Fax: 86-29-8833-7256 Fax: 66-2-694-1350 Tel: 46-8-5090-4654
Canada - Toronto
Tel: 905-695-1980 UK - Wokingham
Fax: 905-695-2078 Tel: 44-118-921-5800
Fax: 44-118-921-5820

DS00002336A-page 8  2016 Microchip Technology Inc.


11/07/16

You might also like