Author Topic: Digital Circuit Simulator  (Read 3283 times)

0 Members and 1 Guest are viewing this topic.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Digital Circuit Simulator
« on: December 07, 2021, 08:33:55 pm »
Hello all, time for a mega-post.

Intro:

I was recently motivated to code something that produces much more than it assumes. Projects like this are usually more egg-headed, like creating programming languages, experimental computation paradigms, cellular automata, and so on. After fiddling with each of these for a while, I settled on something that should have been obvious from the start: binary circuits. After all, these are what computers are made of, so I should be able to simulate these kinds of things on a computer.

Remarks:

After deciding on a proper data structure, the evaluation algorithm turned out to be quite simple to code. This thing works for highly parallelized, feedback-ridden, super ugly circuits, as well as pretty circuits. In fact, it's behavior is... dare I say 100% like what you get on a breadboard. I know this because I scoured YouTube for good videos, some of which are linked in this study, for working examples of known circuits. To my delight, the program I've got can easily handle any test I throw it. By "handle", I mean get *exactly* what the real circuit gives.

The reason I gather you here in this thread is not only to show off this program, but to offer a self-teaching crash course in digital electronics. (See the link below.) I had a lot of fun rediscovering precisely how data latches and other computing essentials were done.

More Remarks:

So far, I've tested the heck out of "static state" circuits, along with "edge detection" circuits. We all know that *real* electronics depend on some rather subtle principles, yet this program ignores things like capacitance, inductance - even resistance, because we never had to worry about these in the first place. We're strictly making logic circuits, where if you test for voltage at any place, you'll find a 0 or a 1, no exceptions.

The code takes zero shortcuts to simulate circuit state and edge detection - there is no use of the timer, internal variables, cheat variables, loops, recursion, nothing. Everything is done with a minima of components, namely six: AND, OR, NOT, NOR, XOR, and Split.

Example:

For one example, of which there are a total sixteen in the program, we simulate the four-bit adder, thereby creating a primitive "computer" out of logic gates. Observe the following schematic and program screenshot:

 
Example10Diagram.png


 
Example10Screenshot.png


Manual:

To understand what's going on here, it's highly recommended that you read the manual. I drafted this thing in Notepad with no spell check, so it's subject to updates. Anyway, on this page:

http://barnes.x10host.com/pages/Logic-Circuits.php

... you'll see how circuits are modeled, how they're evaluated, and how the user interacts with the circuit. This program is exceedingly simple to use, and designing circuits turned out to be not as daunting as initially believed. I'll refrain from further explaining anything here, and defer to the above link for all elaboration.

Closing Remarks:

While this program is a perfectly nice breadboard simulator, it begs to be expanded in any number of directions. Surely it needs a GUI. Surely it needs more inputs and outputs. Surely it needs a better way to skirt the arrays-in-types issue. I'm still deciding what the next direction, if any, will be.

Thanks for your attention
* LogicCircuits.bas (Filesize: 53.25 KB, Downloads: 151)
« Last Edit: December 07, 2021, 08:45:46 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Digital Circuit Simulator
« Reply #1 on: December 08, 2021, 11:40:45 am »
this is very interesting, thank yo for sharing :-)

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Digital Circuit Simulator
« Reply #2 on: December 08, 2021, 03:51:43 pm »
Is there such a thing as an IMP logic gate?

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Digital Circuit Simulator
« Reply #3 on: December 11, 2021, 12:04:17 pm »
Whoops, got sidetracked and almost forgot I posted this program. I don't recall ever holding an IMP gate, as in on a physical chip, although they may exist. Once I discovered that not all gates are (for lack of a better word) linearly independent (i.e. some gates don't need to exist at all because they can be built from others), I got over trying to hunt down every species for my electronics collection. That was a while ago though, the collection is gone, so all I get to do now is simulate having a breadboard.
You're not done when it works, you're done when it's right.