(HISTORY)   (COUNTER)   (FRONTENDS)   (PROBES)   (ASSEMBLY)   (OPERATION)   (HOME)



Simple RF/Microwave Frequency Counter

Matjaz Vidmar, S53MV


2. Counter

The whole counter design is based on the PIC micro-controller 16F876A. The latter includes several peripherals and just a few of them are used in this project. The most important in this project are two internal, hardware counters/timers called TMR0 and TMR1. The TMR0 timer generates very precise interrupts every 100 microseconds (10kHz) from the 20MHz clock/reference. All required timings for the counter timebase are simply integer multiples of this basic period.

The TMR1 is used as a 16-bit (binary) input-signal counter. Its maximum counting frequency is just around 16.7MHz. Therefore, the first four flip-flops of the input-signal-counter chain are added externally as 74Fxxx-logic devices. The first two stages use one of the fastest 74Fxxx-series devices, the 74F50109 dual J/K-flip-flop. Further, the 74F50109 is also specified as metastable-immune and is therefore the ideal component for the counter gate.

A more conventional 74F74 dual D-flip-flop is used in the third and fourth stages. The TTL flip-flops require pull-up resistors to drive the PIC ports RC0, RC1, RC2 and RC3. RC0 is used as a clock input to the TMR1 at the same time. Replacing the 74F74 with a 74ACT74 could save some current and two pull-up resistors. The 74F50109 has the same pin-out and logical function as the 74F109, but the latter has a lower frequency limit and is not specified metastable-free.

ctr

The typical frequency limit of the 74F50109 is specified 150MHz. Driving the 74F50109 with a fast switching transistor 2N3960 (ft=1.6GHz) and a schottky diode 1N5712 to prevent saturation, reliable counting can be achieved up to 190-200MHz! Unlike conventional AND or OR gates, the J/K gate minimizes the jitter of the counting result (wandering of the last digit) regardless of the input signal. Since the /K input of the 74F50109 is inverted, two port pins (RA2 and RA3) of the PIC are required to drive the J and /K inputs with minimal skew.

On the other end, the counter needs to be extended beyond the 4 bits of the 74Fxxx logic and 16 bits of the TMR1 adding up to 20 bits of resolution. To avoid disrupting the operation of the main 100us timer, the TMR1 is not allowed to generate interrupts. The TMR1 overflow (interrupt) flag is checked during every 100us (TMR0)interrupt. The overflows are counted in two additional 8-bit registers. The overall counter resolution is therefore 36 bits.

These 36 bits are truncated to 32 bits, the upper 4 bits are not used. 32 bits allow counting beyond 400MHz with a resolution of 0.1Hz (gate time 10s). None of these counters is ever being reset! The counter value at the beginning of the measurement is stored and subtracted from the end value. Finally, the 32-bit binary result is converted to a 10-digit decimal number and the latter is displayed with the leading zeros blanked, decimal point and units (MHz or kHz).

The basic counter software allows three resolutions (selected with RC4 and RC5): 10Hz, 1Hz and 0.1Hz in direct counting mode (no prescaler), corresponding to gate times of 100ms, 1s and 10s. When used with a divide-by-64 prescaler, the three available resolutions become 1kHz, 100Hz and 10Hz, corresponding to gate times of 64ms, 640ms and 6.4s. All these gate times are obtained by counting the 100us (10kHz TMR0) interrupts.

The PIC 16F876A drives a standard LCD module with a HD44780 controller and a resolution of two rows of 16 characters each. The HD44780 requires 8 data lines (port B of the 16F876A) and three control signals: RegisterSelect (RC6), Read/Write (GND) and Enable (RC7). Since the data presented on the 8-bit-wide output port RB0-7 is only written to the HD44780, the R/W input is hardwired to ground (/Write). The LCD back-light LEDs are supplied through two 10ohm current-limiting resistors.

lcd

The input-signal level is fed to the only remaining PIC peripheral used in this project, the A/D converter. The latter has a resolution of 10 bits, but only the most significant 7 bits are used. These drive a bar indicator on the LCD module with 36 segments, corresponding to an input voltage between zero and 1.4V (full scale) on the analog inputs RA0 (MW mode) or RA1 (RF mode). The operating mode is selected with switches driving the digital inputs RA4 and RA5.

The main counter module is built on a single-sided printed-circuit board measuring 60mmX60mm. Good quality IC sockets are used for the PIC 16F876A and as connectors.

ctr1

Most of the components are in SMD packages and are installed on the bottom (solder) side of the printed-circuit board. Due to the single-sided circuit, many jumpers are required. The PCB pattern is designed for 0805 jumpers marked 0R on the circuit diagram.

ctr2

A 20MHz crystal is used both as a clock source for the PIC and as a frequency reference for the frequency counter. 20MHz crystals are usually designed either for 20pF-32pF parallel resonance or series resonance. Since the internal oscillator inside the PIC 16F876A is not able to oscillate on the correct frequency with large capacitors, a series inductor is required to bring the crystal on the exact frequency. The recommended 2.2uH inductor is suitable for 32pF parallel-resonance crystals.

Of course, the PIC 16F876A is also able to operate with an external clock source. This has to be connected to pin 9 while pin 10 is left open. If a high-quality frequency reference for 5MHz, 10MHz or 100MHz is available, it is recommended to multiply or divide its output to obtain the required 20MHz clock.

Other clock frequencies than 20MHz can be accepted by modifying the software to obtain the 10kHz TMR0 interrupt. The TMR0 time constant allows changing the clock in 80kHz frequency steps (4 clock cycles per instruction and divide-by-2 prescaler for the TMR0). Smaller clock steps of 40kHz can be obtained by inserting NOP instructions in the TMR0 interrupt routine, for example using a high-quality (telecom SDH) TCXO for 19.44MHz.



* * * * *