Skip to content
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

applet.interface.freq_counter: implement basic frequency counter #218

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

attie
Copy link
Member

@attie attie commented Oct 18, 2020

As discussed in #glasgow, this PR will implement a basic frequency counter, based on a ripple counter, paired with using the Glasgow's clock as a time reference.

This commit is work-in-progress:

  • Create FrequencytCounterInterface class
  • Add duration command line argument - longer run offers higher resolution
  • Clean up output
  • Present measurement precision / error in output (as calculated below)

NOTE: This PR differs from #216 - that is providing more complex (but still basic) signal analysis, while this provides a pure frequency / edge counter.

@attie
Copy link
Member Author

attie commented Oct 18, 2020

re aliasing:

With a ~44.1kHz input, we'll typically see one of the following two outputs over a 131072 clock period (@48MHz = 2.73ms).
1 LSB = ~366.211Hz.

edge_count=120
signal_freq=43945.312
edge_count=121
signal_freq=44311.523

I've thought about this a little more... the resolution of the output is the sample period (or its frequency).

  • Above, the sample period / frequency is 48e6 Hz / 131072 = 366.21 Hz, therefore 1 LSB = 366.21 Hz, or ~2.73066ms
  • Extending the sample period to 0.5 seconds produces a resolution of 1 / 0.5 sec = 2 Hz
  • Extending the sample period to 1 second produces a resolution of 1 / 1 sec = 1 Hz
  • Extending the sample period to 2 seconds produces a resolution of 1 / 2 sec = 0.5 Hz

From here we get diminishing returns, so I think I'll set the default duration to 2 seconds, for a 0.5 Hz resolution. I might also present the resolution or error for the measurement in the output.

@whitequark
Copy link
Member

re aliasing:

The ripple counter's length is essentially unlimited, right? (Limited only by FPGA size.) So you can make something obscenely large, like a 32 bit counter, and run it for a second or even several seconds. That's like averaging you suggested on IRC but with less work.

@attie
Copy link
Member Author

attie commented Oct 18, 2020

Yes, correct. I'm planning to make the sample period configurable at runtime, but with a default of 1-2 seconds to help improve this.

@attie attie force-pushed the ripple-counter branch 6 times, most recently from 48a781f to 46d9214 Compare October 19, 2020 15:20
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.

3 participants