Frequency meter with some of quite good performance, capable of measuring frequencies from 1Hz to 10MHz (9,999,999 Hz) with a resolution of 1 Hz over the entire range. Ideal for function generators or as a standalone meter. It is cheap and easy to make, with parts that can be bought anywhere, and with a small size that allow it to be mounted in the panel on any device (Figure 1).
Figure 1. | AVR frequency meter - from 1Hz to 10MHz |
The circuit consists of seven 7-segment displays, Atmel AVR ATtiny2313 uController, and a few transistors and resistors (Figure 2). AVR does all the work and other ICs are not needed here. Its work is simple, AVR counts pulses on the input given at the time of 1 second and displays the result. The most important thing is very accurate time base, and this is handled by 16-bit Timer1 in CTC mode. The second, 8-bit timer counter operates as Counter0 and it counts pulses given to its input, the T0 pin. Every 256 pulses it causes the interruption, where program increases the multiplier. When we receive the 1 second interrupt , the content of this multiplier is multiplied by 256 (shifted left by 8 bits). The rest of the pulses that counter got, are written down and added to the result of the multiplication. This value is then broken into single digits that can be displayed each on a single display. After that, just before leaving the 1 second interrupt, both counters are reset at the same time and the measurement starts again. AVR in his spare time is multiplexing 7 displays. More details in the source code that I put in the attachment.
Figure 2. | AVR frequency meter Schematic Diagram |
Resolution vs accuracy
Accuracy depends on the clock source with which meter is fed. The code itself can occasionally add one pulse at very high frequencies, but it is almost negligible. Crystal, which we use, should be of good quality, and have small as possible ppm (tolerance). It is best if the frequency is divisible by 1024, for example, 16MHz or 22.1184MHz. For get the measurement up to 10MHz, use 21MHz or more crystal, for example, previously mentioned 22.1184MHz. The meter can measure the frequency up to about 47% of its own crystal, so for 20MHz we get a bit below 10MHz, for 16MHz we get a bit below 8MHz measurment – so 22.1184MHz crystal will be perfect for this and its worth to buy. Unfortunately, it is not very popular, and if you find it, it will have a tolerance of 10 to 100 ppm which is not suitable for any accurate measurements. If we have another device to measure the exact frequency (eg oscilloscope with hardware measurement), we can calibrate our circuit by adding a little trimming – (cap pot) (about 1p-10p) to one of the legs of crystal and to ground, and tune the frequency of the oscillation in such a way to get same measurement as on the oscilloscope (Figure 3). If you can not do that, you should to get a small as possible ppm crystal, crystal generator, or simply assume that crystal will work exactly at frequency that is given by the manufacturer.
Figure 3. | Resolution vs accuracy of AVR frequency meter |
Attachment provides a few compiled codes for few different crystals, but you can compile it for your own. In Crystal type in the crystal frequency, in Compare type in the result of dividing this frequency by 1024, (do not type the rest after the comma, if crystal is not divisible by 1024).
Wave
Basically, you can put anything from 0-5V into the input, not just a rectangle. Circuit counts sine or triangle as well, counting is done during the falling edge at the 0.8V. Please note that the input is not protected in any way from higher voltages. Input is not pulled up to VCC, it is a high impedance input so it will not load the measured circuit – you should be even able to measure the mains frequency by touching the input pin with your finger :) Meter measurement can be extended up to 100MHz with 10Hz step, by adding appropriate high-speed frequency divider to input.
Display
Seven 7-segment multiplexed displays with common anode (common plus). If the brightness is too low, you can change the current limiting resistors of the segments to the stronger ones, but remember to not exceed 40mA impulse current for each pin of the microcontroller. Displays have also their current limit, so you should check it. By default, these resistors are 100ohm. Unneeded displays, f.e. those displaying zero’s, are blanked out in order to make reading more comfortable. For example, the value of “0.000.980″ will result with “980″ – dot points are also blanked out. Measurement is refreshed every each second, because the time base is 1 second.
PCB
Double-sided PCB with dimensions of 109mm × 23mm – unfortunately the seventh display does not fit in the free version of Eagle so its drawn from the hand. Three wire connections should be made on the PCB, the first one on the top side of the board, connect power to the VCC pin of the processor – this connection is shown on the silkscreen layer. Two more connections are the displays dots points that should be connected to 330ohm resistor located on the bottom side of the board (Figure 4, 5, 6). At the top of the PCB, Atmel ISP-6 edge connector pads are placed, looking from the top, pin no.1 is the first one from crystal side. No need to solder the connector permanently, or even do not solder it at all, you can program the chip in your own way. Displays must be mounted at some distance from the PCB, so you be able to hand solder the top surface pads (4 pads for each display). The project itself does not provide mounting pads for mentioned before cap trimmer, if needed, solder it on your own, for example see the pictures. PCB on the pictures is different from the one from the attachment, this is the first version 1.0 which was assumed to make only 1MHz measurement.
Figure 4. | Seven 7-segment multiplexed displays with common anode mounted on PCB |
Figure 5. | Attiny2313 microcontroller, ISP-6 connector and wire connections |
Figure 6. | AVR frequency meter: Bottom side of the PCB |
Doawnloads
Source file and compiled code version 1.1; Eagle 6.4.0 project files and PDF’s version 1.1 - download