On SR latches, D latches, and why most sites get edge-triggered circuits wrong.

So my latest two boards arrived, implementing four demonstration circuits using NPN transistors: a bistable circuit using two transistors (well, four–I need two more to drive the two LEDs), an SR gate using NOR gates, an SR gate using NAND gates, and a D latch: a latch which can be used to store a single bit of data, and most often used as a building block to build a register in a CPU.

I’ve just posted the pages.

And I’m building to something here.

Now I don’t mean to pick on the authors of this web site; I think they did a fantastic job with the artwork and with the explanations of how different types of digital electronic circuits work.

It’s just that the article is dead wrong when it describes J-K flip-flops. A mistake that is made on multiple web sites across the Internet. (Example 1) (Example 2) (Example 3)

Screenshot 2023 01 08 at 9 33 14 PM

Notice the article itself even admits there is a problem with their design:

The JK flip flop is an improved clocked SR flip flop. But it still suffers from the “race” problem. This problem occurs when the state of the output Q is changed before the clock input’s timing pulse has time to go “Off”. We have to keep short timing plus period (T) for avoiding this period.

“We have to keep short timing plus period…”

What? What?

This is utter nonsense. And it was encountering articles like this that motivated me to start up the Hacking Den, and to actually build these circuits, in transistors, and to properly prototype them to make sure they work before posting what is, in essence, nonsense.

It’s why I’m holding off writing articles on NMOS, PMOS and CMOS circuits; I only just got the P-MOSFET transistors, and need to spend a little time breadboarding to verify the circuit works (without letting the magic smoke that allow these things to work escape). And it’s why I’m holding off articles on PNP transistor circuits; for some reason or another the bag of PNP transistors I ordered have yet to arrive in the mail.

Runqsbwxjn561


Getting your circuit to work with edge-triggered logic, by the way, is not just a couple of extra NAND gates and a whole bunch of wishful thinking. You can see how getting a circuit to respond to an edge-triggered signal by looking at the logic diagram associated with the 74LS74 TTL D-flip flop work (on page 3), or the 4013 CMOS D-flip flop.

Just a quick glance at the logic for these circuits in their documentation, and it’s clear there is far more to an edge-triggered flip flop than just some additional NAND gates.


It’s also important to remember that a lot of these circuits did not just fall fully formed from the forehead of Zeus, to grace us as fundamental facts of the universe, like the speed of light, the rising of the sun, or how buttered toast always lands butter-side down.

These circuits were designed and engineered to function according to certain required functionality. JK latches did not just fall from the sky; somewhere someone needed a latch which functioned like a JK latch–and someone designed and built it.

And designed it they did: you really have to appreciate the complexity of a 4027 series CMOS J-K flip flip.

Screenshot 2023 01 08 at 9 41 01 PM

This is hardly the 4 NAND gates in the “clocked SR flip flop” example those various informative–but incorrect–web sites.


Bottom line is you have to prototype your circuits before teaching people the wrong stuff.

Otherwise, what are you but a pretty face spewing garbate?

Different ways to make digital gates.

One of the reasons why I picked NPN transistors to make all of the digital gates in the series of videos I made three years ago was that NPN transistors were cheap on Amazon. I could buy a hundred 2N3904 transistors for around $6.

But they are not the most power effective way to build circuits.

We’ve known this collectively for decades, which is why most modern circuits are made using CMOS circuits–using a combination of N- MOSFETs and P- MOSFETs to create digital gates. You can also create gates using PNP transistors, using only N- MOSFETs and only using P- MOSFETs. In all cases except with CMOS, the single transistor is either ‘on’ which allows current to flow through the transistor, pulling the circuit voltage either up or down (depending on the type of transistor), and when it’s ‘off’ a resistor allows a small amount of current to pull the output value the other way.

The problem, of course, is that when your transistor is ‘on’, power flows from power to ground through that resistor, dissipating heat.

CMOS circuits solve this problem by gating both the power and ground, meaning the only power consumed by your circuit is the power necessary to make the next ‘gate’ activate. There is no resistor draining power to ground in the circuit.

Over the next few weeks I hope to put together samples of these circuits showing a different way to build logic gates than using NPN transistors and resistors.


One interesting thing about all of this, by the way, is that once you have the fundamentals: that is, once you have a working NAND gate, for example, it doesn’t matter how your NAND gate is constructed. You can build the rest of your digital circuits by using that same NAND gate over and over again, regardless of how the underlying NAND gate was built.

I can almost imagine a collection of building blocks about the size of small LEGOs, but each is a NAND gate that can be connected to other building blocks to make these various digital circuits. Because, in some sense, that’s what we’re doing when we make a digital computer: we wire up thousands (or, for more modern systems, millions) of these NAND gates together to make something that appears to ‘think.’

Revising the Hacking Den web site.

So a lot has happened in the past three years.

I found myself with a consulting gig that lasted more than a few months. And of course the pandemic turned the world upside down.

My theory with this site, however, was that the things I build–especially transistor-based digital circuits–were essentially timeless, so it didn’t matter how long it took me to build something.

But over the time the project just fell on the back burner.

