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
[TW#15817] MCPWM hardcoded resolution (IDFGH-2398) #1101
Comments
…tead of 1 MHz In our application we want to generate signal behaving like Oneshot125 where 125 us (1000 ticks) is minimum pulse and 250 us (2000 ticks) maximum Fix requested at espressif#1101
Hello michprev, |
Hello @panfeng-espressif, I would like to use up to 32 kHz frequency with 2048 output values (if possible). However, if noone else ever faced this problem I think that there is no need to change MCPWM API - I can make my own MCPWM driver. I think that it is a good idea to include something like "max_output_values = 1000000 / frequency" in the docs, though. |
Maybe you could use mcpwm_set_duty instead. In this way, you need to input a percentage to control the duty. |
Yes but this does not change number of the output values. It sets timer compare values to a percentage of the timer period which is defined at esp-idf/components/driver/mcpwm.c Line 143 in 165e3ed
With 2 kHz frequency there are still 500 different output values. |
You can set percentage from 0.1% to 99.9%. So it's up to 1000 different output values. |
I don't think that you are right. Please consider following code:
If you insert esp-idf/components/driver/mcpwm.c Line 165 in 165e3ed
the result is:
As you can see every second value is the same as the previous one so that there are only 500 output values. |
Yes, you are right. |
I'd like to second this! It's better not to have a driver for the MCPWM peripheral at all than to include one that is unsuitable for most applications the underlying peripheral is actually capable of. I don't know that there is a simple way to make this sort thing into a tidy user-friendly API and for the most part you wouldn't even want to bother given that in most such applications you will also want to update the underlying peripheral registers from the PWM ISR (e.g. set the duty cycle for the next PWM period by advancing an index in a waveform lookup table) and most of the MCPWM API functions are not ISR safe (they either live in a far flung region that is not feasible to relink into fast RAM or try to take locks). The driver is useful as example code -- a reference for the minimum set of registers one must touch to kick it off (especially non-obvious ones like clock gates and the like which are not always clearly cross-referenced with the peripheral registers) but god help you if you actually try and use the driver in a real motor/power control application (!). |
@drenehtsral Agree with you that it's really hard to provide one single set of APIs in such flexible and various application scenarios. In most real-time applications, user would be able to apply their own implementation via register access. |
Hello,
according to 'ESP32 Technical Reference Manual' MCPWM uses 16-bit counter with 8-bit clock prescaler. In 'mcpwm_set_duty_in_us' we set compare value to duty time in microseconds so that MCPWM timer tick frequency is always 1 MHz no matter what frequency we set in 'mcpwm_set_frequency'. Am I right?
In this case we do not get 16-bit PWM resolution, e. g. when we set frequency to 2 kHz (period 500 us) we can get only 500 different values.
EDIT: We need to make MCPWM_CLK_PRESCL and TIMER_CLK_PRESCALE configurable
The text was updated successfully, but these errors were encountered: