Skip to content

Conversation

@codepainters
Copy link
Contributor

Summary

This PR fixes off-by-one issue in TC/TCC get_max_duty() function, for details see #911.

Change verified with Adafruit ItsiBitsy M4 and Sparkfun ATSAMD21G Mini boards.

@jbeaurivage jbeaurivage linked an issue Nov 18, 2025 that may be closed by this pull request
@jbeaurivage
Copy link
Contributor

Thanks @codepainters. However I would suggest, if we want the functions to keep returning u16s, to use saturating_add() instead of the regular + operator to cover the case where CC == u16::MAX. What do you think?

@codepainters
Copy link
Contributor Author

Hmm, fair point. Actually it's quite interesting what the chip actually do if 0 is used as a duty cycle value, let me check the datasheet (and perhaps the hardware).

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

Successfully merging this pull request may close these issues.

TccPwm::get_max_duty() is -1 too small

2 participants