You are on page 1of 4

HOMELAB PROJECT

Self-calibrating
Frequency Meter
No alignment necessary
By Willem den Hollander (The Netherlands)

In the May & June issue of ElektorLabs Magazine we described a 10-MHz reference frequency source that
uses the signals from GPS satellites to provide an extremely accurate reference frequency. The author has
designed a self-calibrating frequency counter based on that circuit.

A brief history Another measurement method became


Features The 10-MHz reference frequency gener- popular with the advent of microcon-
• Self-calibrating with GPS signal ator uses a precise 20-MHz voltage con- trollers: reciprocal frequency measure-
• Input frequency range trolled temperature compensated crystal ment. With this method, the input signal
5 Hz to 80 MHz oscillator (VCTCXO) that is locked to the defines a time window with a duration
• Input signal amplitude 1 pps output signal from a GPS receiver that depends on the desired accuracy.
0.2 to 30 V module. Under ideal conditions, the out- Two counters run during the gate time of
• Resolution 6, 7 or 8 digits put signal has an accuracy of 1 part in this window. The first counts the number
• Accuracy (after locking) 1010. A commercial reference frequency of cycles of the input signal, while the
±1 count pulse generator with comparable accuracy is a second counts the number of cycles of
lot more expensive than our DIY version. the reference signal. The frequency of the
input signal can then be determined from:
Reciprocal measurement
input pulse count
There are various ways to measure sig- The easiest (and conventional) way to frequency =
nal frequencies. They all have one thing measure signal frequency is to count
( reference pulse count ) × tc
in common: they require a stable and the number of cycles of the input sig- Here tc is the period of the reference fre-
precisely known reference frequency. A nal during a precisely defined 1-second quency, which is equal to 1/fref. Assuming
suitable reference frequency source was time window. The uncertainty with this a reference frequency of 10 MHz, the
described in the May& June 2018 issue of measurement method is ±1 digit. That resolution of the frequency measurement
ElektorLabs Magazine [1]. Here we use it corresponds to an error of ±1 Hz, which is 6, 7 or 8 digits with a measurement
as the basis for a full-fledged frequency is of course unacceptable for measure- window (gate time) of 0.1, 1 or 10 sec-
counter with self-calibration capability. ment of low frequencies. onds, respectively.

64 September & October 2018 www.elektormagazine.com


Block diagram
The block diagram of the digital portion
1pps from counter count=16
of the frequency counter is shown in divide by 16
Q
GPS receiver
Figure 1. The counter essentially con- flipflop

sists of the gate timing logic and the


two subsequent 32-bit counters, along
with part of the microcontroller. The
10MHz
other blocks are responsible for gener- Q 32-bit counter
flipflop
ating the reference frequency. For more 20MHz
gate

information about that, please consult VCO

the article in the May & June issue [1].


It’s worth noting that with the exception
DAC
of the VCTCXO (marked ‘20 MHz VCO’ µController Display
DAC
in the block diagram), everything shown
DAC
on the block diagram is integrated into
the microcontroller.
The maximum frequency that the micro-
32-bit counter
controller inputs can handle is 16 MHz, Window gate
so the oscillator frequency is divided generator

by 2 to obtain a 10-MHz signal. That is Input


32-bit counter
well within the specified capability of the signal
gate
microcontroller.
By the way, the microcontroller data-
sheet is not entirely clear on the maxi-
Figure 1. Block diagram of the frequency counter. Except for the display, everything shown here is
mum allowable frequency for the I/Os.
located in the microcontroller.
Sometimes you think it is 16 MHz, and
sometimes you think it is 20 MHz. That
makes it anybody’s guess. However, the signal frequency by a factor of 4 to avoid at least 5 Hz to 80 MHz. The amplitude
author’s prototype certainly did not have confronting the microcontroller input with of the input signal should be between
any problem with frequencies of 20 MHz frequencies too high for it to handle. The 0.2 V and 30 V.
or even higher, corresponding to 80 MHz frequency range of the input circuit, from The display used is a DOG type from
or more at the input. the BNC input to the counter output, is Electronic Assembly with two rows of six-

Input amplifier
As we all know, digital circuits are only
VCC VCC
happy with digital signals, so the input
signal has to be conditioned before it is R6 R7 R9 R11
C6 C7 16
applied to the microcontroller port. Fig-
560R

560R

