<< Back

 

Cesky: , English:

FreqMeter

Precise frequency meter with ATmega8 processor (1 Hz to 50 MHz, or 1 Hz to 100 MHz)

The heart of the frequency meter is the ATmega8 processor, complemented by a 393 divider. The choice of the divider determines the achievable upper limit frequency. With the Philips Nexperia NXP 74HC393 divider, 100 MHz is achievable. The Toshiba 74VHC393FT has a stated typical cutoff frequency of 170 MHz (the meter will display a maximum of 100 MHz). I used the Texas Instruments SN74HC393N, which states a limit of 25 MHz, but worked up to 50 MHz in tests. The PCB design also depends on the divider used. The SN divider I used is in a DIL14 package. The NXP and Toshiba dividers are in SO14 packages, the PCB has to be modified to the SMD version.

Conventional meters measure frequency by counting pulses for e.g. 1 second. This method is suitable for measuring high frequencies. Another method, suitable for low frequencies, measures the interval between pulses.

This frequency meter combines both methods. It counts pulses for approximately 1 second and simultaneously measures the time interval between the first and last pulse. As a result, it is able to measure the exact frequency to the full number of valid digits over the full range of 1 Hz to 100 MHz.

Note: Click to enlarge the images on the page

Circuit diagram and measurement method

In the schematic it is in place of the ATmega8 processor. I used a stock ATmega8L which is designed for low voltages and low frequencies, but even at 5V with 16 MHz it worked fine. A 393 divider is used at the meter input. The choice of divider depends on the achievable upper cutoff frequency. With NXP 74HC393 or Toshiba 74VHC393FT the meter works up to 100 MHz. The output of the divider is routed to the NC7SB3157P6X analog multiplexer, which switches the measurement input to either direct or via the divider. Switching is handled by the processor via the PD5 output. When the frequency rises above 1 MHz, it switches the divider on, when it falls below 500 kHz, it switches the divider off. In the absence of a signal, the processor turns the divider on and off experimentally. The PD6 output resets the prescaler.

The signal is fed from the multiplexer to both input T0 (PD4) and ICP (PB0). Input T0 is the input of Timer0. The 8-bit Timer0 counter counts the pulses arriving at input T0. On overflow, the software increments the pulse counter by 256. The ICP input is the Timer1 input. The 16-bit Timer1 counter takes care of accurate timing. When the counter overflows, the higher word of the timer counter is incremented.

The frequency measurement is done by recording timestamps. The counters keep running, i.e. Timer0 counter counts pulses and Timer1 counter counts time. Roughly every second a time stamp is taken - the state of the time counter from Timer1 and the number of pulses from Timer0. The timestamp instant is synchronized by an edge on the ICP input. The exact frequency and period of the pulse is then calculated from the time increment and the pulse count increment. The length of the measurement period is determined by the Timer2 counter, which counts the elapsed time in us.

A more detailed description of the measurement method can be found on this page.

The meter is powered from a 9V AC power supply with a rectifier bridge and stabilizer. The stabilizer requires cooling. It would be preferable to change the power supply to a USB connector without a stabilizer and power the meter from a regular USB charger.

A two-row LCD display (2x16 characters), operating in 4-bit mode, is connected to the processor. LCD two-line displays tend to be electrically compatible (usually compatibility with the Hitachi HD44780 controller is maintained), but there are differences with the pinout. Therefore, be careful with other displays - you may have pins 15 and 16 (swapped LED- and LED+) differently against the schematic!

The meter input is treated with a decoupling capacitor and a branch of resistors to set the operating point close to the tipping level. This provides higher sensitivity than would correspond to TTL levels. It's not the best solution, I recommend considering another option. For weak signals the sensitivity may be small, for jammed signals it may be large, a hysteresis amplifier would be useful. For example, the output of a PWM modulated generator is modulated at a higher frequency and this results in the meter measuring partly the carrier frequency (at a voltage around 0) and so the measurement result is distorted. Sometimes the high input impedance can be a problem, when the measurement is distorted by the industrial interference oscillations that catch the unshielded conductors (manifested by a higher indicated frequency). The correct solution would probably be a hysteresis input with automatic sensitivity control.

