In the beginning was television
Surely one or the other has already wondered about the crooked clock frequency of the C64. This is due to the television, or rather the PAL (or NTSC) signal, which is used to transmit the color picture. The PAL (Phase Alternating Line) system was developed as an answer to the NTSC system, which had many weaknesses. Since there are similarities as well as differences in the two TV standards, the clock frequencies on the C64 are also different.
The picture we used to perceive on the old tube TVs, also called full screen, was displayed from two fields. First the odd (1,3,5,7,9,…) and then the even (2,4,6,8,10,…) lines were transmitted. The transmission was displayed with 50Hz, which also corresponds to the mains frequency of the electricity network (NTSC 60Hz, because in the USA the mains frequency there is also 60Hz, with color even only 59.939Hz). Divided by the two fields, this corresponded to 25 full frames per second, or 30 for NTSC (for black and white, for color it is actually 29.9695 full frames per second. With PAL 625 and with NTSC 525 lines are transmitted.
However, only 576 of the 625 lines are visible. The remaining 49 lines, also known as the blanking interval, were used for teletext, among other things. (with NTSC it is 486 visible lines).
If you now take the visible image, this leaves 576 lines that can be displayed on a PAL TV. This results in a horizontal frequency of 15.625kHz.
(refresh rate / 2) * (number of lines) =
- PAL: (50Hz / 2 fields) * 625 lines = 15625Hz
- NTSC: (59.9392Hz / 2 fields) * 525 lines = 15734.4Hz
Without going deeper now, the color clock cycle was set to 283.75Hz plus an offset of 25Hz (NTSC 227.5Hz without offset). If you now calculate the line frequency of 15625Hz * the 283.75 color clock cycles plus the 25Hz offset, you get the following calculation:
Line frequency * color clock cycles =
- PAL: 15625Hz * 283.75Hz + 25Hz = 4.43361875 MHz
- NTSC: 15734Hz * 227.5Hz = 3.57955MHz
A number that you may have heard before. Because this is the color subcarrier frequency.
The VIC – Ruler of Time
Now we multiply this frequency times 4 and look at the result:
- PAL: 4.43361875 MHz * 4 = 17.734475MHz
- NTSC: 3.57955MHz * 4 = 14.31818MHz
And we are already in the middle of it, with the first timer of the C64. Because this frequency is found very close to the video controller (VIC).
As you can see, the small silver component has the numbers 17.734 on it. This crystal is in a PAL model of the Commodore C64. And this crystal has a frequency of 17.734MHz. On an NTSC model, a crystal with the value 14.318 would be found there.
This frequency, or color clock, is the clock for the VIC, the video controller in the C64.
There is a version of the VIC for PAL, as well as NTSC. The resolutions are as follows:
- PAL: 504 pixel x 312 lines
- NTSC 520 pixel x 263 lines
One or the other might have wondered about these resolutions, when there is always talk about a resolution of 320×200. That is correct as far as it goes, but you must not forget the frame around the image.
And the VIC requires 63 clock cycles to build a complete line.
To create a complete image, the following number of bars is needed:
- PAL: 312 lines * 63 clock cycles = 19656 clock cycles
- NTSC: 253 lines * 63 clock cycles = 15939 clock cycles
The VIC has a refresh rate of 50.125Hz, or 59.826Hz for NTSC. This is a bit out of the norm, but it was not a problem with the earlier TVs. Today, some monitors have problems with these values deviating from the norm.
In order for the video controller to be able to display a stable image, it needs a clock that can display the individual points per line according to the resolution.
This is calculated by the refresh rate of the VIC multiplied by the number of dots per line and then multiplied by the number of lines (also called raster lines).
Frame rate * vertical pixels * raster lines = frequency for the VIC
- PAL: 50.125Hz * 504 pixel * 312 lines = 7.882056MHz
- NTSC: 59.826MHZ * 520 pixel * 263 lines = 8.181804MHz
This frequency is generated by a so-called VCO (Voltage Controlled Oscillator), or a double one. This frequency reduces the frequency of the quartz to the DOT clock frequency. And also this frequency is fed into the VIC.
So now we have the third clock in the C64, the DOT Clock. This frequency is also applied to the VIC. With the help of the DOT Clock and the color carrier signal the VIC can display the image on the screen.
What about the CPU?
Unfortunately, the clocks we have seen so far would all be too high for the 6510 CPU. Now the VIC gets the data from the CPU via the data bus. So that this transmission runs synchronously, thus in the clock, the VIC however with scarcely 7.88MHZ with PAL and 8.18MHZ with NTSC is clocked, one cannot clock the CPU simply with 1.00 MHZ.
Signals are read either on a rising or falling edge. If now the two frequencies do not run synchronously, the VIC would sometime read the data from the CPU too early or too late.
And since the VIC specifies the clock on the C64, it simply divides the DOT clock by 8, and outputs this signal as φ0 (Phi0).
- PAL: 7.882056MHz / 8 = 0.98527MHz
- NTSC: 8.181804MHz / 8 = 1.02273MHZ
And this finally brings us to the actual clock frequency of the Commodore C64, the CPU clock. This is only “about” 1 MHz.
Phi0 is fed into the CPU and outputs this signal again as Phi2 for further external components. According to the data sheet Phi2 should be output with a delay of 0.
Phi2 and also the DOT clock are also both found at the expansion port, which are needed for various hardware expansions.
In the picture above, Phi0 is shown in yellow and Phi2 in blue. The picture was taken after the C64 had been running for some time and the components were slightly warmed up.
Unfortunately the signal is not as 1:1 as the datasheet would like to tell you. During this measurement I measured a phase shift of almost 20°.
Unfortunately this is not a static value that applies to all C64s at all times. When cold, the value is different than when warm. And other VIC models have slightly different values again. On my board used here, the value was just under 28° in cold state and went down to just under 20° in warm state.
A phenomenon/problem which I noticed especially when I developed the Z80 cartridge. When it was switched on, it worked wonderfully and then became visibly more unstable until it crashed.
If someone has counted, he should have found 5 clocks in total, which are working in the Commodore C64:
- Crystal: 17.734475MHz (PAL) / 14.31818MHz (NTSC)
- Color Clock: 4.43361875 MHz (PAL) / 3.57955MHz (NTSC)
- DOT Clock: 7.882056MHz / 8.181804MHz
- Phi0: 0.98527MHz (PAL) / 1.02273MHZ (NTSC)
- Phi2: 0.98527MHz (PAL) / 1.02273MHZ (NTSC)
Quite a lot of clocks for one computer. But now it is clear where these values come from and why they are so “crooked”.