EmbeddedRelated.com
Forums

Measure Frequency using STM32F4

Started by theAasifShah 6 years ago4 replieslatest reply 6 years ago1231 views
I want to measure the frequency of QCM sensor and monitor its variation over a certain period of time. For this purpose I am currently using STM32f4 Discovery board. I know that there are two methods by which frequency can be measured using a microcontroller:
  1. Input Capture : Using timer in input capture mode and measuring the width of one cycle.
  2. 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. 
TIA

[ - ]
Reply by CustomSargeJuly 21, 2018

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 <<<)))

[ - ]
Reply by theAasifShahJuly 21, 2018

@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?

[ - ]
Reply by CustomSargeJuly 21, 2018

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.

[ - ]
Reply by Bob11July 21, 2018

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.