-
Notifications
You must be signed in to change notification settings - Fork 242
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
PWM get_max_duty() off by one #735
Comments
Makes sense to me |
|
I don't think this can be fixed by modifying |
Really fixing As this is not a soundness issue, it should be sufficient to document that 0xffff would prevent the hardware from generating a true 100% duty cycle. However, the default value should be changed to 0xfffe. That's what I implemented in #744. |
On the RP2040, the maximum duty cycle is TOP+1, equivalent to 100%:
However, currently
get_max_duty()
returns the TOP value.Fixing this is not as easy as just changing
self.regs.read_top()
toself.regs.read_top() + 1
inget_max_duty()
, as both CC and TOP are 16 bit values. So if TOP is0xffff
, the max CC value is still0xffff
and not0x10000
, and it is not possible to configure full 100% duty cycle.The most sensible solution out of this conflict could be to just limit the TOP value to
0xfffe
inset_top()
. (This would also change the default initialization value in the same way.)Other alternatives are:
0xffff.min(self.regs.read_top() + 1)
fromget_max_duty()
. Which would mean that we can't implement embedded-hal'smax_duty_cycle()
fully correctly, because it's defined to return the value equivalent to 100% duty cycle, and that value doesn't exist if top is0xffff
.0x10000
asmax_duty_cycle()
and implement a special case for that value inset_duty_cycle()
, overriding the output pin state manually. (This could be difficult and messy.)The text was updated successfully, but these errors were encountered: