Maximum input frequency is specified to be 30 MHz in the multi-chip configuration, and in single-chip configuration, there are both 5 MHz and 10 Mhz versions operating with 10 and 20 MHz crystals, respectively. All versions have 9 1/2 digit resolution. I have used multi-chip version at 40 Mhz, and depending upon the actual chips you use and your layout, it can work at much higher input frequencies. The 10 MHz single-chip version using the ATtiny2313 is ideal for use with a X10 or X 100 prescaler.
Download the AVRStudio assembly source for 30 MHz (AT90S2313 or Tiny2313) version: ffmtr040916A.asm
Download the AVRStudio Hex (Intel Intellec 8/MDS format) file for the 30 MHz (AT90S2313 or Tiny2313) version: ffmtr040916A.hex
Donwload the AVRStudio assembly source for the 10 MHz (ATtiny2313) single-chip version: nfmtrT050524.asm
Download the AVRStudio Hex (Intel Intellec 8/MDS format) file for the 10 MHZ single-chip (ATtiny2313) version: nfmtrT050524.hex
Download the AVRStudio assembly source for the 5 MHz single-chip AT90S2313 or ATtiny2313 version: nfmtr040916A.asm
Also see the companion Preamp and 330+ MHz prescaler.
I decided that I needed a frequency meter with higher resolution and a higher maximum frequency than the one I built a couple of years ago. The idea for this meter has been around for a while, though I’ve seen it done with a PIC, I don’t remember seeing this particular implementation with an AVR before.
As for microcontroller choice, the requirements for this firmware are that the controller be an AVR with a 16 bit counter, has a ram stack and UART or USART, and the ability to operate at 10 MHz. Some modification may be required to the code to accommodate a USART instead of a UART, a 16 bit stack pointer instead of the 8 bit pointer on the AT90S2313, and the specific controls of the 16 bit counter registers. I used an AT90S2313 because they are available to me and suitably small. For the 10 MHz input single-chip configuration, you need to use an AVR that can clock at 20 MHz. I used an ATtiny2313-20. When programming the ATtiny2313, remember to select a fuse setting for the internal clock oscillator. The AT90S2313 does not have clock fuse settings.
The first phase was to make a high resolution frequency meter/counter just using the AT90S2313 ot ATtiny2313, then to add the external prescaler. Without the prescaler, the maximum input frequency for the frequency meter is 5 MHz or 10 MHz, depending upon the chip you use and the firmware version you choose. With the multi-chip version that includes a prescaler, the maximum input frequency, according the the component specifications, is about 30 Mhz – this will vary with individual external prescaler chips and your circuit layout. To summarize, there are three versions of the code available at the top of this page: The 5 MHz single-chip version, which is basically an AT90S2313-10 clocked at 10 MHz and a serial interface, the 10 MHz single-chip versoin with is basically an ATtiny2313-20 clocked at 20 MHz with a serial interface, and the 30 MHz multi-chip version, which is the same circuit as the 5 and 10 MHz versions, but with the prescaler and quad NOR gate added. In the 30 MHz version, the maximum input frequency for the counter mode (counts until reset via ASCII command) is 5 MHz. The timebase selections between the two version differ as well. The 30 MHz version has timebases of 0.1, 1, 10,and 100 seconds. The 5 MHz version only has 1, 10, and 100 second timebases.
Design Frequency Measurement Mode Counting Mode Timebases
30 MHz 30 MHz maximum 5 MHz maximum 0.1, 1, 10, and 100 seconds
10 MHz 10 MHz maximum 10 MHz maximum 1, 10, and 100 secondds
5 MHz 5 MHz maximum 5 MHz maximum 1, 10, and 100 seconds
The multi-chip meter has five modes of operation: 0.1 second time base, 1 second ,time base 10 second ttime base 100 second ttime base and counting mode. The single-chip versions have four modes of operations: 1 second ,time base 10 second ttime base 100 second ttime base and counting mode.You switch modes by sending any ASCII character making the instrument cycle through the five modes over and over.
ASCII “R” ($52) is a special case. In the 0.1, 1, 10, and 100 second time base modes, it causes the instrument to cycle to the next mode. When in the counting mode, ASCII “R” causes the counter to reset to zero.
I added two push-buttons to one of the 2 line x 16 character LCD display boards that I built (See “Serial Interface for Truly MTC-C162DPLY-2N, 2 line X 16 char LCD display” elsewhere on this site.). One button is used to send an ASCII carriage return ($0D) and the other is used to send an ASCII “R” ($52), so they can be used to advance the operating mode, and reset the counter, when in the counting mode, respectively.
All 10 digits are shown in this 100 second measurement of a 30 MHz signal with .01 Hz resolution. The measurement drifted about 30 Hz within a few seconds from the warmth of my thumb on the 10 MHz crystal can. Do not confuse resolution with accuracy.
The binary-to-BCD conversion is 32 bits wide, so the largest number that can be displayed is 4,294,967.295. At 5 MHz, it takes nearly 15 minutes to overflow. It will not overflow in the frequency meter mode – even at 30 MHz, it takes about 143 seconds to reach this count, in excess of the longest time base available, 100 seconds. When the counter exceeds 32 bits, whether in frequency meter or counter mode, an overflow indicator displayed in the form of a plus sign (+) immediately to the right of the right-most digit.
The counter counts as long as the input signal crosses the input thresholds of the 74HC02. See the 74HC02 data sheet for your particular 74HC02 for details.
An outboard preamp/precaler, which extends the frequency measurement capabilities to beyond 300 MHz was designed after this project. Click here to see the outboard preamp/prescaler.
For more detail: A Little More Serious Frequency Meter using ATtiny2313 microcontroller