ledc example does not work at all
-
- Posts: 24
- Joined: Fri Oct 07, 2016 4:43 pm
ledc example does not work at all
Hi,
I've been struggling to get a PWM signal from my ESP32, so I built the ledc example from the SDK verbatim.
Still no PWM output on any of the configured pins. All I get is a logic high output when the duty is above 0 and logic low output when the duty is zero.
I suspected the problem might have been with my Nano32 board, so I fired up a WROOM-32 - with the same result.
Is the ledc example supposed to work with the current version of the SDK? If not could somebody please update the example or post errata here. Is there a poorly documented trick to getting PWM working? Or am I simply losing my faculties?
Regards,
Murray
I've been struggling to get a PWM signal from my ESP32, so I built the ledc example from the SDK verbatim.
Still no PWM output on any of the configured pins. All I get is a logic high output when the duty is above 0 and logic low output when the duty is zero.
I suspected the problem might have been with my Nano32 board, so I fired up a WROOM-32 - with the same result.
Is the ledc example supposed to work with the current version of the SDK? If not could somebody please update the example or post errata here. Is there a poorly documented trick to getting PWM working? Or am I simply losing my faculties?
Regards,
Murray
Re: ledc example does not work at all
Here are some artifacts that may help or be of interest ...
https://www.youtube.com/watch?v=rarE-WI_Y0A
https://github.com/nkolban/esp32-snippe ... s/ledDim.c
https://www.youtube.com/watch?v=rarE-WI_Y0A
https://github.com/nkolban/esp32-snippe ... s/ledDim.c
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- Posts: 24
- Joined: Fri Oct 07, 2016 4:43 pm
Re: ledc example does not work at all
Hi Neil,
Thanks for helping.
Here's what I did:
Have you tested this code on a recent version of the SDK?
Regards,
Murray
Thanks for helping.
Here's what I did:
- Copied the Hello World sample from the SDK
Copied the code verbatim from the github link you provided
Pasted that code to replace the example task
Changed names in xTaskCreate() accordingly
Successfully flashed my WROOM-32
Connected my oscilloscope to GPIO4 and reset the module
Have you tested this code on a recent version of the SDK?
Regards,
Murray
Re: ledc example does not work at all
Howdy Murray,
I just rebuilt the test using my sample code and it worked as before. In this test I used GPIO 14 as GPIO 4 wasn't already wired to my logic analyzer and I also used a logic analyzer to look at the results. All good and a nice clean PWM signal. Not sure what to say ... maybe check your ground lead for the oscilloscope or some other oscilloscope settings (I don't own one of those and so am speaking from pure ignorance).
I'm using the latest ESP-IDF from github master as well as the latest ESP-IDF template app.
I just rebuilt the test using my sample code and it worked as before. In this test I used GPIO 14 as GPIO 4 wasn't already wired to my logic analyzer and I also used a logic analyzer to look at the results. All good and a nice clean PWM signal. Not sure what to say ... maybe check your ground lead for the oscilloscope or some other oscilloscope settings (I don't own one of those and so am speaking from pure ignorance).
I'm using the latest ESP-IDF from github master as well as the latest ESP-IDF template app.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- Posts: 24
- Joined: Fri Oct 07, 2016 4:43 pm
Re: ledc example does not work at all
Thanks Neil
Odd! I get the same result with my Nano32. I have been developing on both the ESP32 and the ESP8266, and can see PWM signals on the ESP8266 (after I eventually understood the documentation). My work so far on the ESP32 has been with a web server and plain GPIO driving stepper motors. These are now driven through a shift register so that only 3 GPIOs are used between both motors. There is no problem with the CRO connection as I have been using it all along to test signals.
I'm now moving on to DC motor control, and so need PWM. As I said in the original post, the ledc example was built with zero changes. All default values kept with menuconfig. No PWM, just DC that appears to be LOW when the duty cycle is set to 0, and HIGH when it is set to anything else.
Frustrating!
Murray
Odd! I get the same result with my Nano32. I have been developing on both the ESP32 and the ESP8266, and can see PWM signals on the ESP8266 (after I eventually understood the documentation). My work so far on the ESP32 has been with a web server and plain GPIO driving stepper motors. These are now driven through a shift register so that only 3 GPIOs are used between both motors. There is no problem with the CRO connection as I have been using it all along to test signals.
I'm now moving on to DC motor control, and so need PWM. As I said in the original post, the ledc example was built with zero changes. All default values kept with menuconfig. No PWM, just DC that appears to be LOW when the duty cycle is set to 0, and HIGH when it is set to anything else.
Frustrating!
Murray
Re: ledc example does not work at all
If you can recreate in a cleansed/minimal ESP32 application, you might post it to a download site and we can take a look at the source and/or compile it on other environments ... maybe a new set of eyes might see something helpful.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
-
- Posts: 24
- Joined: Fri Oct 07, 2016 4:43 pm
Re: ledc example does not work at all
OK, I have taken the ledc example and applied Occam's Razor to get a bare minimum example. I believe that it's short enough to simple paste here. This time I get no PWM at all. What I do get is a flat line LOW level with a HIGH pulse of 0.5 second duration every 37 seconds.
Since my last post I created a fresh clone of the SDK to make sure that it wasn't in some strange state.
Here is the code:
Since my last post I created a fresh clone of the SDK to make sure that it wasn't in some strange state.
Here is the code:
Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/xtensa_api.h"
#include "driver/ledc.h"
#include "esp_attr.h"
#include "esp_err.h"
#define LEDC_IO_0 (19)
esp_err_t app_main()
{
ledc_timer_config_t ledc_timer = {
.bit_num = LEDC_TIMER_13_BIT,
.freq_hz = 5000,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.timer_num = LEDC_TIMER_0
};
ledc_timer_config(&ledc_timer);
ledc_channel_config_t ledc_channel = {
.channel = LEDC_CHANNEL_0,
.duty = 100,
.gpio_num = LEDC_IO_0,
.intr_type = LEDC_INTR_DISABLE,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.timer_sel = LEDC_TIMER_0
};
ledc_channel_config(&ledc_channel);
while(1) {
ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, 8000);
vTaskDelay(2000 / portTICK_PERIOD_MS);
ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, 0);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}
-
- Posts: 24
- Joined: Fri Oct 07, 2016 4:43 pm
Re: ledc example does not work at all
That was with my Nano32 board. I get the same result with my WROOM-32 except that the period between the pulses is nearly 28 seconds.]
- Attachments
-
- IMG_20170301_114049.jpg (135.71 KiB) Viewed 16948 times
Re: ledc example does not work at all
You probably need to add a call to ledc_update_duty(mode, channel) after the call to ledc_set_duty.
http://esp-idf.readthedocs.io/en/latest ... _channel_t
If you check the LEDC example, you can see this being done after the "printf("LEDC set duty without fade\n");" line
http://esp-idf.readthedocs.io/en/latest ... _channel_t
If you check the LEDC example, you can see this being done after the "printf("LEDC set duty without fade\n");" line
-
- Posts: 24
- Joined: Fri Oct 07, 2016 4:43 pm
Re: ledc example does not work at all
Thanks iggr
That explains the difference in behaviour between the above code and my previous tests. However, remember that I tried the ledc example verbatim.
Anyway, I added the ledc_update_duty() calls to the simple test above and I am back to the original problem. Scope trace is attached. Note the time scale.
That explains the difference in behaviour between the above code and my previous tests. However, remember that I tried the ledc example verbatim.
Anyway, I added the ledc_update_duty() calls to the simple test above and I am back to the original problem. Scope trace is attached. Note the time scale.
- Attachments
-
- IMG_20170301_132639.jpg (116.11 KiB) Viewed 16942 times
Who is online
Users browsing this forum: No registered users and 205 guests