VCC
15k

1k2

10
TE
ure 2 shows the relevant part of the cir- 100n 2u2 7
PE
9
LD
cuit (top half). The display module is also C2 R3
C4
IC1 1
CLR
22R 1 4 Q1 14
IC2
shown here in the bottom half, because J1 C1
47p T1 R5
22u TLV3501
5 2
CLK
Q2 13
R2
R13 Q3 12
that part of the circuit is located on the T3 3
74AC161
220k

100k
J309 Q4 11
T2 2 3
100n P1
10k

C3 6
display board. You might wonder why it D1 BC849C
4
P2
5
R1 22u P3
is on the display board. The answer is R4 BC849C R8 R10
C5
R12 6
P4 TC
15
1M

GND
330R

that the circuit needs to be as close as


1k5

15k

1k2

8
47p

possible to the input connector, because


BAT18-04
VCC
long wire leads should always be avoided
with high-frequency analogue signals. R16 C9 C10 C11 C12

The signal from the BNC connector J1 is


1R6

1u 10u 10u 100n J2


limited by the dual diode D1 and buff- 40 36 25 24 35 34 33 32 31 30 26
INP 1 VCC
VDD
D0
D1
D2
D3
D4
D5
VOUT
RST

VIN
E

2
ered by the FET T1. This input circuit is 1
A1 RS
39
RS 3
20 38
LCD1
required to obtain an input impedance A2
LCD- DISPLAY
CSB CSB 4
R14 R15
CK 5
of 1 MΩ and to avoid overloading due to 2 EA DOG-M 29
10k

10k

C1 D6 SI 6
19 28
C2 D7 7
high-amplitude input signals. R/W PSB CAP1N CAP1P VSS 8
37 23
Transistors T2 and T3 provide enough 21
C8
22 27 9 HOLD
10 RANGE

gain to allows the comparator IC1 to con- 1u


SW1 SW2

vert the analogue signal into a respect-


able digital signal. The amplifier does not 160706 - 12

need to be especially linear, since all we


actually need is the timing of the rising
Figure 2. Schematic diagram of the input amplifier. It is shown on this diagram because it is
and falling edges. Counter IC2 divides the
located on the display board.

www.elektormagazine.com September & October 2018 65


• the buffered 10-MHz and 1-MHz
VCC
outputs are also deleted because
R1
Vdisp they are no longer necessary, but a
VCC
10-MHz signal is still available on the

10k
C3 C4 RC5 output of the microcontroller
J2 100n 10u (pin 16);
1

20
2 • a second 3.3-V voltage regulator
VCC 3 4 5

