Mechanical Boolean Logic

by kebmoore in Workshop > Science

158 Views, 1 Favorites, 0 Comments

Mechanical Boolean Logic

NOT_preveiw_112115.jpg

Almost ten years since my last Instructable? That is long enough. It is time to actually complete a project, not abandon it halfway done.

MOTIVATION:

In 2009, Purdue University gave me a piece of paper declaring me a Bachelor. I found this odd since I was happily married with 2 children. However, the document also said that I was a scientist – a computer scientist. In the years since, I have worked with computers every day, developing tools to control production processes and transform data files. I have not done any real computer science. I didn’t realize this until my son participated in his elementary school science fair. His solar-powered car project was exhibited beside experiments in physics, chemistry, biology and geology. There were no computer science experiments, in spite of the role that computers play in nearly every facet of daily life. Inconceivable!

But what kind of computer science can be done in the average home workshop? Everyone knows that computers are built using microscopic circuits printed on silicon. They use electricity to perform calculations. Manufacturing computer chips requires clean rooms and special equipment and high-purity silicon wafers.

However, let’s look at the more general definition (from Wikipedia): “A computer is a general-purpose device that can be programmed to carry out a set of arithmetic or logical operations automatically. The processing element carries out arithmetic and logic operations, and a sequencing and control unit can change the order of operations in response to stored information.” Note that the definition given doesn’t mention silicon or electricity, even though these are what we think of when we say “computer”. A computer processor is simply an ordered arrangement of logic gates that can be controlled by a set of instructions. Time to do some science – computer science!

GOALS:

