Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pwmFrequency int division vs float division #103

Open
mgeorgiadis opened this issue Aug 1, 2016 · 0 comments
Open

pwmFrequency int division vs float division #103

mgeorgiadis opened this issue Aug 1, 2016 · 0 comments

Comments

@mgeorgiadis
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant