Summary of A Little More Serious Frequency Meter using ATtiny2313 microcontroller
This article details a high-resolution frequency meter design using AVR microcontrollers, offering single-chip (5 MHz and 10 MHz) and multi-chip (30 MHz) configurations with 9.5-digit resolution. The project utilizes specific chips like the AT90S2313 and ATtiny2313, external prescalers for extended range, and an LCD display for output. It supports multiple timebases and counting modes via ASCII commands or push-buttons.
Parts used in the Frequency Meter Project:
- AT90S2313-10 microcontroller
- ATtiny2313-20 microcontroller
- 5 volt regulator
- 74HC4060 prescaler
- 74HC02 quad NOR gate
- LCD display connector
- In-System Programming connector
- Power connector
- X10 or X100 prescaler (for single-chip versions)
Downloads
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.
Overview
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.
To summarize:
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
- What is the maximum input frequency for the multi-chip configuration?
The specified maximum input frequency is 30 MHz, though it can work at higher frequencies depending on the chips and layout. - Can I use the ATtiny2313 for the 10 MHz single-chip version?
Yes, the 10 MHz single-chip version uses the ATtiny2313 clocked at 20 MHz. - How do I switch between operating modes on the device?
You switch modes by sending any ASCII character to cycle through the available time bases or counting mode. - What does the ASCII "R" command do in counting mode?
In counting mode, ASCII "R" causes the counter to reset to zero. - Does the binary-to-BCD conversion limit the display size?
Yes, the 32-bit wide conversion limits the largest displayed number to 4,294,967.295 before overflowing. - What happens when the counter exceeds 32 bits?
An overflow indicator in the form of a plus sign (+) appears immediately to the right of the right-most digit. - Are there different timebase options for the 30 MHz version compared to the 5 MHz version?
Yes, the 30 MHz version includes a 0.1 second timebase, while the 5 MHz version only has 1, 10, and 100 second timebases. - How long does it take for the counter to overflow at 5 MHz?
At 5 MHz, it takes nearly 15 minutes for the counter to overflow.

