Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- / Oscilador inicial, criado pelo GUSTAVO
- // ESP32 DEVKIT / Arduino IDE 1.8.9. / ESP32 versao 1.0.4
- // Based on https://portal.vidadesilicio.com.br/controle-de-potencia-via-pwm-esp32/
- // https://randomnerdtutorials.com/esp32-pwm-arduino-ide/
- // https://techtutorialsx.com/2017/06/15/esp32-arduino-led-pwm-fading/
- // Max Freq = 40 MHz / bit resolution (Bit resolution = 1 to 16 bit)
- // Duty cycle = decimal * 100 / (2 ^ bit resolution)
- // Reference https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-ledc.c
- // https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/ledc.html
- // Exemplo: para um duty cycle de 50% com 10bits (2^10 = 1024) de resolução, devemos escrever 512.
- // resolBits = log((80000000 / frequencia)) + 1;
- // dutyCycle = (pow(2, resolBits)) / 2;
- //-------------------------------------------------------------------
- void setup()
- {
- Serial.begin(115200);
- pinMode(18, OUTPUT); // GPIO_18 as Output
- ledcAttachPin(18, 1); // GPIO_18 attached to PWM Channel 1
- ledcSetup(1, 250000, 5); // Channel 1 , freq 250 KHz , 5 bit resolution = 32
- ledcWrite(1, 8); // Enable frequency with dutty cycle 25%
- }
- //-------------------------------------------------------------------
- void loop()
- {
- ;
- }
Add Comment
Please, Sign In to add comment