Skip to content

potential dc period initializing order issue when pwmX exist #26

@mj2068

Description

@mj2068

self._duty_cycle = 0
self._hz = hz
if not self.is_overlay_loaded():
raise HardwarePWMException(
"Need to add 'dtoverlay=pwm-2chan' to /boot/config.txt and reboot"
)
if not self.is_export_writable():
raise HardwarePWMException(f"Need write access to files in '{self.chippath}'")
if not self.does_pwmX_exists():
self.create_pwmX()
self.__init_frequency(self._hz) # set this first before DC
self.__init_dc(self._duty_cycle)

hi, here's something that i've found, not sure how of an edge case this counts but, if pwmX folder exists and duty_cycle also has a value(could happen if stop() wasn't called previously), then __init_frequency(...), __init_dc(...) sequence could fail for certain init hz. Because __init_frequency(...) runs first, it calculates a period nanoseconds using hz and writes to period, this could trigger one of the "Invalid argument" conditions, if the period is greater than that existing duty cycle.

i tested it, verified what i just described, and i think the order should be first __init_dc to 0, then __init_frequency, but the author specifically commented it should __init_dc first, so that throws me off... maybe something i don't see.

if you could confirm this is valid i can pr and fix it if needed.

thx.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions