Hello Joe,
The timers used in Freescale MCUs, such as the HC908QY4, are not really suited to direct frequency measurement in the tens of MHz region. The timers are more suited to period measurement, using the input capture facility, but this has limitations for high frequency signals.
I have done some rough calculations for the period measurement process. To measure the period of a high frequency signal, you will need to use an external prescaler, probably of 16 bit length. This would mean you would be measuring the duration of 65536 input periods. However, to achieve 1kHz resolution for an input frequency of 30 MHz, the bus rate would need to be 16 MHz, or above - well outside the capabilities of the device you intended using. For a bus frequency of 3.2 MHz, and a prescale factor of 1, the resolution at the highest frequency would amount to about 4kHz.
As the input frequency decreases, the resolution will increase, but eventually the timer will overflow more than once during each period measurement (i.e. the measurement period will exceed the timer overflow period), with additional complication for the measurement process. When this occurs, the simplest approach is probably to dynamically increase the timer prescale value until multiple overflows cease.
Ultimately, you would need to calculate the frequency as the reciprocal of the period, scaling and sequencing the calculations so that integer operations can be used throughout, without loss of precision.
To implement direct frequency measurement, i.e. directly counting the input cycles, the MCU would require the following characteristics -
- A timer with an external clock pin is required for the measurement signal. Many HC08s do have this, but not the QY4 device.
- A second, independent timer module is required to provide the gating interval for the frequency measurement. Generally, only the the higher end devices have more than one timer module (not to be confused with the number of timer channels).
- A further restriction is that the external applied frequency must not exceed the bus frequency. Therefore, it is likely you would need an external divide by four prescaler.
- At the input to the external prescaler, two gates will be required, one for the gating period of the measurement, and the other for determining the count within the prescalers, both external and internal. Since the prescale value cannot be directly read, the value is determined by the firmware applying pulses until the timer register changes state. The second gate is used for this purpose.
Incidently, the Microchip PIC devices can readily handle direct frequency counting up to 50MHz, requiring only the two external gates. The prescaler will accept input frequencies of 50MHz, irrespective of the MCU clock frequency. I actually have a frequency counter that uses the 16F84A device in this manner, that was constructed from a kit.
Regards,
Mac