Tuesday, September 27, 2011

Checking out the Pierce oscillator

The Pierce oscillator is a very simple circuit and as with the ring oscillator also uses inverters (actually just one inverter will do). The principle of operation, however, is very different. While the ring oscillator exploits the incremental propagation delay through the series of inverters, the Pierce oscillator puts the inverter/gate into the linear region of operation and employs it as an analog amplifier.

To find out the details of the gate-based Pierce oscillator I recommend reading the references listed below. What follows is just a summary of the tips and formulas culled from the said references, pointers and tidbits which I found useful in getting a crystal-based oscillator up and running. I also did a number of breadboarded experiments and the results are shown below.

The following schematic shows the basic Pierce oscillator based on a CMOS inverter as its amplifier.


INV is of course the inverter (buffered or unbuffered). Oscillator signal is taken from the inverter output (Vout). To improve (decrease) its rise/fall time, another inverter or, better yet, a (fast!) Schmitt trigger can be used to spruce up the signal. The signal at the inverter input is a sinusoid and can also be used (some Microchip MCU datasheets show the clock signal being derived from the input of the inverter while other Microchip datasheets show it being taken from the inverter output).

Rf is a feedback resistor that puts the gate in linear (as opposed to digital) mode operation. The following table provides a rule of thumb value for Rf given crystal frequency:


Among other things, Rs limits the amount of crystal drive--increasing Rs decreases drive. A ballpark figure or first cut value for Rs can be derived by computing for and equating Rs to the reactance of Cb:
Xcb = 1/(2πfCb), where f = crystal frequency
According to Microchip:
Rs is typically 40 K ohms or less, but is almost never more than 100 K ohms. If the value for Rs is too high, then the high impedance input side of the amplifier may be more susceptible to noise, very much the same way a pull-up resistor on an input pin is normally kept below about 50 K ohms to prevent noise from having enough strength to override the input.
Freescale (Motorola) meanwhile claims that for low frequencies such as 32.768kHz watch crystals, Rs can go as high as 330Kohms. Because of a permissible maximum drive of just 1µW, a minimum Rs value for tuning fork crystals such as the 32.768kHz crystal is 10kohm.

Ca and Cb along with Rs and XTAL provide a 180 degree phase shift (INV provides the other 180 degrees for a total of 360). Moreover, the Rs and Cb network partly "acts as a low pass filter that discourages the crystal from running at a third or fifth harmonic, or other higher frequency" (Lancaster and Berlin). Increasing Ca and Cb decreases the gain. Ca and Cb are usually equal but Cb can be made larger than Ca. The voltage at the input of INV is (partly) determined by Cb / Ca, so that increasing Cb relative to Ca increases the voltage at INV input. As a rule the values of Ca and Cb should satisfy the following condition:
Cload = (Ca)(Cb)/(Ca + Cb) + stray capacitance
where Cload is the load capacitance of the crystal as per manufacturer's specifications. Typical load capacitances are 12 pF, 15 pF, 18 pF, 20 pF, 22 pF and 32 pF.

Finally, an advice worth keeping in mind: "Oscillator design is an imperfect art at best. Combinations of theoretical and experimental design techniques should be used." And so we move on to the experimental side of things.

I performed a few tests on a breadboard using 4.000 MHz and 32.768 kHz crystals. The values for the resistors and caps are the ones I arrived at after some trial and error. The values below seem to work better. Yes, that's a very subjective assessment and shall leave it at that.


I. Motorola MC14049UBCP hex inverting buffer

A. XTAL = 32.768 kHz
Rf = 10Mohm
Rs = 100kohm
Ca = 33pF
Cb = 50pF

Oscilloscope setup
Channel 1 (yellow) hooked up to INV2 output
Channel 2 (cyan) probe hooked up to Cb


CH1: INV2 output
CH2: INV1 output


CH1: Cb
CH2: INV1 output



I increased the capacitances as follows
Ca = 18pF
Cb = 100pF
and I was pleasantly surprised to see that the waveforms became much more stable--it practically ceased "wiggling" (the frequency was stable but the duty cycle wasn't and so the falling edge would be shifting rapidly to and fro horizontally--I was triggering on the rising edge so that wasn't moving at all)

CH1: INV2 output
CH2: Cb


Notice how the increasing the Cb to Ca ratio has decreased the signal's amplitude at Cb.


B. XTAL = 4.000 MHz
Rf = 5.1Mohm
Rs = 2kohm
Ca = Cb = 18pF

CH1: INV2 output
CH2: Cb


The CMOS 4000 series is relatively slow. In the reading above rise time is almost 37ns.

CH1: INV2 output
CH2: INV1 output


CH1: Cb
CH2: INV1 output



II. National Semiconductor MM74HC02N quad 2-input NOR gate. Unfortunately, I don't currently have any CMOS HC or AC series inverters.  According to the datasheet each NOR gate is buffered as follows:


Using a buffered gate in a Pierce oscillator consumes less power and has a gain in the order of thousands compared to an unbuffered gate which has a gain of hundreds. The drawback of a buffered gate is that it is more sensitive to the values of the passive components and tends to be less stable.



A. XTAL = 32.768 kHz
Rf = 10Mohm
Rs = 51kohm
Ca = 33pF
Cb = 100pF

CH1: NOR2 output
CH2: Cb


