Created
February 1, 2018 04:12
-
-
Save igrr/2875a9ca3a8a116e43524d47bee9850f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "esp_err.h" | |
#include "driver/ledc.h" | |
#include "driver/periph_ctrl.h" | |
void app_main() | |
{ | |
periph_module_enable(PERIPH_LEDC_MODULE); | |
int bit_width = 20; // 1 - 20 bits | |
int divider = 256; // Q10.8 fixed point number, 0x100 — 0x3FFFF | |
int duty_cycle = 1 << (bit_width - 1); | |
float freq_hz = ((uint64_t) LEDC_REF_CLK_HZ << 8) / (float) divider / (1 << bit_width); | |
printf("frequency: %f Hz\n", freq_hz); | |
ledc_timer_set(LEDC_HIGH_SPEED_MODE, LEDC_TIMER_0, divider, bit_width, LEDC_REF_TICK); | |
ledc_timer_rst(LEDC_HIGH_SPEED_MODE, LEDC_TIMER_0); | |
ledc_timer_resume(LEDC_HIGH_SPEED_MODE, LEDC_TIMER_0); | |
ledc_channel_config_t channel_config = { | |
.channel = LEDC_CHANNEL_0, | |
.duty = duty_cycle, | |
.gpio_num = GPIO_NUM_2, | |
.speed_mode = LEDC_HIGH_SPEED_MODE, | |
.timer_sel = LEDC_TIMER_0 | |
}; | |
ledc_channel_config(&channel_config); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above code is not working.
In the code ledc_timer_set(LEDC_HIGH_SPEED_MODE, LEDC_TIMER_0, divider, bit_width, LEDC_REF_TICK); is not able to configure LEDC_TIMER_0.
ledc_timer_config_t since it is not used the timer is not configured.
if I put ledc_get_freq it is returning 250hz always.
what can be the issue please help.
I want to generate PWM at 0.5hz
This program is not working for any frequency since the time is not set.
I tried to check it on the oscilloscope but nothing at the output.