1
VDD
28 4 VCC V_BCKP (IC4) has been added to provide the
MCLR RB7/ICSPDAT
X1 2
RA0 RB6/ICSPCLK
27 5 1
RXD1 IC2 TIMER
7 supply voltage for the display, the
4 1 3 26 6 2 8
VCC
20MHz
ADJ
4
RA1
RA2
RB5
RB4
25 10
TXD1
RESET
AADET_N
NC
9
J3
input amplifier and the GPS receiver.
IC1
C1 C2 5
6
RA3 RB3
24
23
6
1PPS
L80
EX_ANT
11
That way the VCTCXO and the micro-
RA4 RB2 SMA
100n
VCTCXO
10u 7
RA5 RB1
22 GND GND controller have their own power sup-
2 3 9 21 3 12
GND OUT
10
RA7
RA6
PIC16F1778
RB0
RC7
18 ply and the stability of the reference
11
12
RC0 RC6
17
VCC
frequency is assured.
RC1 LM1117-3.3
VDISP
13
RC2 RC5
16 10MHz
IC3  
14 15 3 2
J4
RC3 RC4 VIN VOUT
Connector J2 is intended for in-circuit
VSS VSS GND
1
2
INP
8 19
C12
1
C5 C6 C7
programming of the microcontroller, and
3 RS 100n 22u 100n 100n
J4 provides the connection to the dis-
4 CSB
5 CK play board.
6 SDO J1 LM1117-3.3
7 IC4 Vdisp
8
1 3
VIN VOUT
2
Construction
9 HOLD GND
10 WINDOW 2 C8 C9
1
C10 C11 As previously mentioned, the input ampli-
22u 100n 22u 100n fier and the display are located on the
160706 - 13
display board. With the exception of the
connectors and switches, which should
preferably be leaded types because they
Figure 3. Schematic diagram of the microcontroller portion. There aren’t many components, so the
are subject to physical stress, all compo-
PCB is remarkably empty.
nents are SMDs. That keeps the overall
package pleasantly compact (see Fig-
teen characters and white LED backlight- shown in Figure 3. It is largely the same ure 4). It’s a pity that for proper oper-
ing. The display is driven by the micro- as the 10 MHz reference frequency proj- ation the GPS receiver has to be kept
controller over an SPI bus (connector J2). ect in the May & June issue. For more as far away from the oscillator as pos-
details, see the article in that issue. The sible; otherwise it could have also been
Microcontroller portion only differences are: mounted on this circuit board.
The microcontroller, the clock crystal and • the two indicator LEDs are deleted Figure 5 shows the microcontroller
the GPS receiver are located on the main (the microcontroller pins are needed board. It is very sparsely populated, but
circuit board. The schematic diagram is for the SPI interface (J4); that is beneficial for the GPS receiver.
The boards are fitted in a Teko 011 case,
with the original aluminium front and
back panels replaced by acrylic sheets
covered with aluminium-coloured self-ad-
hesive film because the GPS receiver
needs access to the outside world. The
power source is a standard 5-V USB AC
line adapter.
Figure 6 gives an impression of the
author’s prototype.

Firmware
The firmware residing in the microcon-
troller, which performs all the functions
required for proper operation of the fre-
quency counter, is written in assembly
language because using a high-level lan-
guage would have a number of serious
disadvantages.
First of all, it would not be possible to
control the timing of the various functions
with sufficient accuracy, and secondly,
it would take up more memory space.
Figure 4. The display board with the input amplifier. And the software would run slower – also

66 September & October 2018 www.elektormagazine.com


Figure 5. The microcontroller board. Figure 6. The front and rear of the case.

and 7c). The Hold button freezes the


Never calibrate again reading on the display (Figure 7d). Note
that this only stops updating of the dis- a
play; the counter keeps on making
measurements.
The symbol at the left end of the bottom b
a significant consideration. In particu- row (Figures 7d and 7e) indicates that
lar, the multiplication and division oper- the VCTCXO is locked to the GPS signal.
ations that are necessary to calculate But even if this symbol is not shown,
c
the frequency shown on the display are accurate measurement is still assured
coded the way they need to be for this for a relatively long time. Once the fre-
application. Multiplying the content of quency counter has been locked to the
the 32-bit input counter by 10 and then GPS signal, the D/A converter settings d
dividing the result by the content of the are stored in the non-volatile memory of
second 32-bit counter takes less than the microcontroller as described in the
1 millisecond, including BCD conversion. article in the May/June issue. Each time e
All in all, the firmware in its present form the counter is powered up, these set-
occupies only 8% of the microcontroller tings are read from the memory and the
memory. The firmware and the PCB lay- converters are configured accordingly.
Figure 7. a: 0.1-s measurement window;
outs can be downloaded free of charge Of course, the frequency of the VCTCXO
b: 1-s measurement window;
from the project page for this article [2]. will gradually change over time — that c: 10-s measurement window;
is a normal ageing process. But as long d: oscillator locked, readout frozen;
Use as the oscillator is locked to the GPS e: oscillator locked, no input signal.
The frequency counter is easy to use. signal at more or less regular intervals,
The duration of the measurement window the latest calibration factors for the D/A
(the gate period during which pulses are converters are always stored in memory. @ www.elektor.com
counted) can be selected with the Time This way the accuracy of the frequency
ªGPS board
button. That determines the resolution of counter is guaranteed to be ±1 clock
www.elektor.com/gps-board-eb056
the measurement (see Figures 7a,b,c). pulse.
ªGPS antenna
The selected window time is indicated by  180343-02 www.elektor.com/trimble-gps-antenna
the number of dots in the bottom line of
ªPIC multiprogrammer
the display. Web Links www.elektor.com/pic-eb006
The small symbol at the left end of the
[1] www.elektormagazine.com/160595 ªTL866A universal programmer
top line appears for about 200 ms when
www.elektor.com/tl866a-programmer
a measurement has been completed [2] www.elektormagazine.com/
and the display is updated (Figures 7a 180343-01

www.elektormagazine.com September & October 2018 67

You might also like