A “Better” Crystal Oscillator for the DL4YHF Frequency Counter

TL/DR: I like DL4YHF’s idea of making a frequency counter out of a microcontroller. I don’t like the Colpitts crystal oscillator that my Chinese clone added to it since it won’t work below 5 MHz very well. I made a better one with a 74HCU04 hex inverter an a couple extra parts.

That 400V bypass cap has delusions of grandeur.

In the last post we saw that the ever-popular “1 Hz to 50 MHz Frequency Counter and Crystal Tester” came up a bit short in the “crystal testing” department when it came to testing crystals in the low HF range (< 7 MHz or so). Now, if you really need a crystal oscillator and frequency counter for crystals in this range, I think there is a better way for the money and time, but if you already have one of these things and want it to work with lower frequency crystals, it might be worth doing something like the following. (H/T: ZL2PD had similar thoughts, though his clone has more power in the oscillator and probably does a little better at low frequencies out-of-the-box.)

Two wrongs make a right!

I thought I would try to make a better crystal oscillator (for my purposes) using a 74HCU04 unbuffered hex inverter. Those of you who have ever worked with digital circuits will immediately recognize this as a logic chip. It understands “1” and “0”, or in this case, “5 volts” and “zero volts”. You put 5V on the input and you get 0V on the output. If you put 0V on the input you get 5V on the output. A 74HCU04 is just six NOT gates in a single package. Simple right?

You might be wondering what this has to do with generating what is obviously a very analog crystal oscillator. Philosophical reasoning: if the PIC is trying to interpret an analog signal from a crystal oscillator as digital signal, it only makes sense to use a digital chip as an analog crystal oscillator. Two wrongs make a right!

In all seriousness, you probably realized that the logic described is just what a PNP (or enhancement-mode N-channel MOSFET) switching transistor does, and the 74HCU04 is really nothing more than a collection of FETs. Moreover, this is the internal logic that that most computing chips use for their external clock…like the 20 MHz crystal running the PIC in that Chinese clone of DL4YHF’s frequency counter! We use an unbuffered version of the hex inverter to cut down on gate capacitance, but you might be able to get away with modern buffered chips (74HC04, etc). I’m playing it safe.

Aside: The Idiot learns something

I seem to remember learning that you wanted to tie your unused digital inputs to ground. This kept charges from building up and fooling the chip into thinking that inputs were going high when the were not connected to anything.

This works fine and good unless you forget there are actual electrons involved in this logic stuff, and also to tie your outputs to ground. This is bad. In this case, a grounded input will make your outputs try their mightiest to reach 5V while being shorted to ground. At this point you might wonder why your little CMOS chip is suddenly drawing 300 ma from your bench supply. I’ll remember to leave my unused outputs floating from now on. This is why you buy extras.

The circuit

I made a textbook Pierce oscillator out of one inverter stage and then added two buffer amplifiers. This uses one side of the 74HCU04. If one could use the other side with other circuit constants for testing other type of crystals (watch crystals, IF crystals, overtone crystals, etc.)

The 74HCU04 crystal oscillator and amplifiers using one side of the chip. Not shown, but I used a 10uF and .001uF cap across the the power input.

A very good description of the circuit, what the components do, and design parameters can be found on the Crystek website here. Using this as a guide, I used parts that I found on the floor had on hand. The 1M feedback resistor is what makes this an “analog” device–it essentially changes the gate capacitance of the MOSFETs. This resistor is actually a little low in value; 5M would be better for this frequency range, at least according to the people who know what they are doing. Something I learned from the above: the 500-ohm series resistor is usually touted as a “current limiting” resistor, and it does do that, but according to the above documentation it also provides some needed phase shift at low frequencies (<8 MHz). I had 47pF caps on hand, and this reduces the loop gain a little compared to the ~20pF that one usually sees in this arrangement, but that might also keep down spurs or overtones in some cases. With the various crystals I’m testing there is really no point in trying to match load capacitance (even if we know what it supposed to be). This will bring the frequency of oscillation down very slightly, but it is fine for my purposes. Besides, unless you have calibrated the 20-MHz time base in the PIC you are going to have more error than this anyway.

The second stage is a buffer to bring the waveform up to 5V P-P, and the last stage essentially squares off the waveform a bit and provides a little more isolation for the oscillator. We have them so we might as well make use of them.

Some exciting scope photography

The following show the output of each stage (oscillator, buffer, and amplifier) with crystals at different frequencies. This is just to sanity-check the waveform to see if there is anything amiss. The 10M probe shouldn’t load down the circuit too much.

Traces from each stage with a 1922.5 MHz crystal. Note that there is only 3V P-P in the first trace.

( You know those people who have nice digital scopes that provide nice digital images right to you computer? I don’t have one of those, so I am trying to hold a 10M probe in a breadboard with my right hand while trying to photograph a Tektronics 475A with my left. I have to put my beer down to do this.)

These traces shows exactly why we want an amplifier between the crystal oscillator and the PIC. The oscillator itself is only able to put out about three volts peak-to-peak. This would be on the hairy edge of being able to trigger the PIC’s digital input on its own (or any other standard digital I/O running at 5 volts for that matter). The buffer amplifies the signal to about 5 V P-P, and the final buffer squares off the waveform a bit more. In the end we have a nice sharp digital clock signal.

The same circuit with a 12.3MHz fundamental crystal. As above, the first trace is 0.5V/div for about 3V P-P. The others are 1V/div.

At 12 MHz we see similar behavior. The oscillator puts out a fairly decent sine wave at about 3V P-P. These traces really aren’t any worse in terms of harmonics–it just that the 36MHz third harmonic has a noticeable phase shift in this circuit. Despite the ringing it shouldn’t present a problem to the input of the microcontroller for counting the pulses. As the picture at the top shows, this is all being done in a solderless breadboard with a blatant disregard for leads lengths, so there is plenty of stray reactance to go around. Good enough.

For completeness, here is the output of the final amplifier on 993 kHz and 7 MHz. (The latter was proudly ground and etched from around 6.5 MHz by the Idiot himself!) This shows that we’ve now managed to provide a steady 5V P-P signal from below 1MHz to above 10 Mhz that can drive a digital input. We should have something that will reliably oscillate with those old-time crystals ham-band crystals.

Hooking it up….

In my version of this board, there is a jumper JP1 that connects the PIC’s RA4 to either the output of the crystal oscillator or +5V to use the big terminal connections. I just removed the jumper and put the output of my amplifier direction into RA4 of the PIC (the middle pin of the JP1 as shown below). Since this is a logic level output I didn’t see a need for a DC blocking cap so long as we tie the grounds together. I also didn’t put a 1K isolation resistor ahead of RA4, but that might not be a bad idea. At least the idea works!

You can’t power the 74HCU04 from the “5V” pin on JP1 (the one that goes to the transistor collector on the original oscillator) since there is a resistor between the jumper and the 5V regulator. However, if you tap directly into the regulated 5V output of U1 there is plenty of power to run both the pic and the oscillator. I suppose if you wanted to build it this way you could leave the crystal oscillator off and steal it from the top of where R1 would go.

I’m not going to continue making this pretty. I think I’ll make my own with an arduino and a dedicated oscillator/divider chip designed for the purpose. Stay tuned…

Leave a Reply

Your email address will not be published. Required fields are marked *