Seeking Assistance to Reduce Delay in PWM Pulse Output
Posted: Mon Jun 12, 2023 8:16 am
Hello everyone,
I am currently working on a project where I am using the ESP32's LEDC module to generate a pulse output in response to an input trigger. However, I am facing an issue with a delay of one full cycle before the first rising edge of the pulse is generated. I am seeking help to eliminate this delay.
Ideally, I would like to achieve a situation where the rising edge of the pulse is generated within 30 microseconds after receiving the trigger.
Here's a summary of the problem and the steps I have taken so far:
Symptoms:
- I have implemented the pulse output using the LEDC module on the ESP32, triggered by an input signal.
- The pulse's frequency is set to 500Hz, but there is a delay of approximately 2.010ms from the moment the trigger is received until the output is generated.
- I believe this 2ms delay corresponds to one full cycle.
Steps taken:
- I have observed that the behavior differs when I execute the "ledc_timer_config" function every time a trigger is received versus only changing the duty cycle.
- If I execute "ledc_timer_config" before generating the pulse output, it consistently introduces a delay of around 2.010ms.
- By changing the duty cycle to either 0 or any other value, I can observe that the first rising edge occurs within a range of 100 microseconds to 2ms.
- Upon checking the counter value of the timer being used, I discovered that when the counter value is closer to overflow, the delay is smaller, whereas when the counter value is farther from overflow, the delay is larger.
- Unfortunately, I cannot directly set the counter value as it is read-only.
I would greatly appreciate any suggestions or insights into how I can eliminate or reduce this delay. My goal is to generate the rising edge of the pulse within 30 microseconds after receiving the trigger.
Thank you in advance for your help and suggestions!
Best regards,
hkqwerty
I am currently working on a project where I am using the ESP32's LEDC module to generate a pulse output in response to an input trigger. However, I am facing an issue with a delay of one full cycle before the first rising edge of the pulse is generated. I am seeking help to eliminate this delay.
Ideally, I would like to achieve a situation where the rising edge of the pulse is generated within 30 microseconds after receiving the trigger.
Here's a summary of the problem and the steps I have taken so far:
Symptoms:
- I have implemented the pulse output using the LEDC module on the ESP32, triggered by an input signal.
- The pulse's frequency is set to 500Hz, but there is a delay of approximately 2.010ms from the moment the trigger is received until the output is generated.
- I believe this 2ms delay corresponds to one full cycle.
Steps taken:
- I have observed that the behavior differs when I execute the "ledc_timer_config" function every time a trigger is received versus only changing the duty cycle.
- If I execute "ledc_timer_config" before generating the pulse output, it consistently introduces a delay of around 2.010ms.
- By changing the duty cycle to either 0 or any other value, I can observe that the first rising edge occurs within a range of 100 microseconds to 2ms.
- Upon checking the counter value of the timer being used, I discovered that when the counter value is closer to overflow, the delay is smaller, whereas when the counter value is farther from overflow, the delay is larger.
- Unfortunately, I cannot directly set the counter value as it is read-only.
I would greatly appreciate any suggestions or insights into how I can eliminate or reduce this delay. My goal is to generate the rising edge of the pulse within 30 microseconds after receiving the trigger.
Thank you in advance for your help and suggestions!
- ledc_timer_config_t ledc_timer =
- {
- .speed_mode = LEDC_HIGH_SPEED_MODE,
- .duty_resolution = LEDC_TIMER_14_BIT,
- .timer_num = LEDC_TIMER_0,
- .freq_hz = 500,
- .clk_cfg = LEDC_AUTO_CLK
- };
- if (ledc_timer_config(&ledc_timer) != ESP_OK)
- {
- Serial.println("ledc setup failed!");
- }
- ledc_channel_config_t ledc_channel =
- {
- .gpio_num = GPIO_NUM_14,
- .speed_mode = LEDC_HIGH_SPEED_MODE,
- .channel = LEDC_CHANNEL_0,
- .intr_type = LEDC_INTR_DISABLE,
- .timer_sel = LEDC_TIMER_0,
- .duty = 0,
- .hpoint = 0
- };
- ledc_channel_config(&ledc_channel);
- ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, DUTY);
- ledc_update_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0);
hkqwerty