The clock module
We are going to start this series by analyzing what a clock module or system clock is, why it is used, how the Commodore 64 works in general and why we are going to use another clock module during our study.
What is a clock module?
A clock module is an electronic circuit that oscillates, generating a sequence of repetitive pulses that we will call a clock signal. These pulses are distributed to all the logical elements that we have in our computer so that they are synchronized.
Why is it used?
Because generally our computers work with synchronous logic. The gates or logic gates that we use to operate on the data have a set response time to changes in the inputs they receive, this is called propagation delay.
The interval between clock pulses has to be long enough so that the gates and their outputs are set to stable values before the next clock pulse occurs.
How the Commodore 64 works
Welcome to hell, I mean to how the Commodore 64 clock works sort of. And I say sort of because in this post we are not going to describe the circuit in detail but we will describe some interesting twists and turns.
Let’s start with a crystal called Y1, this gives us a mechanical resonance from which we will reach through several circuits the 1 Mhz at which the 6510 typically runs.
Now depending on whether the computer is NTSC or PAL, the signal frequency will be approximately 14.318 Mhz or 17.73 Mhz, rounding up a few hertz.
This signal is known as the Color Clock Because by dividing these numbers by 4 we obtain 3.58 Mhz for NTSC and 4.43 Mhz for PAL, which are the carrier signals responsible for how we see colors on our televisions.
An integrated circuit known as the U31 Dual Voltage Controlled Oscillator generates other frequencies at 8.18 Mhz for NTSC and 7.88 Mhz for PAL, this signal is known as the Dot Clock and it tells us how many pixels can be written per screen in each screen refresh.
NTSC: 59.826Hz (refresh rate) * 520 Pixels * 263 lineas = 8.18MHz
PAL: 50.125Hz (refresh rate) * 504 Pixels * 312 lineas = 7.88MHz
Finally we arrive at the System Clock which defines what a CPU cycle is, as the Commodore 64 is an 8-bit machine, this limits us to displaying up to 8 pixels per CPU cycle, which corresponds to a cycle length of one eighth of Dot Clock.
NTSC: 8.18MHz / 8 = 1.023MHz
PAL: 7.88MHz / 8 = 0.985Mhz
Reaching the maximum speed of 1Mhz for our 6510.
Why do we use another clock in our study?
If we used a 1 Mhz clock it would be very difficult to see what happens on the CPU for each instruction in our program. The instruments we use to measure could not easily detect the variation of bits or electrical impulses on the address bus pins and we would not understand what happens at each step.
That is why we have a clock that allows us to stop the ball and go slower, as slow as we want, even by pressing a button we will go clock cycle by clock cycle and instruction by instruction.
How our clock works
We are going to use the clock from the Ben Eater ki, if you do not know about Ben Eater go check him out we are inspired in their excellente videos to write this articles and create this series.
This clock works with three 555 timers and some AND & OR gates, in the references I leave you the details of how he puts it together in his videos.
This clock allows us, through a switch, to decide if we want to go step by step through each clock cycle by pressing a button or use a potentiometer to give the speed of the instructions.
To visually see how the clock module works and how we run the oscilloscope to analyze its variations, I leave you the first video of the series
6502 vs 6510 Manual Clock Module — Part 1
References
Below I leave you three excellent articles that talk in depth about the Commodore 64 clock.
Hardware Basics Part 1 — Tick Tock, know your Clock — Dustlayer
Hardware Basics Part 2 — A Complicated Relationship — Dustlayer
And How to Build the Clock Module by Ben Eater.