Counter
Counter
Counter
A simple RF/Microwave
frequency counter
I decided to design a simple, easily gate timing.
reproducible counter around a PIC
16F876A. The basic counter range is Both the microwave and RF inputs
extended to at least 180MHz using two have an additional feature, usually not
74Fxx devices. A divide-by-64 found in frequency counters: a simple
prescaler is used for higher signal level detector driving a bar
frequencies up to at least 4.5GHz. All indicator on the LCD display. This is
results of the measurement are shown very useful to check for the correct
on an inexpensive, 2x16 alphanumeric input signal level as well as an
LCD module with large characters. A indicator for circuit tuning or
block diagram of the counter is shown absorption wave meter dip display.
in Fig 1.
The counter has three front ends: a 1.
microwave (prescaled) input, an RF
input and a TTL input. The The counter
microwave and RF inputs are AC
coupled and terminated at low
impedance (around 50Ω). The TTL
input is DC coupled and has high input The whole counter design is based on a
impedance. A progress bar indicator is 16F876A PIC microcontroller. This
provided on the LCD display for the includes several peripherals but just a
130
VHF COMMUNICATIONS 3/2007
few of them are used in this project. The /K input of the 74F50109 is inverted, two
most important in this project are two port pins (RA2 and RA3) of the PIC are
internal hardware counter/timers called required to drive the J and /K inputs with
TMR0 and TMR1. The TMR0 timer minimal skew.
generates very precise interrupts every
100 microseconds (10kHz) from the On the other end, the counter needs to be
20MHz clock/reference. All required extended beyond the 4 bits of the 74Fxxx
timings for the counter timebase are logic and 16 bits of the TMR1 are used
simply integer multiples of this basic adding up to 20 bits of resolution. To
period. avoid disrupting the operation of the
main 100μs timer, the TMR1 is not
The TMR1 is used as a 16bit (binary) allowed to generate interrupts. The
input signal counter. It’s maximum TMR1 overflow (interrupt) flag is
counting frequency is just around checked during every 100μs (TMR0)
16.7MHz. Therefore, the first four flip- interrupt. The overflows are counted in
flops of the input signal counter chain are two additional 8 bit registers. The overall
added externally as 74Fxxx logic counter resolution is therefore 36 bits.
devices. The first two stages use one of
the fastest 74Fxxx series devices, the These 36 bits are truncated to 32 bits, the
74F50109 dual J/K flip-flop. The upper 4 bits are not used. 32 bits allow
74F50109 is also specified as metastable counting beyond 400MHz with a
immune and is therefore the ideal resolution of 0.1Hz (gate time 10s). None
component for the counter gate. The of these counters is ever reset! The
circuit diagram of the counter is shown in counter value at the beginning of the
Fig 2. measurement is stored and subtracted
from the end value. Finally, the 32 bit
A more conventional 74F74 dual D flip- binary result is converted to a 10 digit
flop is used in the third and fourth stages. decimal number and the latter is
The TTL flip-flops require pull-up displayed with the leading zeros blanked,
resistors to drive the PIC ports RC0, decimal point and units (MHz or kHz).
RC1, RC2 and RC3. RC0 is used as a
clock input to the TMR1 at the same The basic counter software allows three
time. Replacing the 74F74 with a resolutions (selected with RC4 and RC5):
74ACT74 could save some current and 10Hz, 1Hz and 0.1Hz in direct counting
two pull-up resistors. The 74F50109 has mode (no prescaler), corresponding to
the same pin-out and logical function as gate times of 100ms, 1s and 10s. When
the 74F109, but the latter has a lower used with a divide-by-64 prescaler, the
frequency limit and is not specified three available resolutions become 1kHz,
metastable free. 100Hz and 10Hz, corresponding to gate
times of 64ms, 640ms and 6.4s. All these
The typical frequency limit of the gate times are obtained by counting the
74F50109 is specified as 150MHz. 100μs (10kHz TMR0) interrupts.
Driving the 74F50109 with a fast
switching transistor 2N3960 (f t = The PIC 16F876A drives a standard LCD
1.6GHz) and a schottky diode 1N5712 to module with a HD44780 controller and a
prevent saturation, reliable counting can resolution of two rows of 16 characters
be achieved up to 190 - 200MHz! Unlike each. The HD44780 requires 8 data lines
conventional AND or OR gates, the J/K (port B of the 16F876A) and three
gate minimises the jitter of the counting control signals: Register Select (RC6),
result (wandering of the last digit) Read/Write (GND) and Enable (RC7).
regardless of the input signal. Since the Since the data presented on the 8-bit-
131
VHF COMMUNICATIONS 3/2007
wide output port RB0-7 is only written to two 10Ω current limiting resistors.
the HD44780, the R/W input is
hardwired to ground (/Write). The LCD The input signal level is fed to the only
back light LEDs are supplied through
Fig 3: PCB layout for the frequency Fig 4: Picture of the component side
counter. of the counter PCB.
132
VHF COMMUNICATIONS 3/2007
Fig 5: Picture of the track side of the counter PCB with SMD compoenets
fitted, note the 0R links.
remaining PIC peripheral used in this IC sockets are used for the PIC 16F876A
project, the A/D converter. The latter has and as connectors. The PCB layout is
a resolution of 10 bits, but only the most shown in Fig 3 and the component layout
significant 7 bits are used. These drive a in Figs 4 and 5.
bar indicator on the LCD module with 36
segments, corresponding to an input Most of the components are in SMD
voltage between zero and 1.4V (full packages and are installed on the bottom
scale) on the analogue inputs RA0 (MW (solder) side of the printed circuit board.
mode) or RA1 (RF mode). The operating Due to the single sided circuit, many
mode is selected with switches driving jumpers are required. The PCB is
the digital inputs RA4 and RA5. designed for 0805 jumpers shown as 0R
on the picture of the completed board Fig
The main counter module is built on a 5.
single sided printed circuit board
measuring 60mm x 60mm. Good quality A 20MHz crystal is used both as a clock
133
VHF COMMUNICATIONS 3/2007
134
VHF COMMUNICATIONS 3/2007
Fig 8: Component
layout for the
microwave
prescaler.
135
VHF COMMUNICATIONS 3/2007
3.
Assembly
Fig 10: PCB layout for the RF front All counter modules require a +5V
end. power supply. A 7805 regulator is a
simple and efficient solution. Some
additional components are required for
The TTL front end is built on a single interference and switching transient
sided printed circuit board measuring suppression. The circuit diagram of the
20mm x 60mm. The PCB layout is power supply is shown in Fig 15 The
shown in Fig 13 and the component 7805 regulator is bolted directly to the
layout in Fig 14. The input cable is rear panel for heat sinking.
soldered directly to the PCB. Input
protection is provided by the 470Ω Two DPDT switches are used for front
resistor and the zenner diodes inside the end selection. An additional switch is
BF998 (breakdown voltage between 8V used to select the gate time.
and 12V). Further protection could be
obtained by additional zenner diodes, All four printed circuit boards are single
however the latter may include a large sided, etched on 1.6mm thick FR4
capacitive loading (more than 100pF). laminate (image resolution is 150dpi).
136
VHF COMMUNICATIONS 3/2007
4.
Operation
Fig 13: PCB layout for the TTL front Immediately after power up, the counter
end. displays the software version/date for
about one second.
The counter is installed in a box made of
aluminium sheet shown in Fig 16. The During normal operation, the leftmost
bottom is made from 1mm thick characters of both rows are used as a
aluminium sheet, the cover is made from vertical bar display of the gate progress
0.6mm thick aluminium sheet and the with 10 horizontal segments. The
LCD is protected by a small piece of remaining 15 characters in the top row of
plexiglass. The internal width is 200mm, the display show the measured
depth 100mm and height 45mm. frequency. Three characters in the bottom
row show the operating mode ("MW",
The RF connectors, switches and LCD "RF" or "TTL") and the remaining 12
module are installed on the front panel. characters are used as a horizontal bar
The power supply connector is installed display of the signal strength with 36
on the rear panel. vertical segments.
137
VHF COMMUNICATIONS 3/2007
138
VHF COMMUNICATIONS 3/2007
Fig 17: The counter in the microwave mode with a gate time of 640ms
corresponding to a resolution of 100Hz.
even worse results! to a frequency counter.
In the TTL mode the prototypes operated Last but not least, all detailed
reliably beyond 100MHz. This frequency information like PCB files or software
limit is however reduced by the coaxial source code are available on Matjaz
cable feeding TTL signals and even more Vidmar's web site [2].
when using oscilloscope probes. The
input signal level is not indicated in the
TTL mode. The built in hysteresis allows
reliable counting of very low frequencies,
like the 50Hz mains. 5.
The current software version does not Probes
detect the mode switching before the end
of the gate period. Therefore one may
have to wait up to 10 seconds for the gate
period to expire and another 10 seconds A very common problem of many
to get some meaningful reading. The frequency counters is that these are
current software also does not make any supplied to the end user without (any)
use of the measured signal level. s u i t a b l e p r o b e s ! I n f a c t , mo s t
Therefore it will display the self RF/microwave sources cannot be
oscillating frequency of the prescaler connected directly to a counter input. The
with no signal input in the microwave conventional oscilloscope probe is not a
mode or any other invalid data due to low good solution for most RF/microwave
signal levels in the RF or microwave measurements either. Worst of all, most
modes. counters are not even designed to be used
The software is designed using the same with some useful probe types.
rules as the whole counter: keep this
project useful, simple and Any serious RF/microwave engineer has
straightforward. A simple prescaler is his/her own set of suitable attenuators,
therefore used in place of a considerably circulators, loads and directional couplers
more complex direct microwave counter. to connect spectrum analysers, power
Some simple 74Fxxx logic ensures meters, counters and other instruments to
enough overlap between the prescaled the circuit under test. A complete set of
microwave frequency range and the transitions between different RF
direct RF frequency range. A TTL input connectors is also required. Finally, a
with hysteresis is an efficient solution for number of pigtailed connectors to be
low frequencies and extreme duty cycles. soldered directly to the circuit under test
Finally, an input signal level indicator is is always of great help.
an inexpensive but very useful addition
139
VHF COMMUNICATIONS 3/2007
140