Logic Circuit Simulator
The Repo

About Project Bit

The goal of this project is to create a logic simulator that is accurate enough to build a working 8 bit computer that runs in near realtime. The components available in the simulator should be similar to components you would be able to buy in real life.

Language:C#
Type:Unity3D
ScreenshotAn 8-Bit counter with a clock
Screenshot 2
Screenshot 3

How It Works

The Basics

Components

The basis of the simulator is built on components and breadboards. Components are of six main types: 1. Wires: Connect pins of the breadboard together. 2. Basic Gates: Sets of simple AND, OR, XOR and NOT gates. 3. Special Chips: Includes clocks, adders and counters. 4. Memory Chips: EEPROM and Ram chips are part of this group. 5. Inputs: These are different types of switches that can be controlled manualy. 6. Outputs: Includes LEDs and 7-Segment Displays

Breadboard

These components can be placed on the breadboard the same way you would place them on a real breadboard. Such as Integrated Circuits being placed accross the center divider. These components are all based on integrated circuits and components that can be bought in real life.

The breadboards main purpose is to connect all these pieces together. When a component's output value has changed it sends an update to the breadboard, the breadbaord then updates the pin's value (High, Low, Unknown). It then propagates this update to all connected pins, in the same row and through wires. If a pin value is changed (High to Low, Low to High), the breadboard will then queue up all connected components to be updated. Each frame the breadboard goes through this queue calling the update function on each component which in turn may trigger this whole process again.

Into The Weeds

Integrated Circuits (IC)

The main wrapper object for all of the circuit components is the IntegratedCircuit object. This object connects the chip/gate/other logic to the breadboard component. The IC has arrays for the input and output values. It also contains references to the nodes/wires that it is connected to. This allows the IC to update it's inputs on on demand and propagate the output values to other ICs and nodes. This object can be created with any number of pins allowing for more customization.

The IC object does not care about how it's outputs are changed based on its inputs. The IC is only aware the output values that change after it calls it's InternalUpdate method. This InternalUpdate value can be tied to anything from a Chip object, Gate object or even a Unity GameObject reference.

This object also has a few other features such as dedicated Positive and Ground booleans to allow for resetting all internal/child states. These components are versatile and can be used fro everything from Chips to LEDs, and even wires.

The following code is an example of the mapping for a Quad Xor Gates Integrated Circuit.

PQ030G_XorGate.cs

Chips

The next layer down from IntegratedCircuits are Chips. Chips are wrappers for collections of other chips or gates and wires to connect them all. The update method passes the input values to the input of the internal chips/gates. It then takes the output from those and propagates them to the next gates/chips in line based on how the wires are connected between them.

This method of chip structure allows the creation of new chips from real world circuit diagrams. In addition to gate based simulation, the chips update can be used for logical updating where the output is set based on a logical function rather than building everything out of gates. This allows for easy creation of more complex chips such as EEPROM memory or registers.

The following code and image are equivilant once the input/outputs have been mapped with a IntegratedCircuit object.

Quad_Xor_Gates.cs
Quad XOR Chip

Gates

Gates are the most basic object that chips and integrated circuits are made out of. These include AND, NAND, OR, NOR, XOR, XNOR, NOT, and buffer gates. Most gates can are defaulted to two or one input and one output, but the number of inputs can be specified for gates such as the NAND gate.

ANDGate.cs
© 2019 Andrew Polk