fixed imprecisse timing on SAMD21 (Arduino Zero) #21
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.
fixed #20
I had a deeper look in your code and find the reason and a solution.
During reading your code I also find a few points which I tried to enhance. And I add some github actions.
Finally, I found the bug.
Using the test scripts provided in #20 leads with the code from this pull request to:
The calculation of the base delay was rounded. But it is not necessary to calculate with these rounded values. Using the precise values may enhance the result.
Some of the floating point calculation can be done as integer calculation without any need for rounding. This should enhance precision.
Using
TC_CTRLA_WAVEGEN_MFRQ
instead ofTC_CTRLA_WAVEGEN_NFRQ
makes setting_TC->COUNT.reg = 0;
unnecessary and fixed the imprecise timing.