A 2.5 GHz counter




An AVR controller can be used as a counter, although it is a bit more involved than with a PIC. The reason is that a PIC (at least the 16F84) has an asynchronous counter input. This input will handle frequencies up to app. 40 MHz. AVR's have a synchronous counter input which is sampled with the clock frequency, so it cannot measure frequencies over half the clock frequency. So, when using a 4 MHz clock, input frequencies must be lower than 2 MHz. Use 40% of the clock frequency to be on the safe side.

The input frequency can be measured by starting an AVR counter. Wait some predetermined time and then stop the counter. Read the counter register, account for the measurement time, and you know the frequency. This sounds simple enough. Things get a little more complicated if you use an external (to the AVR) prescaler to measure higher frequencies. A prescaler can be seen as a counter itself, that produces an output pulse for every n counts of input pulses. Even if this external prescaler has not counted up to its limit, you will want to know this count value, because it adds to the AVR count value to get a resulting counter with more bits.
An example: the AVR internal counter is 16 bits. It can count up to 65536 before overflowing to 0. If you use an external 14-bit counter (a 4020) as prescaler, it will increment the internal AVR counter at every 16384th input pulse. If you know the value of the 14-bit counter after the measurement time, you have effectively a 30-bit counter:
14-bit         16-bit
--------------.----------------
Resulting count value = (14-bit-count shifted 16 bits to the left) + 16-bit-avr-count
So, for this to work you must know at what value the 14-bit counter ends. This can be done by using the AVR to feed extra pulses into this counter until it overflows and the internal AVR counter increments by one. The external count value is then 16384 - (the number of extra pulses fed to the 14-bit counter).

We will need a few logic circuits to control the counter. First a circuit to open or close the gate to the counter. Then, a circuit to let through the extra (flush) counts to determine the end value of the counter:


The leftmost gate is used as a buffer. Then, if a logic one is applied to the second gate, count pulses from the buffer are passed through. After the counting period is over, this gate is closed. Then, extra pulses are sent to the third gate to determine the end-value of the counter.
The counter system then looks like this:


It breaks down into two main parts:
The prescaler and external counter part and the microcontroller/display part.

The counter input has a 3 dB pad to set the input impedance to app. 50 Ohm, an ERA-3 20dB amplifier and a Mini-Circuits MSC-2-11 two-way splitter. One output is fed to an Analog Devices AD8314 log-detector, the other to an On-Semiconductor (formerly Motorola) MC12095 prescaler set to divide by 2, followed by a Philips SAB6456 which divides by 64, making a total prescale value of 128.
Using a gate time of 0.128 seconds results in a 1kHz resolution:

1 s count time = 1Hz resolution
0.1 s count time = 10Hz resolution
0.1 s count time and prescale 128 = 1280Hz resolution
0.128 s count time and prescale 128 = 1000Hz resolution

The AVR controls the gates and feeds extra pulses into the second gate to determine the value of the 4020 counter. It turned out that the MC12095 and SAB6456 were very noisy and disturbed the measurement of the AD8314 log-output. Therefore, a fet switch was added to enable the AVR to powerdown the prescalers when measuring the log-level.


The output of the 4020 is connected to the T0 input of the controller. Log-level is measured on pin 0 of portA. The remainder of the circuit is standard, except for the clock. The AVR can run on an internal 10MHz clock, but also on an external clock. This is controlled by a front-panel switch and two relais.
I used an AT90S8535, which is probably overkill, you could try a smaller controller. The counter is built into a small printer switch box:

Left is a small box with the first two prescalers and log detector, at the right is a box housing the remaining 4020 prescaler and the controller.

I have written the program in Bascom. It was my first program and it probably shows... It works for me however. Particularly useful is the log-level shown on the display.
As an example, a signal of app. 500MHz is measured:

And the signalstrength is increased with 10dB:


The display shows in the upperleft corner a small 'jumping man'. This is to show that the counter is active. Next to the jumping man, an "I" means that the internal clock is used. An external clock is indicated with an "E".
The counter will work with an input level between -40 and -10dBm.

TOC