Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

pwmFrequency int division vs float division #103

@mgeorgiadis

Description

@mgeorgiadis

Hi,

In the PWM module, I've been having some slight issues with the pwmFrequency command. Each time I change the frequency using pwmFrequency, the duty cycle keeps getting set to 0. I took the liberty of inserting some print statements into the source code and found that in line 65 of pwm.py, the duty_percent is calculated with:
duty_percent = old_duty_ns / old_period_ns
Both of those numbers are integers (in nanoseconds) and in python2 this will return an integer result. Since this result is a fraction, it gets set to 0 (confirmed by printing the duty percent). I found that replacing line 65 with:
duty_percent = float(old_duty_ns) / float(old_period_ns)
solved the problem for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions