Error using ledc_set_freq() function

khoi.ly
Posts: 1
Joined: Tue Aug 14, 2018 3:57 pm

Error using ledc_set_freq() function

Postby khoi.ly » Tue Aug 14, 2018 4:10 pm

Hi all,

I was trying to combine two ESP-IDF examples: one is ADC that I use an external potentiometer to adjust the ADC reading, and the other is to update the blinking LED PWM frequency.

Hardware setup:
Pot: 3.3V, GND, and pin GPIO34
GPIO 18 -> LED -> 330 Ohm resistor -> GND

Here is my code:
ADC_PWM.c
Using Pot to control PWM frequency of LED
(4.33 KiB) Downloaded 656 times
When I turn the pot knob down such that the mapped frequency is less than 10Hz, I get "ledc: div param err, div_param=2500000." When I increase the ADC reading voltage such that the mapped frequency is above 10 Hz, the problem is gone.
What does this error mean? And how do it fix it?

I tried with giving a fixed ledc_timer.freq_hz to the ledc_set_freq() function, but the problem remains the same.
I also tried turning of vTaskDelay(), the problem remains the same.

Thank you for any suggestions and comments

Andreas_Mainz
Posts: 4
Joined: Sun Feb 03, 2019 6:47 am

Re: Error using ledc_set_freq() function

Postby Andreas_Mainz » Fri Feb 08, 2019 11:31 am

Hello,

i had also problems with this function and you have to set the freq value carefully. If you set the value too low, the timer would overflow and this causes an function error or even SW Reset with complete CPU restart. Switch on the serial monitor to get feedback from the ledc driver.

This is my code:

Code: Select all

if (Pendel_freq > 20)
     {    // AVOID Parameter error caused by Pendel_freq !!!!!!
          ledc_set_freq(ledc_channel.speed_mode, ledc_timer.timer_num,Pendel_freq);
      }
      else
      {
         if (Pendel_freq == 0)
         {
            // ledcWrite(Pul_out_cha,0);
            ledc_stop(ledc_channel.speed_mode, ledc_channel.channel, 0);
         }
         else
         {
            ledc_set_duty(ledc_channel.speed_mode, ledc_channel.channel, 200);
            ledc_update_duty(ledc_channel.speed_mode, ledc_channel.channel);
         }
      }

Who is online

Users browsing this forum: No registered users and 352 guests