Counter Operation


A frequency counter works by accumulating cycle counts from an AC or RF signal source for a precise period of time (the "gate" period) and then displays this value in some manner. For example, if the gate was open for one second, the number of cycles accumulated would be the same as the actual frequency ("cycles per second"). In this case the counter gate period is normally 100ms, which gives the counter a resolution of 10 Hz. The high resolution mode operates more slowly with a 1 second gate, which does allow a display resolution of 1 Hz.

Unlike most conventional logic-based frequency counters, the time taken to convert the results and do the necessary display and housekeeping tasks in a microprocessor is very short. The counter is ready to make the next reading very quickly, and (in normal mode) makes at least five readings per second. Rather than display the value immediately, the new value is filtered to improve display stability and also to improve resolution (to remove the usual one-count uncertainty that most counters suffer). The display is extremely stable. The telemetry is not filtered.


The Display explained

In the picture above, the small symbol at the right end of the top line of the display is the "gate" indicator. It is present when the counter is actually counting (which is most of the time), and goes away when it is not. In offset modes it shows an arrow symbol rather than a gate.

The counter operates in binary, ie. it counts zeros and ones, not in decimal like a logic based counter. Consequently, the result needs to be converted to decimal before display. This is done by a complex 24 bit binary to BCD software routine which can convert from binary any decimal number up to 16777215. Counting in binary is very convenient for the microprocessor and considerably reduces the complexity of the software.

There are four operating modes, selected by microprocessor input pins. The inputs can be preset to a single mode, or connected to a switch for front panel selection. The inputs have internal pull-ups, so only need to be switched or linked to 0V as necessary. The four modes are:

Except for the last mode, all have 100ms gate time. The offsets are not sent with the telemetry. Other offsets can be programmed in by editing the source code and recompiling. 1650 kHz is a very common IF frequency used by commercial SSB transceivers that can be converted to Amateur bands.

In the different modes, the decimal point is placed to provide direct reading of frequency. Rather than use a normal dot or period, a special decimal point character is used. In normal and offset modes the display is in MHz (eg. 7.05421 MHz), while in high resolution mode the display is in kHz (eg. 7054.4210 kHz). In all modes the leading zero digit is blanked if it would be zero.

In the VHF/UHF model, the offset options are replaced with two prescaler options. In divide by 10 mode, the reading is multiplied by 10 (BCD shift left), so the display indicates frequency correctly. The resolution is reduced to 100 Hz. In divide by 64 mode it would seem obvious to perform the necessary multiplication for direct reading by multiplying (left shifting) the binary result before BCD conersion. Unfortunately an upper frequency limit of 160 MHz is met in the 24 bit BCD conersion routine, and a different approach is needed. The gate time is reduced to 64ms (so the count is reduced by a factor of 64/100), and then the BCD result is multiplied by 100, resulting in the correct multiplication by 64. The resolution in this mode is about 1 kHz. The four VHF/UHF modes are:

Once the counting is done, the microprocessor saves the result in memory for telemetry reporting, adds any offsets requested (such as when counting the local oscillator in a receiver), and then converts the value to decimal and displays it. It then displays the first two analog channels as voltages on the lower line of the display. It is up to the user to scale the value (by adapting the embedded program) to suit the signal conditioning circuitry used. The software is preset to provide a 0-5V range (using a 2.4k series resistor) achieved by shifting the binary result left before decimal conversion. The reason for this is to void the need for high precision division, which is not easy to do in the microprocessor. For channels that are not displayed on the LCD this does not matter, as the PC does the scaling using precision arithmetic, and any range can be used.

In the version of software with "S-Meter" display, the voltage from A-D channel 0 is displayed as a combined bar graph and digital display. The digital display is a single digit that is placed at the end of the bar. It shows S-points 0 - 9, and signal strengths greater than S9 are indicated as letters A-F.

The Analog to Digital Converter which measures these voltages operates with an interrupt routine, so acts as a second independent program. It is important that the micro not be interrupted while timing the frequency count, so the A-D operation is suspended at this time. However, the conversions are quite fast and six channels can be easily read between counter cycles. The results are stored in memory for telemetry and converted to decimal for display on the LCD.

The final activity the microprocessor performs, before starting a new count, is to send the telemetry. Six A-D channels are sent as four ASCII character binary numbers, and then the latest counter result is sent as an eight ASCII character binary number. The telemetry is sent using the microprocessor's UART (Universal Asynchronous Receiver/Transmitter), at 19200 baud, and out through the RS232 transmitter to a PC or other data device. It takes only about 20ms to send all the data.

The telemetry can be used with any computer or data logger, or even with a terminal program (set to 9600-N-8-1). For convenience, an example program is provided, which like the AVR DVM project, uses user-settable scaling and offsets for the displayed data. This will allow you to add offsets to the counter reading without changing the embedded program!

The PC display is a DOS executable, which will operate from DOS, Win 3.x, Win95 or Win98, on any valid serial port. Because the source code is also provided (see here), the user can adapt the program to suit the purpose. It would be very easy to write a chart recorder or data logger application, writing the data to a file format suitable for spreadsheet analysis and graphing. See the software section for more information on how to use the PC software. A counter with graphing and data logging makes a very powerful tool!


Copyright � M. Greenman 1997-2005. All rights reserved. Contact the author before using any of this material.