PWM for low-cost ClassD audio amplifier
Posted: 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:
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!
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);
}
Thanks!