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.
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.