Frequency Counter & Crystal Tester DL4YHF2 Manual
Frequency Counter & Crystal Tester DL4YHF2 Manual
By Steven Vagts
Z-100 LifeLine
Insert, Issue #131
This is a five-digit frequency counter kit based on a PIC single chip 16F628 micro-
controller, with a crystal oscillator measurement function, programmable frequency
setting, and LED digital display. It is most commonly used to measure the oscillation
frequency of a crystal or crystal oscillator.
Part/Model Number: YS9283, B8O8, and many others, but it is actually a generic,
unbranded circuit board based on a circuit developed by Wolfgang Buscher, DL4YHF. I
have also added the ability to test the four-pin crystal oscillator, so we will call
the modified device the DL4YHF2 Frequency Counter and Crystal Tester.
All the parts are through hole components, so the kit is easy, if you have basic
soldering skills, and simple to operate.
Please note, this item ships from an international seller. Expected delivery is 10-15
days.
DL4YHF2 Features:
Power:
Controls:
The DL4YHF2 has no power switch and comes ON when power is applied. It will switch
itself OFF when there is no notable frequency change in 15 Seconds. It does, however,
have one press ON switch used for programming and frequency addition or subtraction.
Assembly:
All the parts needed to construct the
Tester are provided, except there is no
parts list nor instructions. This manual
will guide you through the rather simple
construction and operation of this
Counter.
Before beginning construction, identify and compare the parts you received with the
following list. I also suggest that you check those parts that you can with an ohm-
meter and capacitor checker, if they are available. All parts are new; however, in the
two Freqnency counter kits that I have constructed, I found I was missing a 3-pin
header and had an extra push button switch. In the other China kits that I have
constructed so far, I also found a shorted capacitor and a resistor included in one
kit of the wrong value. A little extra time here to check components now, will save
considerable time trying to troubleshoot a malfunctioning assembly.
Assembly Procedures:
Install the trim capacitor, flat side as shown on the silk screen and the three
transistors. While in some kits, transistor leads may have to be rearranged, in this
kit all the transistor leads are straight and installed as per the silk screen. Leave
the transistor body about 1/4" above the surface of the board, bend the leads to hold
the transistor in place, then solder.
We have some components left to install and some decisions to make, but it is time to
visually check your work looking for solder bridges, parts with cold solder joints
(meaning a poor connection, not having the same appearance of smooth solder flow as
the other solder joints), or open, unsoldered joints. If you have an ohmmeter, check
joints near each other for shorts.
Next, clean the solder side of the board. Many use a special flux cleaner product to
clean the soldering side. Personally, I check each solder connection and use a fine
screwdriver or dental pick to scrape away any flux residue, then use a toothbrush and
a little water to remove the scraped residue.
When you are satisfied that the board is as good as you can make it, locate the five
7-segment LED displays. Note that there is a top and bottom! Make sure that when you
install these, the decimal of each digit is located at the bottom right corner!
These digits usually come with a protective plastic film over the front. Remove these
before you begin. Clearances between digits are tight, so if you fail to remove these,
the digits will often not fit beside each other properly because of the overhanging
plastic film.
For a similar reason, it is also recommended that you DO NOT solder in the digits one
at a time. If one is slightly out of position, it will mess up the alignment of the
remaining digits. Place all five digits into position on the board; double check that
the film has been removed and the decimal is in the lower right of each digit. Pick
the board up so the pins are fully expended through the board. Position your hands
such that your fingers can trap some of the pins of each digit against the back of the
board as you invert the board and rest the displays flat on the work surface.
As with the IC socket, solder one pin on the top and the bottom row of each digit.
Visually check that each digit is tight against the board and that the decimal is at
the lower right. Once satisfied that all is good, solder the remaining pins. Depending
upon the case you wish to use, you may or may not need to cut the digit leads. I’ll
mount mine to a wood board with sufficient clearance to leave the leads alone. The
board will give some weight and physical stability to the finished counter.
Now it is time to decide what source of power you wish to use. This kit comes with a
1.35mm inside diameter x 3.5mm outside diameter male connector, a standard for 5Vdc
connectors, especially for use with USB cables. This Counter, however, can be powered
by up to 9Vdc, and can be powered by a 9Vdc battery. As all my other China kits came
with a larger and more popular 2.1mm inside diameter x 5.5mm outside diameter x 9.5mm
deep 5-9Vdc jack, I preferred using that DC jack.
If you would like to do the same, this requires severe modification to the circuit
board. If not, solder in the given DC jack at this time, and skip the following
section.
The kit comes with a DC jack that takes a 1.35 x 3.5 x 9mm plug. This size is smaller
than that used in the other China kits I have, so I wanted to change it to the more
common 2.1mm x 5.5mm jack size. Obviously, you will need to find the DC jack and the
power cable you wish to use. There are lots of choices. The pictures show my changes.
The first step is to mark and drill the
new size holes required.
Install the 18-pin PIC 16F628 IC, again watching for the location of the half-moon
end, and the assembly is complete. Congratulations!
Operation:
Operation is simple. There is no ON/OFF switch. Plug in the 5-9Vdc power supply or a
9v battery and the device turns ON. If you don’t have the proper connector for the 5-
9Vdc power supply, the battery terminals, ‘-’ and ‘+’, are part of the 4-pin SIP holes
at the center bottom edge. You could attach a 9Vdc battery connector here. However, it
seems to be a weird place to locate the power connectors, instead of beside the power
connector. Using the nearby Frequency Input ‘IN’ and ‘G’ often will cause wear on the
thin wires of the battery supply and will likely cause them to break off.
I also found that those four blank holes were a bit odd for the design. I would have
much preferred the little screw terminals of the earlier testers that I tried. But
perhaps this was intentional to keep your options open - to attach the board to some
larger piece of equipment. Some other options include maybe just using a SIP header
that you can use to attach some clips, or maybe it might be best to solder a pair of
test leads with clips on the ends and wrap the leads around the device when not in
use. I’ll address my solution in the last section.
When I first turned on the DL4YHF2 Counter and tried a crystal, the counter worked
just fine. However, when I attempted to read a frequency from a frequency generator,
all I got was some strange digits on the display. According to what I read on the
internet, if your counter shows a strange frequency initially, enter setup mode to set
the frequency offset to zero (it sometimes happens that PIC programmers don’t erase
the EEPROM where the frequency offset is stored). That solved my problem.
Calibration:
Before operating for the first time, calibrate the unit with a frequency from a known
generator (I used the 50KHz frequency from one of the earlier kits I completed, the
XR2206 Frequency Generator). Attach the frequency generator to the ‘IN’ and ‘GND’
terminals and input a known frequency.
Adjust the yellow adjustable capacitor so that the display is equal to the value of
the signal frequency.
Hint: Do NOT use a metal tool; the metal affects the display readings. If you don’t
have a proper plastic diddle stick, you can whittle a small diameter dowel to use. If
you must use a small screwdriver, note the frequency, adjust the capacitor either left
or right slightly, then remove the screwdriver. Note the new frequency, and adjust
again. Repeat as necessary, removing the screwdriver each time.
Note: The capacitor is fully rotational, meaning it can turn in any direction without
limit. During rotation through 360 degrees, it is simply moving one small metal plate
against another to vary the capacitance. That means there are two positions for each
capacitance value (except maximum and minimum) - while increasing or while decreasing
during rotation. Either position will work fine.
Display Ranges:
The display range automatically switches to give the maximum readout accuracy. The
gate time is also selected automatically as listed in the following table:
The DL4YFM was originally designed for four LED displays, but our unit drives five.
For this reason, the 'single zero' (if no input signal is present) is not displayed in
the 5th, but in the fourth digit.
The PIC firmware always drives a fifth digit as the least significant digit, if the
measured frequency is above 10 kHz. Because there was no free output pin available on
the PIC 16F628 to drive another digit, a logic combination from the first four digit
multiplexer outputs was used (digits 1 ... 4). When all digit multiplexer outputs are
passive (digits 1...4 = high), the optional fifth digit is driven.
The diode between the emitter and ground is used because without it, the transistor
may conduct unwantedly if its base-emitter threshold voltage (typically 0.5 to 0.6V)
was less than the forward voltage of the other diodes in this stage (which will be
about 0.6 to 0.7V for a 1N4148).
Pre-amplifier:
This counter has NO input protection from accidental over voltage. For this reason a
pre-amplifier is often desirable and could be attached as a separate board and used
between the device generating the frequency we care to measure and the input to our
board. One suggested pre-amplified is described here:
If you want to feed the Counter with a TTL signal, a pre-amplifier is not required
because the TTL voltage is controlled by definition and saves about 4mA of current
draw.
If the maximum frequency in your circuit is below 10MHz, you may increase the value of
R3 and R2 by the same factor (say R3=1.2k, R2=56k) to also save some current when
using the counter in a battery-powered device. R1 sets the input impedance and also
the sensitivity. With R1=330 Ohm, the prototype required an input voltage of 600 mVpp
(peak-to-peak) at 40MHz and 150 mVpp at 15MHz. If you need a higher input resistance,
add a FET buffer before the bipolar transistor, or use a fast integrated comparator as
the input stage.
If the counter is used in a shortwave receiver or transceiver, you may want to add or
subtract an offset value from the measured frequency. The offset frequency is the same
as the intermediate frequency in many cases, because the counter is usually connected
to the receivers VFO (variable frequency oscillator). For this purpose, a programming
mode (aka "setup mode") has been implemented in the firmware so you can enter an
offset frequency without reprogramming (or even reassembling) the PIC firmware.
The signal RA5 (pin 4 of the PIC 16F628) is used to switch from normal counter mode
into programming mode. Usually the level on RA5 is high because it is connected to the
supply voltage via pullup resistor (10k to 22k). By pulling RA5 low using the
momentary switch, the firmware is instructed to use the currently measured frequency
as the new offset value. In other words, you must apply the offset frequency to the
counter's input, wait until the value is displayed correctly, and then enter the
programming mode as explained below.
Programming mode:
To enter programming mode, press and hold the programming key (the switch) until the
PIC shows ‘ProG’ on the LED display. Then release the ‘key’. You are now in the first
menu of the programming mode.
To select the next menu, press the key for a short time (less than a second).
To execute the selected function, press the key for a longer time (more than a
second).
Zero: Sets the frequency offset to zero, so the display will show the measured
frequency without offset. The previously programmed offset will be lost.
PSave: Turns the power-saving ON. In power-saving mode, the display is turned
OFF after 15 seconds of no "significant" change in frequency, and ON
again as soon as the frequency changes by more than a few dozen Hertz
(in the 3..4 MHz measuring range). This was added in May 2006 for
battery-powered equipment like QRP transceivers.
Note: There may be more menu items than shown here, but the principle remains the
same.
The frequency offset values are saved as a 32-bit integer numbers in the PIC's data
EEPROM (at the EEPROM's first four memory locations, high-byte first, low-byte last).
If you have no signal generator to produce the offset frequency for programming, or
cannot tap the BFO frequency of your homebrew shortware receiver, you can enter the
offset value with a suitable PIC programmer (like DL4YHF's WinPic). Use a scientific
pocket calculator to convert the frequency (in Hertz, positive or negative) into a
hexadecimal number, and enter this value in the PIC programmer's EEPROM DATA memory
window. If you use WinPic, enable the HEX editor before typing the values into the
memory window. Some examples:
Example for DL2YEO's 30 meter band QRP transceiver: f_RX = f_LO - f_IF = 14.314 MHz -
4.194 MHz = 10.120 MHz, which is the calculation inside the counter (f_LO=measured
input, f_RX=display value, f_IF=programmed offset). If you don't need the 10-MHz-digit
on the display, set the offset to -14.194 MHz instead of -4.194 MHz. This will give
better display resolution, so you only need 4 digits (f_RX=10.120 MHz will be
displayed as 120.0 kHz, which is sufficient because the receiver's tuning range is
only 20 kHz anyway).
Some commonly used IF frequencies can be recalled from the "Table" menu, so you don't
have to measure or enter them yourself. In many cases, there is a BFO for the last
mixer (at the output of the IF amplifier) which produces a frequency close enough to
the desired value.
How it works:
Basically the program runs in an endless loop, with the exception of the initial lamp
test, programming mode, and power-saving mode which are not explained here.
Prepare a coarse frequency measurement for the automatic range switching: Program the
asynchronous prescaler to divide by 64, so the highest external frequencies can be
detected (theoretically 64 MHz, but this exceeds the PIC's specification).
Count the input pulses for 1/16 second, using the PIC's TIMER0 module in counter mode.
During this time, the display multiplexer keeps running. In fact, the counting loop
takes exactly 50 microseconds, including the multiplexer routine. 1250 counting loops
result in a gate time of 1/16 seconds. In the source code, this is done in the
subroutine 'count_pulses'.
Decide which prescaler and which measuring interval should be used, depending on the
coarse frequency measurement.
Reprogram the counter's prescaler so the divided input frequency is below 1 MHz (which
is the maximum input frequency for the hardware counter, if the PIC is clocked with 4
MHz). If the coarse measured frequency is way below 1 MHz, the prescaler is turned off
to get the best possible frequency resolution.
Count the pulses during the measuring interval (alias gate time), which is 0.25, 0.5,
or 1 second. During this time, the display multiplexer keeps running. Overflows of the
8-bit timer register ("hardware") are counted by software in two other 8-bit
registers, so the effective pulse counter has 24 bits (8 hardware bits plus 16
software bits while counting).
If the hardware prescaler was active while counting, multiply the pulse count with the
prescaler ratio so we don't have to care for the prescaler setting in the following
steps.
If the gate time was 0.5 seconds, multiply the pulse count by 2; if the gate time was
0.25 seconds, multiply the pulse count by 4. The result is the input frequency in
Hertz, no matter which prescaler ratio or gate time was used. Like in the previous
step, this "multiplication" is in fact a simple bit-shifting operation.
(Optional) Add the programmed frequency offset. If the result is negative, make it
positive.
Split the frequency into eight (!) decimal digits. This is tricky with a PIC, see the
source code. It is realized by repeatedly subtracting powers of ten from the 32-bit
frequency value, beginning with ten millions (because the highest, theoretically
possible frequency is 64 MHz).
Skip leading zeroes, and insert a decimal point after the kHz- or MHz digit (the kHz-
point is ANDed with a blink flag)
Beginning with the first non-zero digit, convert five digits from binary code into
seven-segment-patterns, and copy the result into the "display registers". The display
multiplex routine which is executed while counting will write these registers to the
LED display of the next main loop.
Poll the 'programming function' input ("RA5"). If this digital input is low, enter
programming mode (not explained here). If not, go to step 1 to begin the next
measurement.
Final Assembly:
For my finished Frequency Counter and Crystal Tester, I made some modifications to
include a frequency probe attachment (the BNC connector in the lower right of the
photo) and the capability of testing the many popular 4-pin crystal oscillators.
The ZIF socket is glued to the top of the plexiglass side with a glue gun. I’ve also
drawn the outlines of the two pin crystal and the 4-pin square and rectangular
oscillators.
The circuit board is screwed to the wood board base with 1/4" pieces cut from a BIC
(tm) pen tube used as spacers. I also attached a 9Vdc battery holder, which is more
convenient than keeping a wall wart handy.
This photo shows my circuit board and the
other parts used to complete my tester.
To sand down the test socket, remove the screw at the end of the socket away from the
handle. Do NOT remove the screw near the handle, as getting the socket back together
is somewhat tricky, if you remove that screw. Push the handle down to close all the
socket slots.
I used a disk sander mounted to my drill. Holding the socket with a pair of pliers at
the handle end, sand the top plate to about half its original thickness - lose about
1/16".
Hint: Sanding causes dust and melted plastic to stick to the sides of the openings in
the top. Use a sharp knife or razor blade to trim away all the excess plastic from the
sides of the socket and holes. A stiff paint brush or old toothbrush is great for
removing any remaining dust. Do NOT lift the handle to open the slots until all dust
has been removed with the brush.
You will also need to remove about the same thickness (1/16") from the length of the
screw that was removed. I found that the screw was fairly soft and could be clipped
with a good pair of diagonal side-cutters.
I have also drawn the outlines of the three case types on the 14-pin test socket. The
5Vdc Vcc must be provided at pins 11 and 14 of the test socket. Ground is at pin 7,
and the frequency signal is found at pin 8 of the socket for all three case types.
As the threaded length of the BNC connector isn’t sufficient to fit through the 1/4"
plastic, you will also need to carefully drill the BNC connector hole, first with a
1/2" center-point wood bit to about half the thickness of the plastic (from the front)
to fit the shoulder of the BNC connector, then with a 3/8" center-point wood bit to
fit the threaded shaft of the BNC connector. Check the hole with the connector to
ensure it fits properly. However, remove the connector until you are finished
preparing the rest of the plexiglass.
I mounted the test socket on the top edge of a 3.5" x 1.5" x 0.25" plexiglass. The
dimensions need not be precise, but the 1/4" plastic makes it easy to glue the socket
with a glue gun. The physical shape of the plastic is also left to your imagination. A
1/2" sanding drum on your drill will quickly shape the plastic to whatever shape you
finally decide on. For storage purposes, I wanted the top of the test socket to match
the height of the plastic over the BNC connector.
Once the shape of the plastic is satisfactory, drill the holes for mounting the
plastic to the side of the wood base and for the ground wire of the test socket. I
found it easier to solder the necessary wires to the test socket, then mount the
socket to the plastic using a glue gun. Next mount the BNC connector. Finally, solder
all the wires to the circuit board, including the two from the battery holder, if
used.
Mount the circuit board to the wood base using spacers from an old BIC (tm) pen or
similar plastic tube, and 5/8" #4 screws (mine came from old VHS tape shells).
Mount the full size crystal oscillator using pins 1, 7, 8, and 14 of the test socket,
with the dot closest to the handle (pin 1).
Mount the half size crystal oscillator using pins 4, 7, 8, and 11 of the test socket,
with the dot closest to the handle (pin 4).
Mount the two-pin crystal cases between pins 7 and 8 of the test socket. They do not
require separate power, but remember, these are bidirectional, meaning they can be
mounted in either direction.
Troubleshooting:
If your counter shows a strange frequency initially, enter setup mode to set the
frequency offset to zero (it sometimes happens that PIC programmers don’t erase the
EEPROM where the frequency offset is stored).
While writing my article on using the DSO138 Oscilloscope Kit, found an issue with our
DL4YHF2 Frequency Counter becoming unstable when displaying certain frequencies from
my XR2206 Function Generator (another kit). So, let me describe the experimental
setup, then the solution.
As you can see, I’m using our DL4YHF2 Frequency Counter, our XR2206 Function Generator
(set for a 40.5 KHz square wave), and our new DSO138 Oscilloscope to show the
waveform. However, when I first put this circuit together, I was very disappointed
with the DL4YHF2 Frequency Counter. While the oscilloscope showed that the waveform
was nicely square and stable, the frequency counter would not stabilize, if I got a
frequency at all. Yet, when I used the frequency counter to test an oscillator, it was
nicely stable at the correct value.
Looking at the circuit diagram for the DL4YHF Frequency Counter, I saw that the
circuit for the crystal & oscillator tester used a 0.1 uF capacitor to eliminate any
unwanted DC voltage. But for the input of external frequencies, a capacitor was not
included. Perhaps a cyclic DC voltage was confusing the counter? So, on a whim, I
included a 0.1 uF (104K) capacitor (type is not critical) at the output of the
generator.
The capacitor fixed the unstable counter, as you can see - a nice solid 40.508 KHz
display, but the waveform was distorted by the charging and discharging capacitor.
I moved the 0.1 uF capacitor to the input of the frequency counter, between the input
jack and the circuit board, as shown...
Thank you.