# Microcontroller-Based Duodecimal Clock Project

Programmers and embedded circuit designers know that decimal is not the preferred number system for digital devices. Binary, octal, and hexadecimal numbers rule the day, so they’re comfortable using strange number systems. Clocks are essentially duodecimal, or base-12, devices. Devlin Gualtieri designed a two-digit clock that only an engineer would love (and know how to read).

The seven-segment LED displays were mounted on the foil side of a single-sided circuit board. I used single-row, in-line sockets to facilitate soldering. The sockets also elevated the displays above the circuit board and the SMT resistors placed beneath the displays.

In Circuit Cellar 294, Gualtieri writes:

Digital timekeeping has supplanted mechanical timekeeping not simply because it’s usually more accurate, but because it’s inexpensive. Digital alarm clocks are available everywhere for about \$10. You can build the clock in this article for a few dollars more, but with a larger share of satisfaction.

Many years ago, I started designing with Microchip Technology PIC microcontrollers. Since I now have the necessary tools for PIC development, it would be hard for me to change. Fortunately, there’s no reason for change, since PIC microcontrollers are adequate for most embedded designs, and they’re quite inexpensive. This design uses the PIC16F630 microcontroller.

PIC microcontrollers have a built-in oscillator with about a percent accuracy, which is reasonable for many embedded applications. This accuracy comes from digitally trimming an internal resistor-capacitor oscillator on the chip. One percent accuracy is not adequate for a clock, since that would be a quarter of an hour’s error each day.

It is possible to use an inexpensive 32.768-kHz tuning fork crystal with a PIC. This frequency is useful for clocks, since a power of two will divide this frequency to 1 Hz. However, this slow clock rate prevents rapid computation and some useful functionality, so I didn’t use such a crystal in this circuit. Instead, I used a half-sized 10.000-MHz TTL canned oscillator. Canned oscillators are easy to use, highly accurate, and not too expensive.

Seven-segment LED displays are common circuit items, and this clock has a two-digit LED display. One digit is for hours, and the other digit is for the twelfth fraction of the hour. It’s straightforward to display the numbers, zero through nine, on a seven-segment display, but 10, 11, and 12 pose a slight problem. The problem of the twelfth hour disappears when we use zero for that digit. This convention is familiar to most technical people.

In the hexadecimal convention, 10 is represented by an “A,” and 11 is represented by a “B.” A capital letter “A” is easy to show on a seven-segment display, but a capital letter “B” looks just like an eight. As a compromise, we could use a lowercase “b,” instead.

We could also use a capital “E,” for 11, but having an “E” follow an “A” disturbs my hexadecimal sensibility. Although I’m not dyslexic, when I see a “b” on a seven-segment display, I think “six.” Another common notation, which I learned in my elementary school “new math” courses, is to use “t” for 10 and “e” for 11. Figure 1 shows possible number representations for ten and eleven, including the ones I chose for this clock.

Representing 10 and 1 on a seven-segment display. The “t” representations are somewhat abstract, but they can’t be confused with other characters. The last pictured in each category are my choices, since they’re easiest to read.

Gualtieri goes on to describe the circuitry.

One way to minimize I/O pin count in a microcontroller circuit is to use multiplexing whenever possible. If we were to drive each seven-segment display and their decimal points individually, we would need 16 output pins. If we multiplex, we need just nine; that is, eight for the segments and decimal point, and one extra for the digit select.
The segments on the displays need a reasonably high current, and they also need about 4.5 V drive. That’s because they’re 1″ displays with two LEDs connected in series for each segment. For this reason, the display chips are driven from a 12-V supply, and the microcontroller interfaces with two 7406 TTL open-collector inverter/driver chips. Green displays were used, but other colors are available.

Digit select is easily accomplished with two transistors, also driven by sections of a 7406. The 5-V power for the PIC microcontroller and the clock oscillator is derived from a voltage regulator powered by the 12-V supply. A 12-V “wall wart” is a safe and convenient way to power this circuit, which is shown in Figure 2. The maximum current draw for my circuit was 250 mA. The circuit has two buttons for setting the clock by ramping the digits up or down.

This is the duodecimal clock’s circuitry. One nice thing about most embedded systems projects is that the software allows reduction in hardware complexity. The particular displays used were green Lumex LDS-AA12RI displays.

The nearby photo shows the the clock mounted in a custom case. You can see an AM/PM dot and the seconds flashing dot. The time setting buttons are mounted at the rear of the enclosure, but you could place them anywhere. A green filter increases the digit contrast.

The clock mounted in a custom case

The complete article appears in Circuit Cellar 294 (January 2015).

# Measuring Jitter (EE Tip #132)

Jitter is one of the parameters you should consider when designing a project, especially when it involves planning a high-speed digital system. Moreover, jitter investigation—performed either manually or with the help of proper measurement tools—can provide you with a thorough analysis of your product.

There are at least two ways to measure jitter: cycle-to-cycle and time interval error (TIE).

WHAT IS JITTER?
The following is the generic definition offered by The International Telecommunication Union (ITU) in its G.810 recommendation. “Jitter (timing): The short-term variations of the significant instants of a timing signal from their ideal positions in time (where short-term implies that these variations are of frequency greater than or equal to 10 Hz).”

First, jitter refers to timing signals (e.g., a clock or a digital control signal that must be time-correlated to a given clock). Then you only consider “significant instants” of these signals (i.e., signal-useful transitions from one logical state to the other). These events are supposed to happen at a specific time. Jitter is the difference between this expected time and the actual time when the event occurs (see Figure 1).

Figure 1—Jitter includes all phenomena that result in an unwanted shift in timing of some digital signal transitions in comparison to a supposedly “perfect” signal.

Last, jitter concerns only short-term variations, meaning fast variations as compared to the signal frequency (in contrast, very slow variations, lower than 10 Hz, are called “wander”).

Clock jitter, for example, is a big concern for A/D conversions. Read my article on fast ADCs (“Playing with High-Speed ADCs,” Circuit Cellar 259, 2012) and you will discover that jitter could quickly jeopardize your expensive, high-end ADC’s signal-to-noise ratio.

CYCLE-TO-CYCLE JITTER
Assume you have a digital signal with transitions that should stay within preset time limits (which are usually calculated based on the receiver’s signal period and timing diagrams, such as setup duration and so forth). You are wondering if it is suffering from any excessive jitter. How do you measure the jitter? First, think about what you actually want to measure: Do you have a single signal (e.g., a clock) that could have jitter in its timing transitions as compared to absolute time? Or, do you have a digital signal that must be time-correlated to an accessible clock that is supposed to be perfect? The measurement methods will be different. For simplicity, I will assume the first scenario: You have a clock signal with rising edges that are supposed to be perfectly stable, and you want to double check it.

My first suggestion is to connect this clock to your best oscilloscope’s input, trigger the oscilloscope on the clock’s rising edge, adjust the time base to get a full period on the screen, and measure the clock edge’s time dispersion of the transition just following the trigger. This method will provide a measurement of the so-called cycle-to-cycle jitter (see Figure 2).

Figure 2—Cycle-to-cycle is the easiest way to measure jitter. You can simply trigger your oscilloscope on a signal transition and measure the dispersion of the following transition’s time.

If you have a dual time base or a digital oscilloscope with zoom features, you could enlarge the time zone around the clock edge you are interested in for more accurate measurements. I used an old Philips PM5786B pulse generator from my lab to perform the test. I configured the pulse generator to generate a 6.6-MHz square signal and connected it to my Teledyne LeCroy WaveRunner 610Zi oscilloscope. I admit this is high-end equipment (1-GHz bandwidth, 20-GSPS sampling rate and an impressive 32-M word memory when using only two of its four channels), but it enabled me to demonstrate some other interesting things about jitter. I could have used an analog oscilloscope to perform the same measurement, as long as the oscilloscope provided enough bandwidth and a dual time base (e.g., an old Tektronix 7904 oscilloscope or something similar). Nevertheless, the result is shown in Figure 3.