I believe the over- and undershoots (at the rising and falling edges) is confusing the scope. In the screenshot above it's 40.98kHz, but in real time it's all over the place, sometimes reaching as high as 80kHz. So I turned on the cursors. As you can see it says 32.89kHz. Resolution is such that moving the cursor just one pixel down results in a reading of 32.68kHz.

To obtain a slightly better reading I sent the INV2 output to a Goldstar FG-2002C function generator / frequency counter. The LED display has a resolution to two decimal places and said the signal was 32.77kHz. I guess the output is pretty close to the crystal's fundamental frequency. The frequency counter apparently loads the INV1 output because connecting it directly produces garbage readings (bounces around from 40 to 65kHz). A minimum of 15 ohms of resistance or a few picofarads (the smallest I have right now is 18pF) of capacitance in series is enough to satisfy INV1. The reading is the same as probing INV2 output.

CH1: NOR2 output
CH2: NOR1 output


CH1: NOR2 output
CH2: VDD


CH1: NOR1 output
CH2: Cb


Changing the time base and capturing those overshoots/undershoots:

CH1: NOR1 output
CH2: Cb
Trigger: rising edge, 1.0V


CH1: NOR1 output
CH2: Cb
Trigger: falling edge, 4.0V



B. XTAL = 4.000 MHz
Rf = 5.1Mohm
Rs = 10kohm
Ca = Cb = 33pF

CH1: NOR2 output
CH2: Cb


CH1: NOR2 output
CH2: NOR1 output


CH1: Cb
CH2: NOR1 output


It turns out that the scope probe might be (largely) responsible for the ringing in the output. When not probing either INV1 or INV2, VDD has much less ripple and the ripple in Cb signal practically disappears:


CH1: Cb
CH2: ground


CH1: NOR2 output
CH2: VDD


CH1: Cb
CH2: VDD



References:

Friday, September 23, 2011

Taking a look at basic ring oscillators

Just playing around with ring oscillators cobbled up using a number of basic CMOS gates. Measured VDD of the linear power supply = 5.07 to 5.09V for all circuits. Circuits were assembled on a solderless breadboard. Interconnect wires varied in length. And the relatively long interconnects--compared to the short traces had these been fabricated on a PCB--almost surely affected performance and the characteristics of the oscillators.

I. First up is the Fairchild CD40106BCN hex Schmitt inverter. According to the datasheet its maximum propagation delay = 400ns at 25°C and VDD = 5.0V. Its maximum rise/fall time (transition time) = 200ns at 25°C and VDD = 5.0V. This oscillator has the lowest frequency among those tested. But its output is also the closest to looking like a square wave. Numbers in the schematics refer to IC pin numbers


I measured the output at the various pins to see how transition time would be affected--wanted to decrease it to make the wave as square as possible. The most significant effect occurs with the very first inverter after the oscillator. However, as you can see below, having inverters to "clean up" output after the oscillator has an impact on frequency as well.

Output at pin 8:

At pin 2:

At pin 4:

At pin 6:


II. Motorola MC14049UBCP hex inverting buffer. After discovering how lousy the output of a 3-inverter configuration was I tried a 5-inverter one. As you will see there is improvement but it isn't that remarkable, even if the frequency is almost halved.

At room temperature and VDD = 5.0V, maximum rise time of the 4049 is 160ns, while maximum fall time is 60ns. Maximum propagation delay for low to high transition = 120ns. For high to low max propagation delay = 60ns.

A. Using 3 inverters:

Output at pin 15:

At pin 6:

At pin 4:

At pin 2:


B. Using 5 inverters:

Output pin 4:

At pin 2:


III. If I had them in my inventory I would've tested a 74AC hex inverter and Schmitt trigger, but the only part I have that comes close is a National Semiconductor MM74HC02N quad 2-input NOR gate. Datasheet says it has a maximum propagation delay of 18ns at 25°C and VDD = 4.5V. Maximum rise and fall time = 15ns at 25°C and VDD = 4.5V.  With those specs, it's easy to see that the 74HC line is ultrafast compared to the jurassic 4000 series. However, its transition time to propagation delay time ratio isn't good enough to produce square waves. Actually the output is close to a sine wave. In fact, as can been seen in the scope readings, its rise and fall times aren't even short enough for the output to reach VDD or ground.



At pin 10:

At pin 13:

Friday, September 16, 2011

A very noisy table lamp

Using the ATX switching power supply I was testing a circuit consisting of a PIC12F1822 and SN75176 transceiver, plus a couple of LEDs. The circuit has 10uF filter caps and the MCU has a 0.1uF bypass cap. Much to my chagrin the fluorescent lamp on my bench was affecting the circuit--the MCU would sometimes do a power-on reset when I turned the lamp on or off. The desk lamp has an electronic ballast/starting circuit and has an 18-watt circular fluorescent tube. Adding more caps--100pF, 1nF, 10nF, 100uF--were for naught.

To find out how what the heck was happening I hooked up the oscilloscope to the power rails. I was horrified by what I saw.






The transient would sometimes reach 20V peak to peak! Fortunately it would last for less than 20us. To determine the frequency, I turned on the FFT. As you can see below the range is between 20 to 100Mhz.








I wondered whether a linear power supply would be immune to the transients. I hastily cobbled up one using a 220VAC to 12VAC transformer, W01M bridge rectifier, 470uF filter cap, 78L05 5VDC voltage regulator and a 200-ohm resistor as load. Here are scope readings:







Most of the noise is in the range <40Mhz. The amplitude of the transients seem less than for the ATX supply. However, this supply wasn't connected to the MCU circuit. That may have had an effect.