# Oscillator and Power Source Frequency

I've been working through a Nixie Clock schematic, to understand how the clocks function as a whole, and am stuck on how timing works for the PIC microcontroller. The schematic can be found here: http://www.nixieuhren.de/downloads/108b-6.pdf

Why does the microcontroller need both a crystal (in the OSC Pins) and a frequency from the power source (in the T0CKI pin)? Couldn't the microcontroller keep time simply from the oscillator?

Is the frequency from the power source necessary? And if so, why?

• The 60Hz is the time standard. The XTAL merely tells the MCU how fast to provide the state-machine actions. – analogsystemsrf Apr 11 '17 at 4:33
• I think that the signal power source is used to synchronize switching VFD with AC-power network to avoid flicker. Flickering occurs when the external lighting and light VFD have different frequencies. There are open source firmware? – AltAir Apr 11 '17 at 8:03

The issue is the cost of precision.

All MCUs need a fast clock oscillator so they run, but it doesn't matter what this frequency is, within a wide margin. This means you can use a very cheap, uncalibrated crystal, a ceramic resonator, or if you don't need to hit baud rates, even an RC oscillator. If you used this as the timing source, you would get quite erratic time-keeping behaviour as the temperature changed, and as it aged.

The mains waveform is kept accurate, at no cost to you. As the clock needs a mains power supply (too hungry for batteries), you might as well use that. Note that the actual mains frequency varies a little from f_mains (50 or 60Hz) throughout the day. What is guarranteed is that after n periods of 24 hours, there will have been approximately n*24*3600*f_mains cycles, with the error being non-cummulative. In other words, ideal for a wall clock.

From wikipedia Utility Frequency article

Today, AC-power network operators regulate the daily average frequency so that clocks stay within a few seconds of correct time. In practice the nominal frequency is raised or lowered by a specific percentage to maintain synchronization. Over the course of a day, the average frequency is maintained at the nominal value within a few hundred parts per million.[19] In the synchronous grid of Continental Europe, the deviation between network phase time and UTC (based on International Atomic Time) is calculated at 08:00 each day in a control center in Switzerland. The target frequency is then adjusted by up to ±0.01 Hz (±0.02%) from 50 Hz as needed, to ensure a long-term frequency average of exactly 50 Hz × 60 sec × 60 min × 24 hours = 4,320,000 cycles per day.[20] In North America, whenever the error exceeds 10 seconds for the east, 3 seconds for Texas, or 2 seconds for the west, a correction of ±0.02 Hz (0.033%) is applied. Time error corrections start and end either on the hour or on the half-hour.[21][22]

• I can see that the frequency tolerance of the delivered mains is tighter than the +/-10% we always designed PSUs for. UK is +/-1% (www2.nationalgrid.com/uk/services/balancing-services/frequency-response/). But where did you get the 'over time it all averages to 0%-ish error' bit from? Thanks, Neil_UK. – TonyM Apr 11 '17 at 6:29
• @TonyM It's one of those 'I've always known it, but where's a good citation?' kind of things. I'll race you to one. I'm assuming from your comment that wikipedia doesn't supply a reference. – Neil_UK Apr 11 '17 at 7:34
• I know what you mean on the 'always known it' - good thing is moments likes these make us check them, to see if it's changed over the decades since we learned it :-) I wouldn't take Wikipedia as a definite though, people like us write some of that stuff because 'we've always known'. We ought to be certain you're telling the OP a fact though, have you found an authoratative source? If it's used that commonly for clocks, it should be easy enough to find. – TonyM Apr 11 '17 at 7:47
• That snippet has the embedded references in there, 19 to 22, though #20 is 404, I might go in there and edit that. – Neil_UK Apr 11 '17 at 8:06
• @TonyM Fixed up link 20 on wikipedia, but that still only does europe and US, not UK and rest of world. Some continents have trouble keeping the voltage within a factor of two, I wonder how they manage frequency? – Neil_UK Apr 11 '17 at 8:27