Click on the image to enlarge...

Surface connection and mounting

The PCB is designed as a single-sided connection with several wire jumpers.

The power supply is 9V AC power supply (from an old modem), bridge rectifier and 7805 stabilizer. The stabilizer requires a heat sink. To fit under the display, I had to bend the fins of the heatsink. If you use a USB power supply (from a +5V USB charger), you eliminate the need for the rectifier and heatsink.

A series of pins are soldered to the display and it plugs into a connector in the PCB. I very much prefer the connector solution to a wired cable connection - much easier to handle and you can swap displays easily. The difficulty you may have is with the choice of display. Electrically, the displays tend to be compatible (the controller is compatible with the Hitachi HD44780), but the pinouts may differ. The display I used has a pin layout that most closely matches the WINSTAR WH1602A-YGH-ET display - which means: the pins are located on the bottom left, in the order 14 (=DB7) ... 1 (=Vss), 16 (=K LED-), 15 (=A LED+). While you can use a different display (may even work out cheaper), you may need to change the pins on the PCB, such as reversing the pin order and moving them up, i.e. you need to enlarge the PCB.

Before assembling, check how the electronics will fit in the box in portrait mode. I used a box similar to the KM78 box, only a few millimetres taller. You may need to skimp on the height of the connector for the LCD (choose a lower connector) and consider whether you can fit a possible heatsink stabilizer and power connector in there (possibly tuck the lid of the box to create more space).

I recommend you solder the power circuits first and check the supply voltage. After the other components are soldered, it is hard to find power supply errors or even some circuits may be damaged.

I recommend placing the 393 circuit in the socket to make it easy to change when looking for the circuit with the highest cutoff frequency. However, if you use the NXP 74HX393 or Toshiba 74VHC393FT, you must modify the connection from the DIL14 socket to SO14.

Bottom side (connection side):

Fitting of components:

The board is attached to the bottom of the box with 2 screws (you can use the KM78 box, but you may need to use a lower connector for the LCD and a lower heatsink for the stabilizer). I recommend screwing more spacers into the top holes, like struts, to make the board more stable. Even better would be to prepare a PCB joint across the entire surface of the box so that it can be screwed in with the top screws, which is also a necessary modification for the display with the pins on the top left.

The display is attached to the bottom side with a connector and to the top side with screws to the posts. The top holes in the display may need to be widened a bit with a file to accommodate the M3 screws.

2 banana plugs are fixed into the lid of the box and a hole is cut for the display.

Printing of the box (I printed on an inkjet printer):

I glued the label on the top of the box and re-glued it with anti-abrasion adhesive.

Programming and revival

The code to program the processor in HEX or BIN format can be found in the source file package. After programming, set the fuses as follows (16 MHz crystal configuration):

low = 0xEF (11101111), high = 0xC9 (11001001).

When power is applied, the display should light up as follows:

The first row indicates the absence of a signal. The second row displays the current input level LOW or HIGH - can be used to set the decision level of input circuits.

When a signal is applied, the first row displays the frequency and the second row displays the pulse period.

If you want to modify the program, it is compiled using WinAvr 20100110 (avr-gcc 4.3.3). The installer can be downloaded from e.g. SourceForge https://sourceforge.net/projects/winavr/. The program is compiled with the command file c.bat (=compile).

Calibration

When fitted with a conventional crystal, the achieved frequency accuracy at room temperature is around 50 ppm (= 0.005% deviation) - the deviation appears on the penultimate digit of the reading. The accuracy of the crystal can be increased by calibrating it by 1 order of magnitude. Calibration of frequency and time is an activity most easily achieved in domestic conditions, as we have an accurate time standard available, e.g. via the internet.

