PWM for low-cost ClassD audio amplifier

dj.petr
Posts: 1
Joined: Sat May 11, 2024 2:01 pm

PWM for low-cost ClassD audio amplifier

Postby dj.petr » Sat May 11, 2024 2:23 pm

Hi, everyone!
I´m new in ESP and I need to control duty of PWM by analogue signal connected to the internal ADC. I have this code:

Code: Select all

const int analogInputPin = 36; 
const int pwmOutputPin = 2;   

void setup() {

  pinMode(analogInputPin, INPUT);
  ledcSetup(0, 78000, 10); // freq of PWM 78kHz, 10bit
  ledcAttachPin(pwmOutputPin, 0); 
}

void loop() {
  int analogValue = analogRead(analogInputPin);
  ledcWrite(0, analogValue);
}
I watch the output of ClassD amplifier on a scope and theres a problem with aliasing on sinewave frequencies higher than cca 1kHz (input is sinewave with amplitude 1-4V with ofset voltage). So i have question, how to solve this, how to optimize code to run on a higher frequencies than 1kHz..

Thanks! ;-)

liaifat85
Posts: 200
Joined: Wed Dec 06, 2023 2:46 pm

Re: PWM for low-cost ClassD audio amplifier

Postby liaifat85 » Sun May 12, 2024 1:57 pm

Implement an anti-aliasing filter on the PWM output signal to remove high-frequency components before it reaches the amplifier. This can help in reducing aliasing effects in the output signal.

Who is online

Users browsing this forum: Bing [Bot], prashant.anlg and 86 guests