How to allow exactly only one of two inputs at a time

Thread Starter

Blaizer

Joined Oct 18, 2020
12
To answer some more questions, denouncing is not required, but I’d probably only try it if I used an MCU, otherwise it would be too hard-coded. Displaying the output is also not required, but hey, maybe one day I’ll want an RGB controller that lights up when you hit the buttons...

I wrote out the 16 states and made it into a circuit, but perhaps I did it wrong because it just lead to oscillation. I think it’s because the next state doesn’t depend on the current state of A’ B’, otherwise there’s no way to tell when a button has just been pressed. I think the next state depends on the last button that was held down before both were pressed together.If that sounds a little imprecise, it’s exactly what ronsimpson/kjeldgaards circuit gives. I was actually successful in getting a mostly working solution starting with this as a base, however it oscillates when both buttons are pressed simultaneously.

I think if I go back and use the ronsimpson circuit as the output for the extra columns in the truth table, I can get the right answer.
 

Thread Starter

Blaizer

Joined Oct 18, 2020
12
Ok so I went back and tried again to make a more stable circuit that has a defined result for when you press A and B simultaneously. I started with trying to make a stable variant of ronsimpson's circuit. Here's the truth table for that (the output is As and Bs which stands for stable, the previous output is Ap and Bp).

ronsimpson stable:
1603158445646.png

That's not the correct answer yet, though, because that's just the circuit where A does nothing while pressing B, and B does nothing while pressing A. What we want is the opposite of that, but we can use As and Bs in the next truth table for the final result:

final result:
1603158714031.png

Plugging that in, I got these simple results:

As = A(~B + ~Bp)
Bs = B(~A + Bp)

A' = A(~B + ~As)
B' = B(~A + As)

And here's the circuit for that:

1603158800622.png

Which works nicely. Weirdly enough, though, when I stop the simulation, set both A and B to 1, then start the simulation, to simulate pressing both buttons at the same time, I still get oscillation. Not sure if I still don't have it quite right, or if I'm using the program wrong...

I've attached the logisim file if anyone's interested.
 

Attachments

Thread Starter

Blaizer

Joined Oct 18, 2020
12
As and Bs is just the output of the circuit that ignores B while you're holding A, and ignores A while you're holding B, basically the circuit that ronsimpson posted. X is undefined since it shouldn't be possible. In the first table, the last row is X X, because the last output of the circuit could never be 1 1. In the second table, the X X are on every row that As Bs is 1 1, because that can never happen.
 

Thread Starter

Blaizer

Joined Oct 18, 2020
12
Well, I finally got a working solution with no oscillation problem. The realisation came from Kjeldgaard's post, which showed a circuit that was equivalent to ronsimpson's one, but using only NAND gates. Seeing the NAND gates, I immediately recognised the setup as an SR Latch, but then inverted.

Untitled.png

Knowing that we basically need an inverted SR latch as the first half of our circuit, then the output of that to go into the second half, I finally came up with this (logisim file attached again):

1603182094954.png

I inverted the inputs before going into the SR Latch, without realising that's different to what's in the first image, but turns out the result is the same.

So yeah, finally got a working solution. It probably still has some timing issues where when you press one button while holding the other it outputs both for a few nanoseconds before correctly outputting just one. But hey, it's cool that I can actually build it now and test that on an oscilliscope or whatnot.

I'm not sure if I'll ever be able to fix all the tiny timing issues with just discrete logic, and no clock, so I'm now leaning the other way to thinking I should use an MCU! In any case I'm happy I finally figured this out! It's been nagging at me for days. Thanks to andrewmm for setting me on the right track with adding the extra 2 states to the truth table.

But anyway, even though I've got this, I'd still love to see your assembly code, jpanhalt, since I am now leaning towards just ditching the 4021 and going with a single MCU for everything. And also anyone else's thoughts on either of these two solutions.
 

Attachments

Last edited:

Thread Starter

Blaizer

Joined Oct 18, 2020
12
Oh and sorry for the triple post, but just so I'm not spreading misinformation, lemme correct myself. That double NAND setup is actually not an SR Latch, it's a ~S~R Latch (imagine that's an overline over the SR). That means the inputs are actually low instead of high to the two NANDs in order to do the set/reset.

That's why I invert the inputs before going into the SR latch, because what I need is basically a ~S~R latch. I may be totally wrong about this part, but I'm pretty sure the first thing about the NANDs is correct.
 
Top