Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RMT resolution divider rounding error (IDFGH-14301) #15092

Closed
3 tasks done
rickou opened this issue Dec 25, 2024 · 1 comment
Closed
3 tasks done

RMT resolution divider rounding error (IDFGH-14301) #15092

rickou opened this issue Dec 25, 2024 · 1 comment
Assignees
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Type: Bug bugs in IDF

Comments

@rickou
Copy link

rickou commented Dec 25, 2024

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.3.2

Espressif SoC revision.

ESP32

Operating System used.

Windows

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

None

Development Kit.

ESP32-Wroom

Power Supply used.

USB

What is the expected behavior?

I need very precise RMT output frequency, so I would like to configure the RMT with a resolution of 720721Hz (based on 80MHz APB clock)
=> this give a theorical divider of 110.999956
=> expected to choose the nearest divider (111) in order to minimize the resolution loos

What is the actual behavior?

The divider is not round to nearest, but truncated to int.
in my case, i get lot of loss !
727272Hz (+7kHz !) instead of 720720.7207Hz (-0.2793Hz)

Steps to reproduce.

rmt_tx_channel_config_t tLocTxChannelConfig = {
.clk_src = RMT_CLK_SRC_DEFAULT,
.gpio_num = xxx,
.mem_block_symbols = 64,
.resolution_hz =720721,
.trans_queue_depth = 10,
.flags.invert_out = false,
.flags.with_dma = false,
.flags.io_loop_back = true
};
ESP_LOGI(TAG, "Init RMT for %s (res=%i)", psInContext->cpsConfig->cpcName, (int)tLocTxChannelConfig.resolution_hz);
ESP_ERROR_CHECK(rmt_new_tx_channel(&tLocTxChannelConfig, &psInContext->tTxChannelHandle));

Debug Logs.

I (4700) Motors: Init RMT for RA (res=720721)
W (4700) rmt: channel resolution loss, real=727272

More Information.

suggestion to round to nearest integer:

uint32_t real_div = group->resolution_hz;
real_div <<=1;
real_div +=config->resolution_hz;
real_div /=config->resolution_hz;
real_div >>=1;

or something like that: 🤢
uint32_t real_div= (uint32_t)(((float)group->resolution_hz/config->resolution_hz)+0.5)

@rickou rickou added the Type: Bug bugs in IDF label Dec 25, 2024
@github-actions github-actions bot changed the title RMT resolution divider rounding error RMT resolution divider rounding error (IDFGH-14301) Dec 25, 2024
@espressif-bot espressif-bot added the Status: Opened Issue is new label Dec 25, 2024
@wanckl
Copy link
Collaborator

wanckl commented Dec 26, 2024

@rickou you are right, thanks for your report, we will fix soon

@espressif-bot espressif-bot assigned Kainarx and suda-morris and unassigned Kainarx Dec 26, 2024
@espressif-bot espressif-bot added Status: In Progress Work is in progress Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable and removed Status: Opened Issue is new Status: In Progress Work is in progress labels Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

5 participants