Description
It would be nice to have the full 16 bit resolution available for the duty cycle. In my use case I am controlling a digital servo with it. I didn't want to have to add a PWM IC to the boards I am building because there would be added expense to have the PWM IC soldered onto the boards. The IC's are SMDs with some pretty small pins and doing it by hand would result in a high failure rate if I even managed to get any soldered down properly at all.
One such PWM IC is the PCA9685 and it has a 12 bit duty resolution. This allows me to turn a servo from 0° to 359° using 0.0879° increments. With the EP32 being locked to a 10 bit resolution my increments would become 0.3516° increment which is quite a large difference. if the full 16 bits were available the increments would become 0.0055° if the servo is capable of moving that small an amount. I know the ones that I am using work with 12 bit.
Adding a function or property that would allow a user to obtain what the max duty cycle is would be extremely handy to have. max_duty = (2 ** timer_cfg.duty_resolution) - 1
It would also be nice to have an additional parameter added to the set frequency and the constructor that would allow a user to set a lower duty resolution. If the parameter is not supplied then the maximum duty resolution would be used. it would be simple to add in a check to ensure that a provided duty resolution was not higher then the maximum if it is then raise an exception.
Now I am not sure if anyone has worked with a high quality digital servo at all. These things are capable of moving 60° in 0.2 seconds and sometimes faster. Without having the ledc_set_fade_with_step
, ledc_set_fade_with_time
functions exposed in some manner it becomes quite the task to throttle how fast the servo moves. Writing the code to handle that in Python does consume quite a bit of resources where I am sure using that functions would be considerably less.
I do not know how the threads work with the ESP32 and if they are "real" threads. If they are it would be helpful to also have the thread safe versions of the functions exposed or have the program automatically use a thread safe version if making a setting change that is not happening from the main thread. I would think there is a way to identify a main thread. I do not know if the non thread safe versions of functions are blocking calls or not. I would imagine the non thread safe fade functions would block until the fade completes.
The ESP32 has a whole bunch of PWM capabilities that are not exposed and it would be handy if they were. From reading the SDK and looking at the ESP32 port files I don't believe it would be hard to add the above mentioned things for someone that has worked with the backend MicroPython code. I would be willing to add the features is someone would explain how the MP_ROM_QSTR function/macro works and where the values that are passed to it is located.