Skip to content

PWM driver turns off pin if off time is 0 in set_values #1955

@zephyrbot

Description

@zephyrbot

Reported by Geoff Gustafson:

If you try to set a PWM to on or off all the time (with off = 0 or on = 0), in both cases the driver will see it as an error in __set_one_port() and silently turn off the pin entirely. For the "on = 0" case, this is great - this is exactly what you want. But for the "off = 0" case, this is exactly the opposite of what you want. Now, it seems the PWM can't be set to fully on, so the "best" solution is to change the pin to GPIO mode and set it high. But that may be impractical because it would presumably require including the GPIO module as well.

In any case, the documentation for the pwm_pin_set_values() function currently says nothing about this border case.

Another option may be that this function shouldn't just fail silently but rather report an error. But it strikes me that in the case of an accidental call to this function with "off = 0", it would be better to just leave the PWM in whatever state it was previously in.

But I think the best solutions are either:

  1. Leave the PWM at its previous settings
  2. Set the off time to 1 cycle and decrease on time by 1 cycle to keep the period the same

I've attached a patch with solution #1 for DW and QMSI. Not sure if the problem exists in other drivers; they are different.

(Imported from Jira ZEP-401)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: PWMPulse Width ModulationbugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions