Accurate PWM frequency for SAMD21#23
Merged
Merged
Conversation
added 2 commits
July 11, 2020 17:27
that the API implies. For SAMD51, which doesn't have any spare bits, don't try to adjust the period.
Author
|
Two more notes about the commit:
|
Member
|
Thanks for you PR, I'll test it and then merge your PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I ran into some issues trying to generate a 50 Hz PWM signal to drive an SG90 servo motor from a Seeeduino XIAO using an ATSAMD21. No matter what I tried I always ended up with a 733 Hz (48Mhz / 0xFFFF period counter). When I dug into the code it looked like the prescaler register wasn't being set and the PER register wasn't being leveraged to get an accurate frequency. This code resolves this issue and also addresses a couple of bugs that I encountered in the prescaler calculation. I tried to keep the code sane for the SAMD51, but to be honest I didn't have a dev board to test against. With these changes, I was able to generate and measure (using a USB logic analyzer) accurate PWM frequencies from 1Hz up to 46.8Khz (the max frequency attainable while preserving 10 bit resolution).