Microcontroller Class D Amplifier |
5 Feb 2012 |
|
This article is about an obsolete version of the amplifier. For the new revision, go here. Class D amplifiers are very efficient and could be simple to build. They operate the power stage in a binary mode and pass the delivered pulse train through a low-pass filter (which might involve the speaker itself) to filter all frequency components introduced by the switching of current.
I designed a 70W bridged amplifier based on the Atmel Tiny (attiny45) microcontroller. Vcc is 12V and it requires no heat sink, nor has a feed-back loop of any kind. The output power is limited by 2 factors:
I used the hardware ADC and the 2-channel 8bit timer as a PWM. Since we get the full 8-bits of precission only at full power, the sound quality at quiet levels was originally very poor - for example, at 1% power, we get less than 2 bits! I implemented 2 tricks to mitigate the problem:
The PWM driver and the dither block are implemented in the timer interrupt handler: ISR(ADC_vect) {
static u8 last_error;
s16 adc = ADC;
s8 val1 = (u8)(ADC >> 2) - 128;
u8 val2 = adc>>1 & 1;
u8 error = adc & 1;
u8 dither = error & last_error;
last_error = error - dither;
DACN = 128 - val1 - dither;
DACP = 128 + val1 + val2;
}
where DACP and DACN are the two PWM registers.
The DC offset stage is just a decoupling capacitor and a trimmer. The low-pass filter that follows is required because my laptop produces
a supersonic ripple at the headphone jack. It comes from the power brick and transfers
all the way to the audio output. The H-Bridge on the output side is what people traditionally use to drive robot motors. It suits our purpose well and additionally is always in a safe state in case the CPU ever hangs. I implemented the circuit on a prototype board, which I power from a computer power supply. Functionally it works very well without producing any heat. It drives my 3 front speakers either in parallel or in series.
The LEDs are all functionally required - I use them as zener diodes. The following links contain a picture of the schematic, eagle schematic + C source code and a more artistic pic.
Choose the appropriate voltage regulator for audio input sensitivity, ie. 78L33 for 3.3V peak-to-peak input. I found the ATtiny45 internal voltage references to be too noisy and thus I used Vcc as ARef.
|
|
Comments for Microcontroller Class D Amplifier |
|
Post a new comment |
|