Frequency counter?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Frequency counter?

4,542 Views
BobMac
Contributor I
Does anyone know where I might find an app note on using a 908? timer for a frequency counter?
Thanks, Bob
Labels (1)
0 Kudos
Reply
4 Replies

628 Views
bigmac
Specialist III

Hello Bob,

The basic approach taken would depend on the frequency range you wish to measure, and the resolution required.  Of course, the MCU clock would need to be crystal derived for measurement accuracy.

The HC08 timer is most suited to the measurement of period, using input capture - the frequency can then be calculated.  However, this is most suited to low frequency measurements where the input period is many bus cycles.  Resolution can be increased by measuring the total period for multiple input cycles.  To further increase the measurement frequency would require external prescaler hardware.

For direct frequency measurement of higher frequencies, you would likely need two separate timer modules (not two channels in the one timer module).  One of the timers would require external clock input for connection of the signal, and the other timer would need to generate an accurate gating period of suitable duration (say one second).  The measurement of frequencies greater than the maximum bus frequency would require additional external prescaler hardware.

These are some of the basic considerations.  What are your actual requirements?

Regards,
Mac

 

 

0 Kudos
Reply

628 Views
BobMac
Contributor I

Bobmac to Bigmac HI there!

 I wanted to impliment a low frequency (0 to 10KHz) freq. counter as part of a larger test equipment project. I'm not too worried about the accrecy at the moment because our processor is crystal controlled (an AB32) . I thought that I would bypass the "reinventing the wheel" phase of the project and learn something at the same time.

Thanks for your reply, Bob 

0 Kudos
Reply

628 Views
bigmac
Specialist III

Hello Bob,

Some further comments assuming your use of input capture facility -

If you are able to vary the prescale setting (without affecting the operation of other sections of code), you can avoid multiple timer overflows, with resultant simplification of frequency calculation.  For example, with a bus frequency of 4MHz and a prescale setting of 64, you can measure down to 1Hz without the input period exceeding the timer overflow period.

To check for multiple timer overflows (under-range), set a flag during timer overflow ISR, and clear the flag during input capture ISR.  On entry to the timer overflow ISR, if the flag is already set, the frequency is too low, or there is no input signal.

Using this technique, you could start a measurement with maximum prescale value, and then progressively reduce the value until the period reading for a single input cycle was equal or greater than a value of $8000.  This would achieve maximum resolution without the need to take overflow into account.  If a prescale value of 1 was reached, and the period reading was still below $8000, you could then continue to totalise the period of multiple input cycles until the criterion was reached.  For a frequency of 10kHz, this would occur after 82 cycles.

To calculate frequency to say 3 decimal places using integer arithmetic -

If single cycle measurement -
freq = fbus * 1000 / period / prescale;

If multiple cycle measurement -
freq = fbus * cycles * 1000 / period;  // prescale = 1

Regards,
Mac

 

 

0 Kudos
Reply

628 Views
UK_CF_FAE
NXP Employee
NXP Employee

Hi There, I'm gonna mis-spell my name as Mac so I can join this party.

You need input capture mode to make a frequency counter in the range 0 to 10kHz. At the lower frequencies, you'll get timer overflows, which will need to be handled.

Donnie's engineering bulletin EB389 should be everything you can dream of. Do a keyword search for this on our site. It even has code examples.

good luck

Mac A.K.A Mark

0 Kudos
Reply