📜 ⬆️ ⬇️

Software implementation of class D amplifier



Best-404-Error wonders whether it is possible to get a compilation result with a length of less than 512 bytes if the source is written in a high level language. You can, if you simplify the task assigned to the firmware.

The software implementation of a class D amplifier allows changing its parameters (PWM frequency, duty cycle in rest mode) by changing the firmware.
')
Device hardware diagram:



The input signals pass through capacitors to cut off the DC component, and then through resistor dividers, adding to them a new DC component of about +0.55 V. At the same time, the capacitors and lower resistors of the dividers form an HPF that cut off frequencies below 28 Hz. Experience has shown that it is better to increase the cut-off frequency of these filters, because small distortions still occur.

The signals arrive at the first and third ADCs of the microcontroller. The reference voltage of the ADC is chosen equal to 1.1 V. The division ratio of the clock frequency is 16, so the ADCs operate at a frequency of 500 kHz. The interrupt handling routine cycles through the first and third ADCs. One of the read values ​​is written to OCR1A, the second to OCR1B.

Timer 1 is configured so that the unit at the PWM outputs appears when these values ​​coincide, and zero — when the timer is reset to zero. After tuning, this part of the algorithm is performed in hardware, but at the same time as the signal amplitude, the PWM frequency changes relative to the initially specified one.

If the duty cycle in the quiescent mode is selected to be 50 percent (better quality, but less economical), then low-pass filters are needed before the dynamic heads.

Files: source code in C ++ , the result of the compilation of Atmel Studio 7.0 (it turned out 495 bytes), the scheme in Eagle format , the board in it , the G-code for cutting through the board image , drilling it , cutting it to size .

The fee is one-sided:



Dynamic heads are connected via standard dual H-bridge L293N:



Amplifier in action:

Source: https://habr.com/ru/post/455445/


All Articles