# Calculating frequencies based on cycle counts

Discussion in 'General Electronics' started by Calum MacLean, Dec 8, 2004.

1. ### Calum MacLeanGuest

Hi

I hope I'm mailing this to the right group.

My company has a piece of hardware which, among other things, is intended to
provide measurements of the frequency of a clock signal (typically a few
MHz).
To do this, it will measure the number of rising clock edges in a period of,
say, 10us (which time period is measured using a system clock running at a
higher frequency - say 100MHz or so).
So, we will end up with the number of rising clock edges in every 10us, and
from this the clock frequency is to be calculated. The aim is also to track
the frequency as it changes over time.

My question is, what is the best way to calculate the clock frequency at a
particular point? Are there standard statistical/numerical methods which
can be used for this?

Obviously, you can get a rough measurement of the frequency over a short
time - the 10us. And you can get a more precise measurement over a longer
period of time, but then the time resolution is not very accurate.

Are there techniques which can be used to calculate a value, with an error
range, for the frequency at any point in time?
So you could plot the frequency against time, with a given error.

Note also that there would also be an error in the system clock measuring
the 10us period, so this would also have to be taken into account.

I'd note that I'm neither a hardware engineer, nor a mathematician, so I
hope what I've described above makes sense.

Calum

2. ### MGGuest

You describe basically two methods. One is to measure the period of the
unknown signal by counting how many of the reference clock periods fit
between two consecutive raising edges. Clearly this is the fastest update
time, you can not know the frequency in less than one period, at least in a
practical way. If you were using a 1MHz reference to measure a ~10us period
you would have a 1uS resolution. You could count 9 cycles in a 9.99uS signal
or count 10 cycles in a 10.01uS signal.
practical same signal but two differenr results. So the error would be
roughly 10% plus the uncertainty of the reference.

Using a higher frequency reference will give better resolution, 100MHz will
get you a 0.1% max error.
This method let you know the changes of frequency that happen in every cycle
ar every other cycle if you have to stop to read the counter. The
disadvantage is that you need a fast reference clock and a fast counter.
Think of this method as clocking a counter with the reference *gated* by the
unknown signal used to start and stop the counter.

The other method reverses the situation, you use the signal to clock the
counter and use a much slower reference to gate the counter. In practice
you obtain the gating signal by dividing a suitable clock.
For example you divide your 1MHz clock by 1,000,000 and have an accurate one
second clock.
Now you allow the counter to accumulate the same 10uS signal for one second
and then stop and read the counter, let say you read 100.001 count. That
means that the unknown signal is actually running a tad faster than 10us and
you are able to appreciate that to one part in 100,000. In this case the
reference accuracy could be as good as the GPS clock.

The disadvantage here is that you have a snapshot of what is going on with
the unknown frequency only once a second.
You can tell wheter the frequency is flapping all over in that second, you

This are basic extreme examples, the reference clock or the gate time can be
changed to achieve the suitable compromise, the moral of the story is that
you must trade resolution for speed unless you are willing to use very very
high clock.
You could also duplicate the circuit and while one is counting the other is
stopped and being read. This allows to catch and neasure each period.

Hope this helps
MG  