ledc not working

michox
Posts: 8
Joined: Tue Jun 02, 2020 4:38 pm

ledc not working

Postby michox » Fri Jun 19, 2020 8:58 pm

Hi everybody,
I have been trying to get a simple pwm signal running for half a day now and I have no clue why it is not working... The doc mentions that after ledc_channel_config the pwm signal should be generated... am I missing something? I am doing nothing else except this.
here is my code:

Code: Select all

ledc_timer_config_t ledc_timer = {
        .speed_mode = LEDC_LOW_SPEED_MODE,    // timer mode
        .duty_resolution = LEDC_TIMER_12_BIT, 
        .timer_num = LEDC_TIMER_1,            // timer index
        .freq_hz = 10,                         // frequency of PWM signal
    };
    ledc_timer_config(&ledc_timer);
    ledc_channel_config_t channel_config = {
        .gpio_num = 23,
        .speed_mode = LEDC_LOW_SPEED_MODE,
        .channel = LEDC_CHANNEL_0,
        .intr_type = LEDC_INTR_DISABLE,
        .timer_sel = LEDC_TIMER_1,
        .duty = 2048,
        .hpoint = 0,
    };
    ledc_channel_config(&channel_config);
    ledc_set_duty(channel_config.speed_mode, channel_config.channel, 2048);
    ledc_update_duty(channel_config.speed_mode, channel_config.channel);
Some tips would be greatly appreciated!

ESP_Sprite
Posts: 9577
Joined: Thu Nov 26, 2015 4:08 am

Re: ledc not working

Postby ESP_Sprite » Sat Jun 20, 2020 11:33 am

Can you check the return values of the ledc_* functions? They may be telling you what is wrong, and you're just throwing away that information. Also, is there any hint to what's wrong in the serial output of your program when it runs?

michox
Posts: 8
Joined: Tue Jun 02, 2020 4:38 pm

Re: ledc not working

Postby michox » Sun Jun 21, 2020 11:27 am

they were saying that all is fine (return code 0)
I got it to work by using the arduino framework functions

Code: Select all

    ledcAttachPin(MOTOR_STEP_PIN, LEDC_CHANNEL_0);
    ledcSetup(LEDC_CHANNEL_0, 0, LEDC_TIMER_12_BIT);
    ledcWrite(LEDC_CHANNEL_0, 2048);

Who is online

Users browsing this forum: No registered users and 403 guests