# Mechanical CPU Clock

17 Steps

The Mechanical CPU Clock shows the basic building blocks of a CPU (ALU, buses,RAM,registers, and a Control Unit). It executes a set of instructions which will emulate a simple wall clock.
The inspiration for this project came from trying to teach my son and daughter about how a computer works (in reality, I was always fascinated with mechanical computers and clocks, but I had to give a better excuse to my wife for buying a laser cutter specifically for this project). After looking around the web at various mechanical computers, I could not find something that represented all the components of  CPU. However, I draw my inspiration from the following projects (and their derivatives):
Marble adding machine: www.youtube.com/watch?v=GcDshWmhF4A
DigicompII: http://digi-compii.com/
Ball Logic: http://brain.wireos.com/?p=2207

In the following sections I will attempt to explain how everything works as it is being built. I am not going to go deep into the subject of computer science and will purposely try to avoid some terms, so to not confuse the novice reader. If I do use any terms, I will try to explain them simply. However, there might be some needed background information that I will miss, so please do not hesitate to contact me about trying to explain the concepts in more details (I don't promise anything, but I will do my best). Even if you are not going to build the clock, going through the sections will help in the understanding of how the clock/CPU works (the build sections will go over the concepts of ALU,RAM,register,control unit and buses). Again, one of the motivations for this project was to get people to understand how a CPU (the heart of a computer) works.
More details about the clock can be found here: http://www.liorelazary.com/index.php?option=com_content&view=article&id=46:mechanical-cpu-clock&catid=10:clocks&Itemid=15

123D: http://www.123dapp.com/idw-3D-Model/Mechanical-CPU-Clock/604647

Reading the time (http://www.youtube.com/watch?v=iFKargQxN8k):

The time (hour) is read in binary (http://en.wikipedia.org/wiki/Binary_numeral_system) from the middle register (register A, look for the highlight in the video where register A is at). Note the position of the 4 flip-flops (the 4 upside-down red T levers). If a lever is pointing to the right, then the digit is 0, if its on the left then its a 1. Write down the digits from each of the 4 flip-flops, from top to bottom. Then rewrite the number from left to right by rotating 90 degrees to the right, so that the left most digit is from the bottom and the right digit is from the top. For example. If the clock has the flips-flops at this position:

flip-flop 1 pointing left == 1
flip-flop 2 pointing left == 1
flip-flop 3 pointing left == 1
flip-flop 4 pointing right == 0

which is rewritten to: 0111 which is a binary representation of 7 decimal. So the time is 7 o'clock.

To Transform from binary to decimal (the number system that humans are used to):

add 1 if the top dial is pointing to the left or  nothing if its pointing to the right
add 2 if the second dial is pointing to the left or nothing if its pointing to the right
add 4 if the third dial is pointing to the left or nothing if its pointing to the right
add 8 if the forth dial is pointing to the left  or nothing if its pointing to the right

So  the above example translates to: 1 + 2 + 4 + nothing = 7 decimal

Here is a simple conversion from binary to decimal. So if register A has

0000 is 0 but its 12 in the clock case
0001 is 1
0010 is 2
0011 is 3
0100 is 4
0101 is 5
0110 is 6
0111 is 7
1000 is 8
1001 is 9
1010 is 10
1011 is 11

In the video the clock goes through a full cycle, 0,1,2...11 and back to 0, so see if you can follow it.

The minutes can also be read from the position of the ball and the lever (a bit hard to see in the video). The numbers on the outside represent the minutes in HEX format. To convert the number to decimal (the number system we are used to) you take the first digit to the left multiply that by 16 and add the right digit.

Example: 32 in HEX = 3*16+2 = 50 in decimal

00 is 12, 05 is 5, 0A is 10, 0F is 15, 14 is 20, etc.

Remove these ads by Signing Up

## Step 1: CPU instructions

For a CPU to do any meaningful work, it needs to be told what to do. This comes in the form of instructions. For this wall clock I will only concentrate on the hours to make things simple. That is, we will increment a variable named Hours and check to see if its equal to 11 (we will use 0 base indexing for the hours, so 12 is represented as a 0). If the check is true, then we will reset the variable back to 0.  We do not want to code the above statement directly into the CPU, since we want it to be general purpose CPU (otherwise we are just making a clock). Therefore, we will implement a basic instruction set and write the clock code around these primitive instructions (the set of instructions to execute are known as an assembly language). Lastly, we will keep the hour variable in a Register, which is a term given for a special memory component used to hold data and operate on it.  We will also use a simple 1 unit (1 bit) memory address to act as a flag for the control unit, and name it DTD for personal reasons (stands for dedicated to Dani. A long personal story). Note that this CPU will be programed with the clock instructions, but it could be programed with any other code to do a number of other things.

Here are the basic instructions (assembly language) that we will use:
INCRMENT: Increment register A by adding 1 to it.
EQUAL: If register A is equal to a specific number, then skip the next instruction.
CLEAR:  set register A to 0, set DTD to false
JUMP: jump to a specific instruction at a given line number
SET_DTD: set DTD to true
CHECK_DTD: if DTD is true, then skip the next instruction.

Here is the assembly language code for the clock (register A will hold the hours).

1: CHECK_DTD
2: JUMP 5
3: CLEAR
4: JUMP 1
5: INCREMENT
6: EQUAL 11
7: JUMP 1
8: SET_DTD
9: JUMP 1

Line 1 checks to see if DTD is set to true (this is used to indicate if we need to reset the hour). If its true the we jump to line 3 and set the hour to 0 and the DTD to false. If DTD is false then we continue with the next instruction and jump to line 5. Line 5 increments the hour (register A), while line 6 check to see if it equal to 11. If register A is equal to 11, then we jump to line 8 and set the DTD to true and jump back to the beginning (line 1). Otherwise, we go to the beginning. If we run though this code once an hour, then by reading register A, we can tell what is the current hour.
 1-40 of 44 Next »
apage says: Jan 24, 2013. 12:53 PM
What did you use to control the timing and the sweep arm? An existing clock mechanism? Microcontroller?

Thanks
lelazary (author) in reply to apageJan 25, 2013. 2:19 PM
I used a 1RPH motor (I got mine here http://www.herbach.com/Merchant2/merchant.mv?Screen=PROD&Store_Code=HAR&Product_Code=H1-33&Category_Code=SYNCTIME).
Josehf Murchison says: Nov 15, 2012. 12:49 PM
Just plain neat I like it. Looks like fun.
Joe
ihart says: Apr 25, 2012. 1:39 PM
First of all, nice job in implementing this device and showing how it works. Also, congrats on getting the "pass" to buy your laser cutter. ;-)

I think that this is actually a Finite State Machine and NOT a CPU. A CPU fetches instructions from a memory and then takes actions based on those instructions. Actions include jumps within the program counter (PC) space, math operations in the ALU etc.

Your machine includes a set of flip flops representing the "current state". Every time a ball is dropped, the flip flops decide what the "next state" will be based on the "current state" of the machine.

In your description, when you say that your machine is jumping to a line of code, I think you mean that it is jumping to a new binary encoded finite state.

Here is a write up on the differences I found with a quick Google:
http://www.cs.utah.edu/~rajeev/cs3810/slides/3810-14.pdf

lelazary (author) in reply to ihartApr 26, 2012. 6:52 AM
Thanks for you comment.
You might be right that its not a CPU, but not because its a Finite State Machine (because a CPU can be boiled down to a FSM). So first you must define what is a CPU (and there are a few), but the view I take is that a CPU is a Universal Turing Machine (UTM). Which state that a UTM is one that can simulate every possible Turing machine (or every possible FSM). There are one instruction set computers (see OSIC) which are able to simulate every possible FSM, and they don't need to fetch instructions, since they only have one.

This clock can be shown to be a Turing Machine, and thus a computer (see fixed-program computers), however, where is its program memory?
I argue that the program memory is implemented in the paths the ball takes, and is burned in using the laser as well as the configurations of the flip-flops, so its similar to burning the program on a ROM. (although I agree this is a far fetch, but remember that the goal of this project was to help explain what's inside a CPU, and not create a CPU to solve various problems). Therefore, I could change the program of the clock (or change the FSM) by simply rotating one of the L levers or changing the T flip-flops to an L. I could also, remake the tracks of the C register, to check for a different number, or change the B register to increment instead of reset (by changing the L to flip-flops and reconfiguring the paths). Also see the Harvard Architecture CPU which has its instructions separated from the data.

However, the main problem is in proving that the instruction set I provided are able to simulate every possible Turing Machine for it to be a CPU (which I don't believe it does). Note that its not that easy, since there are very simple machines which can be a UTM (http://en.wikipedia.org/wiki/Wolfram%27s_2-state_3-symbol_Turing_machine)

However, even if you don't buy the argument that the program is read from memory (and I agree this is hard to swallow, even for me) or that it can not emulate every possible Turing machine. I still stand by the fact that this is still useful in describing a CPU.
mlah in reply to lelazaryMay 1, 2012. 6:10 PM
Its really stretching it though to say that it is programed though. I can reprogram a finite state machine by slotting in new components too. I feel like the program really should be separated from the processing unit. Reading through it the first time I kept getting confused because you kept referencing lines of code that aren't really in the machine as lines of code. Its a super cool project it just feels like its a little misleading.
ihart in reply to lelazaryApr 26, 2012. 9:16 AM
I think you have handled the religious discussion on what a CPU is quite well. You are not trying to model a Von Neumann computer (http://en.wikipedia.org/wiki/Von_Neumann_architecture) that so many of us are used to.

My thought is that your son and daughter will learn a lot from your device but are more likely to use their understanding of it to become Electrical Engineers with digital logic design skills (VHDL/Verilog on FPGA/ASICs) than Computer Scientists slinging C or assembly code ;-)

Your implementation of a binary mechanical clock is wonderful.
lelazary (author) in reply to ihartApr 27, 2012. 6:59 AM
Either my kids will end up in EE/CS or they will need years of therapy because dad insisted this clock is a computer, but they could never access facebook with it.

In the mean time you can enjoy my 6 year old son trying to explain how to read the clock: http://www.youtube.com/watch?v=iFKargQxN8k
flamekiller says: Apr 28, 2012. 12:31 AM
Very c lever and well implemented. Bravo, sir!
aayaffe says: Apr 20, 2012. 7:49 AM
Incredible!
Brilliant idea, very very nice execution.
Thanks for the detailed instructable!
janw says: Apr 19, 2012. 11:28 AM
This is a really great idea and build!

Also it is a super clear i'ble.

Congrats. This is definately a 5 star project.
Xolin in reply to janwApr 19, 2012. 3:38 PM
www.d-e-f-i-n-i-t-e-l-y.com/
janw in reply to XolinApr 19, 2012. 11:29 PM
Thanks. But remember that English isn't my mother tongue. It is only my 3th language (of the four that I read, write and speak if you don't count Latin and ancient Greek) and I do make a mistake from time to time. A lot of people aren't even able to write theire own mother tongue properly!

I wil definately definatly definantly definetly definently defiantly definitely remeber it.
quakefiend says: Apr 19, 2012. 2:27 PM
what laser cutter did you buy?
lelazary (author) in reply to quakefiendApr 19, 2012. 9:32 PM
Look on my website. www.liorelazary.com. I wrote a whole article of how I imported the laser cutter from china.
andrew.spencer.2 says: Apr 19, 2012. 10:51 AM
Wow, that's really clever! I understand most of it except how to read the minute hand during the first 25 minutes of the hour before it picks up the ball again. Is it visible through the side of the clock or something?
lelazary (author) in reply to andrew.spencer.2Apr 19, 2012. 9:28 PM
Sorry, on the video its a bit hard to see, but you can see the shadow of the arm (a bit better in real life). So it is hard to read the minutes from 0 to 25. For my first prototype I used clear acrylic so you saw the arm much better. However, it made the tracks very hard to see. Someone suggested using a semi-clear acrylic (like a fogy one) so you can see the tracks and the arm better.
Treknology in reply to andrew.spencer.2Apr 19, 2012. 3:47 PM
While I like it, my interpretation leaves 7:15 as the maximum count before resetting to 0:00
Syx in reply to andrew.spencer.2Apr 19, 2012. 2:47 PM
+1 - Can't see how to read the minutes before the ball is picked up again.
seishin says: Apr 19, 2012. 8:27 PM
This is brilliant. I am humbled and blown away. Not only for what this device does, but more so for helping me understand what a CPU does. You: "One of the motivations for this project was to get people to understand how a CPU (the heart of a computer) works" - done, beautifully, unexpectedly; thank you.
snurrberget says: Apr 19, 2012. 7:45 PM
Just fabulous! People like you make people like me teach my kids that the evil professor in Cartoon Networks is somewhere out there in the real world!
Damn good job on a crazy idea! :)
agittins says: Apr 19, 2012. 3:55 PM
Probably the most amazing project I have seen to date, bravo!
Treknology says: Apr 19, 2012. 3:41 PM
While learning to read the time would be a little annoying, I think it's a GREAT demo of simple logic circuits in a very elegant design. This is the stuff of a great 'ible.
r570sv says: Apr 19, 2012. 2:25 PM
Awesome work! Love the idea of the 2nd track!
kaisersuzuki says: Apr 19, 2012. 1:53 PM
I can't even get my kids to eat dinner, let alone begin to comprehend how to read this.
throbscottle says: Apr 19, 2012. 1:52 PM
Completely mad! And utter genius! I salute you sir!
Azzurro says: Apr 19, 2012. 1:08 PM
It's a must for geeks. :) respect.
nwlaurie says: Apr 19, 2012. 11:30 AM
I have total admiration for the depth and persistence of geekery that can produce something like this.
Stunning!!
Obi-Wahn says: Apr 19, 2012. 10:09 AM
Frankly, I have no freakin' idea what you are talking about, but I have to say, even if I don't understand a bit, I think it's the best Instructable AND project I've seen in a while.

I'd take my hat off if I'd wear one ;)

teden says: Apr 19, 2012. 9:10 AM
Reminds me of the joke we use around here - "freaking smart guy, no context though; ask him the time, he'll explain how to build a clock"
kenyer says: Apr 19, 2012. 8:49 AM
great!!! Now I want to make something like that and I have already so many projects waiting for me.
DELETED_jrutherford5 says: Apr 19, 2012. 8:01 AM
(removed by author or community request)
robot797 in reply to DELETED_jrutherford5Apr 19, 2012. 8:22 AM
i wish i had a device like that
it is to eqpencife for me to order the parts
and i cant never afourd a laser cutter

:(
wesday says: Apr 19, 2012. 7:27 AM
Your a freekin genius. Even thoughI don't understand it AT ALL.
MPLS_CBG says: Apr 19, 2012. 7:20 AM
It also reminds me of Dr. Nim. Was that made by Digicomp also? looking forward to a more thurough read through after this darn day job thing ;-)
tamberg says: Apr 19, 2012. 6:30 AM
Absolutely beautiful! Kind regards, tamberg
Dream Dragon says: Apr 17, 2012. 11:45 AM
It is most ingenious, even reading the instructions I'm not completely sure I understand it, but it's really elegant.
odalcet says: Apr 16, 2012. 11:56 PM
A 5 million cubic meters graphing calculator: http://www.youtube.com/watch?v=wgJfVRhotlQ
milsorgen says: Apr 16, 2012. 3:48 PM
This is fantastic!
commodore73 says: Apr 16, 2012. 12:43 PM
Can you implement this as a visual app in software so I can download it? Wait, let me figure out the layers of abstraction there...
 1-40 of 44 Next »