Skip to content

ledc duty_resolution seems to be fixed at 13bit (GIT8266O-684) #1109

@simonliu009

Description

@simonliu009

Environment

  • Development Kit: NodeMcu-8266 (2891) V1.2 made by Ai-thinker
  • IDF version (git rev-parse --short HEAD to get the commit id.):
    08e225d (master branch)
  • Development Env: make
  • Operating System: Ubuntu in WSL
  • Power Supply: USB

Problem Description

  • It seems that ledc duty_resolution is fixed at 13 bit. I tried LEDC_TIMER_8_BIT/LEDC_TIMER_10_BIT/LEDC_TIMER_13_BIT for duty_resolution at 20KHz/25KHz frequency, to get 50% duty cycle I have to set duty to 4096( no matter resolution is 8bit or 10bit or 13bit), and to get 100% duty(almost 100%) I have to set duty to 8191( no matter resolution is 8bit or 10bit or 13bit). But 4096@50% duty cycle is supposed to be the duty of 13bit resolution, is that correct?
  • I can't get actually 100% duty cycle in ledc by setting duty to (2**duty_resolution -1), there is still a sag by the end of each cycle.

Both release/v3.3 and master branch with latest commit have this issue. I didn't check v3.4 but I guess the result should be the same.

  • 不论我怎么设置duty_resolution(我尝试了LEDC_TIMER_8_BIT/LEDC_TIMER_10_BIT/LEDC_TIMER_13_BIT),只有将duty设置为4096才能 达到50%的duty cycle,duty设为8191才能达到100%(实际上是接近100%),频率也尝试了20KHz/25KHz,结果都一样。
  • 将duty 设置为 (2**duty_resolution -1)也无法实际上达到真正的100% duty cycle,每个周期末尾还是有一个波形的跌落。

Expected Behavior

To get 50% duty cycle at 20KHz:

  • duty should be 4096 with 13 bits duty_resolution
  • duty should be 512 with 10 bits duty_resolution
  • duty should be 128 with 8 bits duty resolution

Actual Behavior

To get 50% duty cycle at 20KHz:

  • duty is 4096 with 13 bits duty_resolution -- which is correct
  • duty has to be 4096 with 10 bits duty_resolution -- which is wrong?
  • duty has to be 4096 with 8 bits duty resolution -- which is wrong?

** There should be a relationship between frequency and duty_resolution but this is a more complicated discussion in the case of ESP8266 because it involves ledc_clk_src, I might post my questions about frequency/duty_resolution on espressif esp8266 forum later. **

Code to reproduce this issue

The following code is based on ledc example from RTOS SDK which I used to reproduce this issue.
test code on gist

Debug Logs

1. LEDC fade to duty = 8192, duty resolution = 8, frequency = 20000
I (36333875) ledc: channel_num = 0 | duty = 49; duty_p = 24 | step_duty = 0 | step_01duty = 0 | step_001duty = 8

2. LEDC set to duty = 4096, duty resolution = 8, frequency = 20000
I (36339877) ledc: channel_num = 0 | duty = 24; duty_p = 49 | step_duty = 25;

Other items if possible

screen shots from my USB scope
ledc_1
ledc2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions