Measure Frequency using STM32F4Started by 5 years ago●4 replies●latest reply 5 years ago●1142 views
- Input Capture : Using timer in input capture mode and measuring the width of one cycle.
- By configuring the timer to count up on external event (which in this case will be the QCM sensor itself) and hence counting the pulses.
My Question is: Which method is better? Are there any advantages/disadvantages of one over the other?
Note: The QCM sensor I am using has a known base Frequency of 6MHz and since the purpose is to analyze the variations in frequency, I believe the precision does matter in my application. Kindly suggest me some good techniques for that as well.
As to method: counting sensor pulses with a fixed interval for sample freq will work better than a free running counter with the sensor as sample freq. Unless your uC has a Really fast counter, the 6MHz of the sensor won't have many counts per sample = Lots of jitter error.
Then it's a matter of accuracy vs sample frequency: 1 sample count per second will be more accurate than 1000. Also, at 6MHz a prescale divider may be warranted. Two divide by 10 stages still yields 60KHz to the uC.
I'd start with writing the sample processing code. You're sampling the sensor for some purpose. Whatever that program execution time is will be the upper bound of sampling frequency, for contiguous sample processing. Initially set a slow sample freq, then when processing code is running well, ramp up the samples per second until system response time is acceptable.
Just considerations given the few details. Good Hunting <<<)))
@CustomSarge Thank you for your time. The QCM (Quartz Crystal Microbane) is just like any other crystal which gives out pulses of 6MHz. Also, I can run the uC timers at frequencies as high as 168 MHz. Would you still prefer sampling over counting the pulses? If so, could you please explain why?
Hmmm, so the sensor issues pulses of N cycles of 6MHz? Totally different situ, warranting a demodulator for 1 pulse per burst.
The whole "count pulses across time vs count time across pulses" is based on the profile of the signal. For pulse freq much greater than counter speed, count pulses in a fixed time frame. For counter freq much greater than pulse freq, use count with the pulses being the frame. It comes down to resolution, more "counts" per event = higher accuracy. Required samples per unit time is the other factor, setting an upper bound to either method.
You don't really mention whether you're looking for jitter in the base 6MHz (ie jitter between pulse widths but an overall accurate 6MHz) or drift (ie little jitter but not quite 6Mhz). In general input capture would be more useful for determining the former, and external event counting for the latter. In either case CustomSarge also correctly notes the best method also depends on the profile of the signal and the ratio of the two clocks.