zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.61k stars 6.5k forks source link

pwm: Update PWM API for dynamic prescaler computation #6958

Open erwango opened 6 years ago

erwango commented 6 years ago

As discussed in #5469, current PWM API prevents dynamic prescaler computation.

Indeed, using get_cycles_per_sec in pin_set prevents to adjust PWM prescaler to the requested cycle duration and hence imposes to set it before compilation. Hence PWM application is limited to work in the duration range matching harcoded prescaler value.

I propose to remove function get_cycles_per_sec from API and let driver compute it internally inside pin_set. It seems this function is not used today (not in PWM tests/samples at least).

Drivers should be able to handle directly pwm_pin_set_usec.

henrikbrixandersen commented 3 years ago

This needs rethinking after introduction of the PWM capture API functions, which also use the pwm_get_cycles_per_sec() API function.

manoj153 commented 3 years ago

Is there a detection mechanism to log error that the provided period is not supported based on the base pre-scaler set value?

pszkotak commented 2 years ago

If I understand correctly with current implementation there is impossible to have e.g. LED blinking with higher period that 250ms using PWM based driver (as in https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/basic/blinky_pwm).

It limits some applications or makes a need for weird workarounds.

@carlescufi, @anangl, is it planned for development? Do you have any estimations?

Edit: Even with the proposed change limitations caused by the min PWM clock at 125kHz and max COUNTERTOP of 32767 still hold. Workarounds are needed for slow blinking use case anyway.

zephyrbot commented 7 months ago

Hi @anangl,

This issue, marked as an Enhancement, was opened a while ago and did not get any traction. Please confirm the issue is correctly assigned and re-assign it otherwise.

Please take a moment to review if the issue is still relevant to the project. If it is, please provide feedback and direction on how to move forward. If it is not, has already been addressed, is a duplicate, or is no longer relevant, please close it with a short comment explaining the reason.

@erwango you are also encouraged to help moving this issue forward by providing additional information and confirming this request/issue is still relevant to you.

Thanks!