-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add frequencyio.FrequencyIn #1614
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! In the long run maybe the DPLL1 stuff might be factored out into samd-peripherals, in case other code wants to do similar stuff, but it's fine for now. This has been a long road, but it's also been tested a lot as a result.
Yeah, that is totally doable I think. I can work that soon. |
Its time again to try and get this in. Updates since #1144:
Instead of putting this in
pulseio
, this creates a newfrequencyio
to better manage inclusion/exclusion. Most of the smaller builds (M0 basic, CPX, etc) were exceeding flash size.Now uses a single "reference TC" for interrupts/results calculation, and "capture TCs" for frequency sensing. This keeps the interrupts from flooding the MCU, but does eliminate 1 timer available for capture. I've had up to 2MHz input detected with no detrimental effects to the VM, USB, or REPL.
Since the "capture TCs" now use a simple count-of-events based on a time period, I added a
capture_period
property. Notes about this are in the documentation. There is some math-assumption built in to the frequency calculation, since the reference TC will not catch the time periods exactly.I'm getting a variance of 10% maximum on readings. Using a sample average has proven the best way to smooth this out. Here are some example Mu screenshots with a 2KHz signal:
To anyone testing/reviewing: please, don't be gentle with it! Break it. Criticize (constructively)! All of that is appreciated on my end. 😄
NOTE: I have left the previous SAMD21 code in, even though it isn't included by default. I still need to go back through and test it with a custom build, but I would like to leave it as an available option.