Esp32 changing pwm frequency
Posted: Wed Jun 05, 2019 6:37 am
Hi,
I am using this code to vary duty cycle of pwm and is working fine
But I want vary frequency and keep duty cycle constant, My issue is that if I use
is not working...I mean if I use with a bigger delay like 1000 is changing frequency but I want do this very fast.
Is there other option to achieve this?
Basically I need change up to 60Hz starting from minimum possible...
Thank you in adavance
I am using this code to vary duty cycle of pwm and is working fine
Code: Select all
// the number of the LED pin
const int ledPin = 16; // 16 corresponds to GPIO16
// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
void setup(){
// configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
}
void loop(){
// increase the LED brightness
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
// decrease the LED brightness
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
}
Code: Select all
ledcWriteTone(channel, frequency);
Is there other option to achieve this?
Basically I need change up to 60Hz starting from minimum possible...
Thank you in adavance