My goals for any project and Instructable are simple:

  • Low cost (if you have money to burn, please donate to my early retirement fund)
  • No parts made from unobtainium (a rare element that is either very expensive or only found in a single store in Outer Mongolia, and it's on back-order)
  • Simple fabrication (use common tools, no tool-and-die machinist certification required)
  • Fill a need (okay, sometimes I like to tinker for the sake of tinkering)

Additionally, I want to work with my children on this project, to stimulate a love for learning and building. If we end up with a science fair project, that will be a bonus.

Please note: I am going to prattle on for several pages about my inspiration for the project and the design process that I went through, followed by a bit of theory. Hang in there; we’ll get to the part where I start making the gates soon.

​INSPIRATION:

320px-Difference_engine.JPG
Denha_flipflops.png
marble_adder.jpg
digicomp2.jpg

I have long been fascinated by the work of Charles Babbage. He designed the first programmable mechanical computers back in the 1830s. First the Difference Engine to calculate tables of numbers, and then a general purpose computer, the Analytical Engine. In his lifetime, they were never completed due to funding problems, disagreements with his machinist and a failure to stick with a design. If they had been finished, we might have had mechanical computers a full century before the electronic models of the mid-1900s.

I have also been captivated by rolling ball sculptures and marble runs. The motion of the balls through the different track elements is mesmerizing. A flip-flop can be used to send balls alternately onto two different tracks. Essentially, it is a switch that changes state every time it is “read” by the next ball.

The use of a marble or metal ball with flip-flop gates as a form of mechanical logic occurred to me almost immediately, and apparently to others as well. I found the work of Matthias Wandel, Evil Mad Scientist and Eric Uhrhane, and I marveled at the work they had done. It is time to build on the ideas of others and do some science.

​THEORY:

TOGGLE_STATES_01.png
SET_STATES_01.png
RESET_STATES_01.png
QUERY_STATES_01.png

Any switch could be used to represent a value in Boolean logic. “On” = TRUE or 1, “Off” = FALSE or 0. To be useful, we need to change the state of the switch based on the output of another switch. The early computers used electrical relays or vacuum tubes to run calculations. Modern chips use semiconductors.

The ball logic gates use the position of flippers to represent values. If the flip-flop is tilted to the left, the ball will take the path to the right and tilt the flip-flop to the right. If the flip-flop is tilted to the right, it will take the path to the left and tilt the flip-flop to the left. The output of a ball represents a value of TRUE or 1, no ball represents a value of FALSE or 0.

A flip-flop gate, while useful, may not be sufficient to create the Boolean logic gates needed to make a processor. Eric Uhrhane modified a simple flip-flop by removing one or more arms to change the behavior when a ball rolled through the gate. He named them t, q, s, and r gates for toggle, query, set, and reset. He also realized that levers or pulleys would be needed to transfer gate states up, against gravity. I cannot think of better names, but in my own mind I have decided to alphabetize these as PQRST Logic Gates, for Pulley, Query, Reset, Set and Toggle. By stacking PQRST elements together, we can perform all of the Boolean operations and eventually create a working computer.

The first image shows the behavior of a TOGGLE gate when a ball is input. The initial state is FALSE. When a ball (TRUE) is input at the top of the gate, the ball flips the Toggle to TRUE and exits to the lower right. When another ball is input, the Toggle flops to FALSE and the ball exits to the lower left.

The next image is a SET gate. The initial state is FALSE. When a ball (TRUE) is input at the top of the gate, the ball flips the toggle to TRUE and exits to the lower right. When another ball is input, it exits to the lower left but does not change the state of the switch. The state of the SET gate by itself can only be changed once.

The third image is a RESET gate. The initial state is FALSE. When a ball (TRUE) is input at the top of the gate, the ball exits to the lower right without changing the state of the switch. If the gate has been tipped to the right, it can be switched back when another ball is input. The state of the RESET gate by itself can only be changed if it was initially TRUE.

The last image is a QUERY gate. The initial state is FALSE. When a ball (TRUE) is input at the top of the gate, the ball exits to the lower right without changing the state of the switch. The state of the QUERY gate by itself cannot be changed by a ball moving through. If the gate is set to TRUE, a ball input will be diverted to the path on the left.

The PULLEY (not shown here) is used in pairs, using rigid connections or strings to connect and transmit positions. There are some variations on the PULLEY, depending on whether there are strings on one or both sides of the pair.

​DESIGN:

andgate.jpg
FA2M99DIG5EGDTO.MEDIUM.jpg

If you look online for examples of mechanical binary logic other than those previously mentioned, you will find a few examples, mostly push-pull rod logic (see RandomWraith), or occasionally pulleys (see Blubell). They often suffer from friction and alignment issues, as well as backlash when combining several gates together. Additionally, they are often complex, requiring lots of little parts that require assembly. Since even a small, 8-bit processor would need hundreds of gates, simplicity and ease of manufacturing must be a design priority.

There may be other ways to create gates, but I think the rolling balls will work to solve some of these issues. Alignment should not be an issue, since the balls can roll in any direction except up. Since each gate is toggled independently, there should be no issues with backlash in transmitting a state downstream. While there will be small parts involved, they should be mostly standardized and easy to mass-produce.

Design is not a fast process for me. I think about it. I mull it over. I draw and re-draw my designs. There are notes on napkins, graph paper and random scraps of paper as my mind tries to visualize an elegant solution. My wife rolls her eyes and sighs, but she has learned not to ask the question “What are you thinking about?” when she catches me with a blank look on my face. This process has taken a couple years for this project, as life imposes priorities. In this case, however, an idea has reached a critical mass and will not be denied.

I downloaded and learned to use OpenSCAD. This has been invaluable in iterating through designs, seeing what will work and won’t, without wasting material. The 3D models scattered throughout this Instructable were built in OpenSCAD. Once I had developed a model that looked workable, I used LibreCAD to create the technical drawings to use as patterns. If I had a 3D printer, I could have just exported the models to be printed. Instead, I have a small collection of woodworking tools and some limited skill in using them, so I needed to design this with in mind.

​NOT GATE:

NOT_GATE_STATES.png

The simplest Boolean operation is NOT. If an input value is TRUE, the output is changed to FALSE. If it is FALSE, it becomes TRUE. To model this in ball logic, a Set gate is stacked with a Query gate and a Reset gate on a single shaft. Initially, the gate is set to FALSE, with all of the gates tipped to the right. In the model, the “A” and “!A” labels indicate the value of the ball as it passes through the Query gate. If a ball (representing TRUE or 1) is inserted at the top of the Set, it tips the Query gate so that the query ball runs through the !A path. To reset the gate, a ball is dropped through the top of the Reset gate to tip everything back to FALSE.

In addition to the Boolean NOT, this gate also acts as a buffer, allowing us to query the value later in a calculation. This is a distinct strength of these ball logic gates: you get both the Boolean operation and its compliment at the same time. You simply decide which path to read.

OR GATE:

OR_NOR_TRUTH.jpg
OR_GATE_STATES.png

The Boolean OR evaluates 2 or more inputs and returns TRUE if at least one of them is TRUE. The implementation of OR in ball logic is identical to the NOT/BUFFER gate shown in the previous step. The inputs A and B are both fed into the SET layer of the gate. If one or both of them are TRUE (or 1), the gate returns TRUE when queried.

XOR GATE:

XOR_XNOR_TRUTH.jpg
XOR_GATE_STATES.png

The XOR (Exclusive OR) is very similar to the OR, but substitutes a TOGGLE for the SET gate. Just like the OR, inputs A and B are fed into the toggle. When one-and-only-one of the input signals are TRUE, the output of the QUERY is TRUE. If neither or both of the inputs are TRUE, the QUERY returns FALSE as shown in the truth table shown above.

AND GATE:

AND_NAND_TRUTH.jpg
AND_GATE_SET.png
AND_GATE_RESET.png
AND_GATE_QUERY.png

The Boolean AND operation returns TRUE only if all of the inputs are TRUE. The implementation in ball logic is 2 connected NOT/BUFFER gates. The when a ball is dropped into the QUERY path, the state of input A is evaluated first. If A is FALSE, the ball falls through to the output as FALSE and the state of B is not evaluated. If A is TRUE, the ball is directed to query B. If B is FALSE, the output is FALSE. Only if A and B are both TRUE will the output be TRUE.

The signals for A and B are input from the side of the gate rather that the top because of the vertical alignment of the SET layer. The RESET layer has additional ball paths so that both A and B can be reset with a single ball.

BUILDING THE GATES - MATERIALS:

In keeping with my goals from Step 1, I want to use common and inexpensive materials. I didn't want to use glass marbles because there is too much variation in size and glass isn't very dense. I needed heavy balls of a consistent size. I looked on McMaster-Carr and found Low-Carbon Steel Ball, 3/8" Diameter, Pkg Qty 250 (MC # 96455K54). I chose these