To calibrate the frequency meter crystal, the ClockTest program can be used. After the program is loaded into the processor and the power is turned on, the display starts counting down the time. The first line shows the elapsed time in seconds, rounded to the nearest minute. This is followed by the deviation from a whole minute, in seconds (in the range -30 .. +30 seconds). That is, from the 30th second onwards, a negative deviation is displayed, and from the whole minute onwards, a positive deviation. The second line displays the calculated processor frequency, which would correspond to the current elapsed time in whole minutes. According to the picture - if exactly 4 minutes have passed and the display reads "240-7", it means that the processor is 7 seconds late, it thinks only "240 - 7" seconds have passed, the crystal frequency in that case would be 15534440 Hz.

After a certain period of time, the elapsed time indicated on the display and the actual elapsed time will be deducted. The corrected CPU frequency is then F = F_CPU * time_indicated / time_actual. The corrected processor frequency is written to the F_CPU parameter in the MAKEFILE of the meter source code, and the corrected program is compiled and written to the processor.

Example of use:

I start a calibration measurement at 19:55:00. I will measure the calibration for 1 day. On the second day, I take a reading on the display at 19:26:00, 84660 seconds. The display reads 84660+5. That means - 84660 seconds of whole minutes have passed, but the processor thinks it is 5 seconds more. The actual processor frequency is then: F = 16000000 * 84665 / 84660 = 16000945 Hz (the same value should appear in the second line of the display). I write this value to the F_CPU variable in the makefile, translate it and burn it into the processor. Now I can repeat the refinement measurement with a longer time.

Note: It is advisable to choose a measurement time such that the deviation is a few seconds (so that no inaccuracy error occurs in the time reading) and yet less than 30 seconds (so that the whole minutes on the display agree with the actual elapsed time). Before calibration, it is advisable to leave the instrument on for a few minutes to allow the internal temperatures to stabilise. Also next time, if you want an accurate full digit reading, it is advisable to let the instrument stabilize first to achieve the same temperature conditions as the calibration. Of course, the calibration will no longer be valid if you use the meter in freezing temperatures or in hot summers; the meter does not have temperature stabilization.

During calibration you can use the programs in the "util" folder. The CLOCK.EXE program is a Windows program to display the current time (Windows 10 can also display the time with seconds, but it is not a window that stays permanently on the display). The AboutTime program is a program to synchronize the PC time with an accurate time server. If the default servers are not in use, the tik.cesnet.cz and tak.cesnet.cz servers can be used.

After proper calibration, the generator and meter data should differ only minimally. When measuring, use a rectangular signal. When measuring shape oscillations, PWM control is used, the meter would also pick up PWM carrier oscillations and the reading would be distorted. Distortion of the reading can also occur with a rectangular signal if long unshielded wires are used. The conductors pick up industrial interference and this can cause the frequency reading to jump randomly by up to several units of Hz (the decimal places do not change). This mainly affects the frequency range in the hundreds of Hz. You can treat this by connecting the meter to the waveguide outputs - an RC filter is used which will also suppress interference induced on the wires.

Deficiencies and corrections

Downloads

Source codes of FreqMeter with firmware

Schematic diagram in Eagle Free

Graphic documents (schematic and circuit board)

ClockTest program for crystal calibration

Complete download of FreqMeter documents

Used components

The parts selection was tailored to a GM Electronics store near me. The display I chose here is one that matches the display I used with its pins, i.e. the pins are on the bottom left. A different display (2 rows of 16 characters) should work with the same functionality, and may be cheaper, but may have a different pin layout. Typically, many displays have the pins on the top left, which will mean having to modify (and enlarge) the PCB. Anyway, still try wiring the LED for the backlight (on my displays, the pins are reversed from the datasheet).

I listed the SN74HC393N divider, which is the only one I could get at my GM store and with which the meter works up to 50 MHz. If you want to achieve higher frequencies, try looking for another variant of the 393 circuit. The Philips NXP 74HC393 version works up to 100 MHz. The Toshiba 74VHC393FT has a stated typical cutoff frequency of 170 MHz. Both are available from mouser.com in SMD versions - the PCB will need to be modified for the SMD variant. The meter will display a maximum of 100 MHz.

Total price for everything is 441 Kc (including box, photocuprextit, more expensive display and more expensive connector).

Miroslav Nemecek

<< Back