Unlike Arduino boards like UNO, MEGA and many others, ESP32 board does not support analogWrite() command while programming with Arduino IDE. This is because in the Arduino IDE board library for ESP32 does not contain predefined analogWrite() function. This is because ESP32 offers many more features with its Digital to Analogue converters, which cannot be fully utilized by analogWrite() function.
ESP 32 board can output PWM signals with any frequency the programmer wants upto 40MHZ. but in other arduino boards like arduino uno only selective frequencies are available. ESP 32 also offers DAC resolution upto 16 bits. In this board the relation between ADC resolution and PWM frequency is inverse.The maximum PWM frequency with the currently used ledc duty resolution of 10 bits in PWM module is 78.125KHz. The duty resolution can be lowered down to 1 bit in which case the maximum frequency is 40 MHz, but only the duty of 50% is available. Available DAC pins in ESP32 can be seen from figure below.
int PWM_FREQUENCY = 1000; // this variable is used to define the time period int PWM_CHANNEL = 0; // this variable is used to select the channel number int PWM_RESOUTION = 12; // this will define the resolution of the signal int GPIOPIN = 15 ; // GPIO to which we want to attach this channel signal int dutyCycle = 127; // it will define the width of signal or also the one time void setup() { ledcSetup(PWM_CHANNEL, PWM_FREQUENCY, PWM_RESOUTION); ledcAttachPin(GPIOPIN, PWM_CHANNEL); } void loop() { ledcWrite(channel, dutycycle) }