Building a Class D Audio Amplifier HAT
Overview
This tutorial will walk you through building a Class D audio amplifier HAT for Raspberry Pi. Using the PAM8403 chip, we'll create a stereo amplifier delivering 3W per channel, perfect for desktop speakers or portable audio projects.
Objectives
Building a Class D amplifier HAT teaches essential audio electronics:
- Class D Operation - Understanding pulse-width modulation amplification
- Audio Signal Path - AC coupling and input filtering
- Bridge-Tied Load - Maximizing power from low voltage supplies
- HAT Integration - Interfacing with Raspberry Pi audio output
Use Cases
- Desktop Speakers - Power small speakers from Pi audio
- Media Centers - Audio for Kodi or Pi-based media players
- Voice Assistants - Speaker output for Pi voice projects
- Portable Audio - Battery-powered Bluetooth speakers
Bill of Materials
| Component | Value | Footprint | Purpose |
|---|---|---|---|
| PAM8403 | - | SOIC-16 | Class D stereo amplifier |
| C1, C2 | 1µF | 0603 | Input DC blocking |
| C3 | 10µF | 0805 | Power supply filtering |
| C4 | 100nF | 0402 | High-freq decoupling |
| RV1 | 10kΩ | Potentiometer | Volume control |
| J1 | - | 3.5mm jack | Audio input |
| SP_L, SP_R | 2-pin | 5.08mm | Speaker terminals |
| J2 | 40-pin | 2.54mm | Pi GPIO header |
Understanding Class D Amplifiers
Class D amplifiers use pulse-width modulation (PWM) for high efficiency:
| Amplifier Class | Efficiency | Heat Generation | Use Case |
|---|---|---|---|
| Class A | 20-30% | High | High-end audio |
| Class AB | 50-60% | Moderate | General audio |
| Class D | 85-95% | Low | Portable/efficient |
The PAM8403 achieves over 90% efficiency, enabling operation without heatsinks.
Circuit Design
Step 1: PAM8403 Power Supply
The PAM8403 operates from 2.5V to 5.5V. Using the Pi's 5V rail provides maximum output power:
Step 2: Audio Input with DC Blocking
Capacitors block DC offset while passing audio frequencies:
Capacitor selection:
- Target frequency: 20Hz (low end of audio)
- Input impedance: 20kΩ typical
- C = 1 / (2π × f × R) = 0.4µF minimum
- Using 1µF provides margin
Step 3: Volume Control
A potentiometer provides analog volume adjustment:
Step 4: Bridge-Tied Load Outputs
The PAM8403 uses BTL configuration, doubling voltage swing across speakers:
Complete Schematic
Raspberry Pi Audio Configuration
Configure the Pi to output audio to the 3.5mm jack:
# Set audio output to headphone jack
amixer cset numid=3 1
# Test with a sound file
aplay /usr/share/sounds/alsa/Front_Center.wav
# Adjust volume
alsamixer
For I2S audio (higher quality), modify /boot/config.txt:
dtparam=audio=on
audio_pwm_mode=2
Speaker Selection
The PAM8403 works best with 4-8Ω speakers:
| Speaker Impedance | Max Power (5V) | Recommended Use |
|---|---|---|
| 4Ω | 3W per channel | Desktop speakers |
| 8Ω | 1.5W per channel | Small speakers |
Higher impedance speakers reduce power but also reduce noise.
Ordering the PCB
Export the fabrication files and upload to JLCPCB. See Ordering Prototypes for detailed instructions.