Figure 3—This is the result of a cycle-to-cycle jitter measurement of the PM5786A pulse generator. The bottom curve is a zoom of the rising front just following the trigger. The cycle-to-cycle jitter is the horizontal span of this transition over time, here measured at about 620 ps.

This signal generator’s cycle-to-cycle jitter is clearly visible. I measured it around 620 ps. That’s not much, but it can’t be ignored as compared to the signal’s period, which is 151 ns (i.e., 1/6.6 MHz). In fact, 620 ps is ±0.2% of the clock period. Caution: When you are performing this type of measurement, double check the oscilloscope’s intrinsic jitter as you are measuring the sum of the jitter of the clock and the jitter of the oscilloscope. Here, the latter is far smaller.

TIME INTERVAL ERROR
Cycle-to-cycle is not the only way to measure jitter. In fact, this method is not the one stated by the definition of jitter I presented earlier. Cycle-to-cycle jitter is a measurement of the timing variation from one signal cycle to the next one, not between the signal and its “ideal” version. The jitter measurement closest to that definition is called time interval error (TIE). As its name suggests, this is a measure of a signal’s transitions actual time, as compared to its expected time (see Figure 4).

Figure 4—Time interval error (TIE) is another way to measure jitter. Here, the actual transitions are compared to a reference clock, which is supposed to be “perfect,” providing the TIE. This reference can be either another physical signal or it can be generated using a PLL. The measured signal’s accumulated plot, triggered by the reference clock, also provides the so-called eye diagram.

It’s difficult to know these expected times. If you are lucky, you could have a reference clock elsewhere on your circuit, which would supposedly be “perfect.” In that case, you could use this reference as a trigger source, connect the signal to be measured on the oscilloscope’s input channel, and measure its variation from trigger event to trigger event. This would give you a TIE measurement.

But how do you proceed if you don’t have anything other than your signal to be measured? With my previous example, I wanted to measure the jitter of a lab signal generator’s output, which isn’t correlated to any accessible reference clock. In that case, you could still measure a TIE, but first you would have to generate a “perfect” clock. How can this be accomplished? Generating an “ideal” clock, synchronized with a signal, is a perfect job for a phase-locked loop (PLL). The technique is explained my article, “Are You Locked? A PLL Primer” (Circuit Cellar 209, 2007.) You could design a PLL to lock on your signal frequency and it could be as stable as you want (provided you are willing to pay the expense).

Moreover, this PLL’s bandwidth (which is the bandwidth of its feedback filter) would give you an easy way to zoom in on your jitter of interest. For example, if the PLL bandwidth is 100 Hz, the PLL loop will capture any phase variation slower than 100 Hz. Therefore, you can measure the jitter components faster than this limit. This PLL (often called a carrier recovery circuit) can be either an actual hardware circuit or a software-based implementation.

So, there are at least two ways to measure jitter: Cycle-to-cycle and TIE. (As you may have anticipated, many other measurements exist, but I will limit myself to these two for simplicity.) Are these measurement methods related? Yes, of course, but the relationship is not immediate. If the TIE is not null but remains constant, the cycle-to-cycle jitter is null.  Similarly, if the cycle-to-cycle jitter is constant but not null, the TIE will increase over time. In fact, the TIE is closely linked to the mathematical integral over time of the cycle-to-cycle jitter, but this is a little more complex, as the jitter’s frequency range must be limited.

Editor’s Note: This is an excerpt from an article written by Robert Lacoste, “Analyzing a Case of the Jitters: Tips for Preventing Digital Design Issues,” Circuit Cellar 273, 2013.