Tuesday, February 20, 2024

A Few Evenings with Logisim

 It's been raining like crazy and I am waiting for the last round of boards to come back, so I spent a few evenings and weekends trying to learn a bit about logic design.  

I have a junk box full of CMOS DIP IC's; I could breadboard experimental logic circuits but I hate breadboarding.

Instead, I started up Logisim Evolution, a fantastic and free logic simulation program, which I will abbreviate as "L-E" going forward.



Aside: Evolution is a fork from the original Logisim--there is more information online about Logisim vs. the L-E fork. The UI has changed in L-E, but for what I've seen so far the 2 versions are pretty interchangable; if you read or see a tutorial about one you can generally apply it to the other.

L-E: What Can (and Can't) You Do?

Good news--If your circuit can be realized with 1's and 0's you can probably simulate it in L-E. 

However, as far as I can tell there is no analog anything in L-E--no ADC's, no DAC;s, no op amps, no resistors, no caps, no analog scopes.

In spite of this limitation, or maybe taking advantage of it, I found some amazing Logisim and L-E creations online. 

One of my favorites is here; this guy seems to have not only simulated his own 16 bit CPU and PC, but also created a primitive operating system for his sim. Wow! 

Where to start?

I knew pretty much zilch about logic design, so, for me? Anywhere.

I started emulating some CMOS IC's I used frequently, such as the CD4051; I have read the datasheet and have successfully designed 405x's in working circuits, but, how do these IC's really work?  

My 4051 Sim. There is a mux simulator tool in L-E; I could have used that for the 4051; instead as an exercise I primarily used AND gates.

Running some test signals through this "IC" it seems to work. Off to a good start....

New Idea--Transmission Gates

OK with some understanding of basic gates (a good summary is here) I felt some improvement--from newbie to "a bit beyond Newbie" perhaps?

What next? 

Again: anything.

"Transmission gates" were new to me. 

They are sort of like VCA's, FETs or BJT transistors when used as a switch--in a transmission gate, if control data goes North to South, logic can flow East to West.  

I hadn't heard of these before, but digging into datasheets, yes, they are present by the bushel basket in many of our beloved CMOS IC's...for instance on the 4014 datasheet--i.e., below, circled in red:



That's a transmission gate.  

Here's a transmission gate in L-E:

 

Emulating the 4014 datasheet fragment somewhat:

Clock and ClockInv: Feed one side to North, the other side to South. Now, on every positive clock you can pass data through the gate. On negative clock you can't.  

Datasheet Limitations?

Next: I went through more CMOS IC datasheets--most have a logic diagram--to get more IC CMOS favorites working in L-E.  

Bad news--I found that simulating the datasheet's logic diagram sometimes and perhaps often (?) didn't work.  

Apparently whoever drew up the diagram for one logic sheet or another just got the damn thing wrong--some of the diagrams had serious mistakes and/or omissions; not sure if this was intentional--protecting intellectual property, or perhaps multinational IC manufacturers getting lazy?

Regardless, in some cases I had to modify the datasheet's diagrams or start from scratch to get the IC simulation to work. 

You can look at what I've "finished" on github, here--please fork 'em and improve 'em. 

CPU/MPU is Next....

With some CMOS IC's under by belt--next question--could I simulate a basic 8- or 16-bit CPU of my own design?

Having watched all one thousand of  Ben Eater's awesome vids  I felt I had a basic idea of how CPU's work: registers, ALU, busses, memory, mux's etc., so instead of planning I dug in and started simulating. 

Bad idea?

During my logic simulation equivalent of the Dead's space jams I realized I wasn't simulating a CPU--I was trying to make an entire computer:



Jerry's Kids! What I created as of 2-20-24. "CharPU" uses 16 12-bit opcodes, supports (so far) a Program Counter, one 16 bit register, 256 bytes of 8 bit ROM. Works--but--the simulation has a long way to go....

To get this working I needed a "counter within a counter"--to step through, say, the 5 or 6 clock cycles needed to write from ROM to a register.  For this I simulated a ring counter....using simulated D flip-flops.  

Ring Counter simulation. The inverted feedback path creates a "Johnson Counter".  

At this point I started to see some of the limits of L-E:

  • I couldn't assign pins to be an input and output at the same time--see the discussion here. Which means (as I see it): I couldn't easily create bidirectional data and address busses. Apparently this not changing any time soon. This meant I needed a data bus for input abd aniother for output. Extra virtual wiring, but in spite of this, as I see it, L-E remains than breadboarding.
In L-E you cannot have bi-direction busses....
  • Don't expect a lot of I/O from the real world into your SIM. Apparently you can enhance your Sim using TCL ("tickle") but I don't have time to learn a new high level language....
  • it would be nice if the serial I/O could attach to one the host's PC "real" serial ports, but that's wishful thinking. The list of improvements slated for L-E is huge (here) and with everyone clamoring to get more FPGA's working with L-E I doubt anything a newbie audio guy like me,  wanting to see some UART enhancements, will get much attention....but still, serial port I/O would be cool, hook your L-E sim to an Arduino!
  • There is a keyboard simation tied to the host PC's keyboard and a behind glass TTY display. This is very useful. 
  • My big battle has been staying organized. L-E allows for the creation of subcircuits and importing preexisting Logisim libraries, but still, I found keeping everything straight, especially when things started getting complex, being a major challenge--even with the primitive CPU above I struggled with things like consistent tunnel names, zooming in and out, and making things easy to follow and understand.
  • When viewing projects, how come there is a vertical scroll in L-E but a not horizontal one? 


Conclusions--is a life of logic for me?

Maybe. On a different planet/different reality/different universe I could be working for Intel, laying out CPU logic and being happy (and not showering, ever).

Probably.  

Coda...I spent a lot of time with L-E for a few evenings and an entire weekend and it really played hell with my OCD. Little eating; little sleeping, zero breathing fumes, just me and my PC. Something about the reward of seeing the little red lines (doesn't work) in L-E turn green (works) was really appealing. 

My psychiatrist wife is worried--L-E and a life of logic could be dangerous for me. We will see.




No comments:

Post a Comment

JTAG to SWD Converter

Readers: If you'd like to build the project featured in today's post, please go to PCBWAY's Community pages--gerber file, KiCAD ...