Issue with MCPWM Prescaler on ESP32-S3

KashunCheng
Posts: 1
Joined: Sun Sep 08, 2024 8:29 pm

Issue with MCPWM Prescaler on ESP32-S3

Postby KashunCheng » Sun Sep 08, 2024 8:41 pm

Hello everyone,

I’ve been working with the MCPWM feature on the ESP32-S3 and encountered an issue with updating the prescaler values on the fly, similar to what was discussed in the original post (viewtopic.php?t=14210). In that post, henrik.basic presented a workaround that worked for the ESP32.

Following the same workaround:

Code: Select all

mcpwm0.timer[0].mode.start        = 0;   // Stop on TEZ
mcpwm0.timer[0].period.prescale   = newPrescale;
mcpwm0.timer[0].sync.timer_phase  = 0;
mcpwm0.timer[0].sync.sync_sw     ^= 1;
delayMicroseconds(0);
mcpwm0.timer[0].mode.start        = 2;   // Free running
This worked well on my ESP32 board, when I tried using the exact same code on the ESP32-S3, the prescaler value didn’t update as expected. I still encountered the issue where the prescaler was stuck at the old value.

I’ve tried experimenting with different delays between stopping and restarting the timer, but I haven’t been able to resolve this on the ESP32-S3. It seems like the ESP32-S3 might handle the prescaler differently, or there could be other factors in play with this newer chip.

Has anyone else experienced this issue with the ESP32-S3? If so, were you able to find a working solution? I’d appreciate any insights or recommendations!

Thank you in advance for your help.

MicroController
Posts: 1724
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Issue with MCPWM Prescaler on ESP32-S3

Postby MicroController » Mon Sep 09, 2024 8:51 am

At https://github.com/espressif/esp-idf/bl ... ruct.h#L36 it says:
the divisor of PT0_clk, takes effect when PWM timer stops and starts agsin.

Code: Select all

mcpwm0.timer[0].mode.start        = 0;   // Stop on TEZ
...
mcpwm0.timer[0].mode.start        = 2;   // Free running
How do you ensure that the timer has already stopped (TEZ) before starting it again?

eriksl
Posts: 116
Joined: Thu Dec 14, 2023 3:23 pm
Location: Netherlands

Re: Issue with MCPWM Prescaler on ESP32-S3

Postby eriksl » Tue Oct 29, 2024 5:23 pm

BTW I think the timer scaling of the mcpwm on the esp32s3 has a bug. I will file a bug report soon. Maybe this is related, maybe not. According to a diagram in the TRM there is just one (shared) prescaler for all timers within one module (group). Rather useless I'd say, but ok. The text in the IDF documentation says there is a shared prescaler and each timer has it's own (pre)scaler. That makes more sense to me. The register description in the TRM confirms this. Now what's interesting, as soon as you create two timers within one group and the frequency is not equal, IDF driver will abort. Even though the difference could be easily resolved by the independent scaler...

Who is online

Users browsing this forum: No registered users and 86 guests