mcpwm_set_frequency() equivalent for esp-idf v5.0
mcpwm_set_frequency() equivalent for esp-idf v5.0
Hello Community,
Does anyone have a working example of how to update the PWM frequency using the new mcpwm driver in IDF v5.0? This was simple in v4.4 using the provided mpcwm_set_frequency() function, however in IDF v5.0, mcpwm_set_frequency was removed. According to the migration documentation from https://docs.espressif.com/projects/esp ... erals.html
"mcpwm_set_frequency: PWM frequency is determined by mcpwm_timer_config_t::resolution_hz, mcpwm_timer_config_t::count_mode and mcpwm_timer_config_t::period_ticks."
It's not clear what the steps are to actually change the frequency of the PWM while maintaining for example a steady 50% duty cycle.
Does anyone have a working example of how to update the PWM frequency using the new mcpwm driver in IDF v5.0? This was simple in v4.4 using the provided mpcwm_set_frequency() function, however in IDF v5.0, mcpwm_set_frequency was removed. According to the migration documentation from https://docs.espressif.com/projects/esp ... erals.html
"mcpwm_set_frequency: PWM frequency is determined by mcpwm_timer_config_t::resolution_hz, mcpwm_timer_config_t::count_mode and mcpwm_timer_config_t::period_ticks."
It's not clear what the steps are to actually change the frequency of the PWM while maintaining for example a steady 50% duty cycle.
Re: mcpwm_set_frequency() equivalent for esp-idf v5.0
have you looked at any of the examples here ?
https://github.com/espressif/esp-idf/tr ... rals/mcpwm
https://github.com/espressif/esp-idf/tr ... rals/mcpwm
Re: mcpwm_set_frequency() equivalent for esp-idf v5.0
Yes, thanks for the suggestion. I did look through all of those and ran the mcpwm_servo_control on my ESP32-S3 to generate a PWM signal. The mcpwm_bldc_speed_control is almost what I need except it modulates duty cycle to control speed and I need to modulate frequency. I know there has to be a simple way to dynamically update the frequency of the PWM signal like while a stepper motor is stepping, but I'm just not finding enough of a clue in these examples and don't know enough about the v5.0 implementation of PWM control. I understand how the comparator is used to change duty cycle for a constant frequency PWM output, but then how do you change the period_ticks of the mcpwm_timer?
-
- Posts: 290
- Joined: Wed Sep 05, 2018 6:23 am
Re: mcpwm_set_frequency() equivalent for esp-idf v5.0
Thanks for reporting. Yes, we will provide an API to change the period dynamically.
Re: mcpwm_set_frequency() equivalent for esp-idf v5.0
That would be awesome, thank you!
-
- Posts: 290
- Joined: Wed Sep 05, 2018 6:23 am
Re: mcpwm_set_frequency() equivalent for esp-idf v5.0
New API available on the master branch now: https://github.com/espressif/esp-idf/co ... 2bfd341a70
We will backport that API to release/v5.0 and release/v5.1 as well.
We will backport that API to release/v5.0 and release/v5.1 as well.
Re: mcpwm_set_frequency() equivalent for esp-idf v5.0
awesome, will check it out, thank you!
Re: mcpwm_set_frequency() equivalent for esp-idf v5.0
@esp_morris
Was this also backported to 5.1?
Thanks!
Was this also backported to 5.1?
Thanks!
Re: mcpwm_set_frequency() equivalent for esp-idf v5.0
Whether API has been added, I found that the programming guide of 5.2.1 still does not mention setting (or adjusting) PWM operating frequency. Also, how to set up two sets of MCPWM in version 5?ESP_morris wrote: ↑Wed Oct 11, 2023 8:10 amThanks for reporting. Yes, we will provide an API to change the period dynamically.
Re: mcpwm_set_frequency() equivalent for esp-idf v5.0
Version 5 of MCPWM is much more complex than version 4. Version 5 introduces a series of concepts including generators and comparators. resolution_hz should be the granularity of the specified timer and period_ticks/resolution_hz should be the PWM period.ChrisP_SD wrote: ↑Fri Sep 22, 2023 4:59 amHello Community,
Does anyone have a working example of how to update the PWM frequency using the new mcpwm driver in IDF v5.0? This was simple in v4.4 using the provided mpcwm_set_frequency() function, however in IDF v5.0, mcpwm_set_frequency was removed. According to the migration documentation from https://docs.espressif.com/projects/esp ... erals.html
"mcpwm_set_frequency: PWM frequency is determined by mcpwm_timer_config_t::resolution_hz, mcpwm_timer_config_t::count_mode and mcpwm_timer_config_t::period_ticks."
It's not clear what the steps are to actually change the frequency of the PWM while maintaining for example a steady 50% duty cycle.
As for whether period_tick is related to the set duty cycle, I don't understand it yet (and this process also needs to generate mcpwm_comparator_set_compare_value through comparator comparison value, and the input value is a uint32_t volume value. Simple guess period_tick can be understood as the graininess in PWM period, and the duty cycle of 50% should be period_tick*0.5). The new MCPWM is too hard to learn.
I looked at LEDC examples, and if you don't mind, LEDC can actually meet your needs.
Who is online
Users browsing this forum: alifepretend and 151 guests