My interest has never really changed, however. And recently I decided to pick up the mantle, so to speak, open up my copy of Eagle, run some simulations in iCircuit, and start over from the very beginning.

Thus, the revised version of this web site.

Eventually my goal is to start building a table of circuit references to the left, starting from transistors and moving up to a full system.

I also realized video isn’t really my strong point, so I intend to revamp all of the information as a reference web site instead.

We’ll see how this all works out.

A quick update

So for the past few weeks I’ve been building 1 bit registers. And I mean a whole bunch; 32 to be precise. For registers B through E of our 8-bit digital computer.

And now I’m starting to wire them together.

This is a circuit which implements the entire circuit we described in Introduction to Digital Computers, Part 4.

It’s not quite working yet; I need to finish wire wrapping the back pane, and building a test circuit to put it through its paces.

Splash

But the number of transistors we need to make this have grown, and I’ve filled the original panel almost entirely full. And once it’s done, we can walk through a demo of the circuits actually in action.

Then onto Introduction to Digital Computers Part 5, where we control the circuits with another circuit, building a functional computer, followed by Part 6 where we talk about instruction decoding and decoding strategies.

Quick Video: The Accumulator

A new quick video with a bit of a status update: I now have a working accumulator register tied to my ALU. (I’m also working on the flags register as well as the 4 8-bit registers B through E introduced in the “Introduction to Digital Computers Part 4” video.

This includes video of the ALU in action.


As a quick aside, each board of my ALU contains 66 transistors each, handling addition, subtraction, and, or, xor, not, left-shift, right-shift and passing the bus through to the output, as well as driving the status LEDs.

Each accumulator board contains 37 transistors: 1 to drive the LED, 8 to provide a tri-state gate for writing the accumulator to the bus, and 28 transistors to provide the three S/R flip flips and associated latching logic so we load on the rising edge of the clock line, and present the results to the output on the falling edge. And we need 11 boards total: 8 for the accumulator and 3 for the flags. There is an additional flags logic board which contains 43 transistors providing glue logic to make the flags work with the ALU.

And each register board contains 36 transistors: 1 to drive the LED, 19 for the 2 S/R flip flips making the D-latch, and two tri-stage gates using 8 transistors each; one to output the register to the data bus, and another to the address bus. (This is so we can combine two registers, such as B and C, into a single 16-bit address value.)

Each board now takes me about an hour to assemble–and I’ve got 20 register boards to build, as well as the flags logic board (which should be delivered from Seeed Studio in a couple of weeks, along with a board that contains 8 LEDs which will display the contents of the bus line (so we can see better what’s going on with our circuits than me waving vaguely towards a bunch of toggle switches).


So that’s our update.

I do have the next video outlined; basically I intend to roughly follow the evolution of the control circuits from older computers, starting with the ENIAC–which used a bank of mechanical toggle switches and a mechanical counter to control the circuits that made up the ENIAC’s math circuits and registers. That will progress to using a transistor-based counter circuit and decoder circuits to get instructions, and show how a modified transistor-based counter with data latching abilities can be used for jumps and conditional jumps as we send signal pulses to our registers, accumulator and ALU.


Thanks for watching.

It was bound to happen.

One of the boards I designed simply does not work. Worse, it’s not a simple error: I can’t simply cut one or two lines on the board and run jumpers. Turns out a bunch of resistors were incorrectly wired to power–and cutting them would require so much work it’s easier to basically start over again.

And it was such a rookie mistake, too.

That means my hope for having the accumulator and flags registers connected to the ALU will have to wait a few weeks. Meanwhile I suppose I can start building the B through E registers…

A quick status update to a computer made of transistors…

Why build one when you can build 8, string them together in a primitive card cage and wire wrap the pieces together?

This is the accumulator and the ALU together for the first time. I need to build a test circuit and verify the connections before I video tape this part of the work. And notice I have space for a flags register as well as the B through E registers.

Because I can, and loose transistors aren’t all that expensive…

My accumulator boards just showed up!

They’re nowhere near as complicated as the 1 bit ALU boards, but they do contain the accumulator circuit as discussed in our “Introduction to Digital Computers Part 4 video, along with a single tristate circuit for allowing the contents to be written to our bus, as discussed elsewhere in the same video.

These accumulator circuits are used as-is with the accumulator of our transistor-based circuit, and with additional circuitry for our flags register.

Of course this will take a while to build–and I have another 1,000 transistors and resistors on order (because ordering in bulk is cheap)–so hopefully I will be able to demonstrate a working accumulator with the ALU circuit built earlier.

Fortunately the boards (which implement the logic for a 1 bit accumulator) are not quite as complicated.

IMG 5411

This is starting to get exciting, because instead of just showing addition we can show state, that is, we can show intermediate results being stored away and used for subsequent operations.

Announcing a new Quick Video: Building an ALU.

So this one is a little different; in this video I show the steps to go from the design of an arithmetic logic unit to actually demonstrating a working 8-bit ALU, made entirely out of 2N3904 transistors.

The show notes include links to circuit diagrams and files in case you may want to build your own.

Here’s the video, and thanks for watching.