Warning: syntax error, unexpected '&' in comments/Microcontroller Class D Amplifier.ini on line 35 in /home/content/b/e/r/bertrem/html/rdimitrov/blog/show.php on line 135

Warning: Invalid argument supplied for foreach() in /home/content/b/e/r/bertrem/html/rdimitrov/blog/show.php on line 146

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:

  • Precision in the digital domain. Making the gain very high will hurt quality at lower levels.
  • Isd of the power MOSFETs. The ones I had are rated at 6A, potentially delivering P = I^2 R = 144W at 4 Ohm or 72W at 2 Ohm..

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:

  • Non-symmetrical output signals. Since different PWMs are driving the 2 halves of the H-bridge, they don't have to be completely out of phase. Bit adc[2] from the figure below is sent only to 1 PWM.
  • Dither. Dither was used in 8bit graphics to exploit the fact that the eye averages neighboring colors. Apparently it works very well with audio. Disabling this block noticeably reduces the audio quality.

 

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

Name: Comment:
Email(hidden):
0 + 8:
5 characters word: