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

#### Blaizer

Joined Oct 18, 2020
12
I'm trying to make a custom DPad for a game console controller. One of the requirements of a DPad is that only one of up/down may be active at a time, and only one of left/right may be active at a time. Usually you would do this with a physical solution, but I'm looking for a solution within the circuit.

So in the most simplest terms, I have 2 inputs A and B, and 2 outputs A' and B'. A usually outputs A' and B usually outputs B', except for the case when both A and B are high. Very simple truth table, the only interesting thing is the last row:

 A B A' B' 0 0 0 0 0 1 0 1 1 0 1 0 1 1 * *
*When A and B are both high, exactly one of A' or B' should be high, and it should be the corresponding input that became high most recently. If both A and B became high at exactly the same time, then the circuit can just bias towards one, I'm not too worried about this case.

So the question is, how would I build a simple circuit like this? I'm using the 4021 8-Stage Shift Register as the base of my controller, with the inputs of my buttons feeding into this. I'd like it to be as simple as possible, probably using a few logic gates and latches.

#### AlbertHall

Joined Jun 4, 2014
11,310
What is the serial output of the 4021 connected to?

#### Blaizer

Joined Oct 18, 2020
12
To the console, in this case an NES.

#### jpanhalt

Joined Jan 18, 2008
11,088
*When A and B are both high, exactly one of A' or B' should be high, and it should be the corresponding input that became high most recently. If both A and B became high at exactly the same time, then the circuit can just bias towards one, I'm not too worried about this case.
The underlined is clear, but is that what you really mean? Lockouts work for FIFO (i.e., first entry determines output). Your case would allow A' until B is pressed, then B'. What happens if A releases and then re-asserts?

Just want to be sure that is what you mean.

#### Blaizer

Joined Oct 18, 2020
12
Your case would allow A' until B is pressed, then B'. What happens if A releases and then re-asserts?

Just want to be sure that is what you mean.
Yes, you always get either A' or B' when both A and B are held, and always the last one pressed. So if you hold A, then hold B, you get B'. Then when you release A and press it again you get A'. Hope that's clear!

Last edited:

#### jpanhalt

Joined Jan 18, 2008
11,088
That can be done easily with the simplest MCU, but for that you would need to define a maximum time difference that would be "simultaneous," as everything is clocked. At 32 mHz, 8-bit PIC's can execute one instruction every 125 ns.

Even with discrete logic gates, the delay will be a couple of nanoseconds or more for common devices. I suspect using some flip flop would give "memory", but also slow it down.

#### Blaizer

Joined Oct 18, 2020
12
I'd rather do it without an MCU, so with logic gates, and chips similar in complexity to the 4021. I'm not too worried about a few nanoseconds of delay as the controller is only polled about 60 times a second. Obviously the less input-lag the better, but I don't think any solution would produce any noticeable input-lag.

#### ronsimpson

Joined Oct 7, 2019
1,227

#### Blaizer

Joined Oct 18, 2020
12
B and not A would work, yes, but it doesn't satisfy the underlined text in the original post.

#### ronsimpson

Joined Oct 7, 2019
1,227
but it doesn't satisfy the underlined text in the original post.
and it should be the corresponding input that became high most recently.
OK I did not see that. Need a SRFF.

#### andrewmm

Joined Feb 25, 2011
1,468
This is another case that a processor is great,
I'd suggest an arduino if your new to the idea.

Looking at the requirements,
you have multiple buttons,
are they going to be need to be debounce ?

Are you going to want to keep count of who pressed first / second ?
are you going to want to display the information ?

A processor is very much the answer to all these and many more options,

#### ronsimpson

Joined Oct 7, 2019
1,227

#### djsfantasi

Joined Apr 11, 2010
7,693
Have you considered a variant of a “radio push button” circuit? Search for that phrase, even on this site, and you’ll find several suggestions.

#### Blaizer

Joined Oct 18, 2020
12
This is close, but does the opposite of what I want it to do. If you hold A and press B, it ignores B until you let go of A, and vice versa. I want pressing B to override holding A, and vice versa.

Have you considered a variant of a “radio push button” circuit? Search for that phrase, even on this site, and you’ll find several suggestions.
This is also a good idea, but most radio push button circuits don't consider the case of pushing multiple radio buttons at the same time, which is the exact case I'm trying to solve.

#### Kjeldgaard

Joined Apr 7, 2016
451
A small change to the Ronsimpson sketch from #12:

#### andrewmm

Joined Feb 25, 2011
1,468
Just a thought regarding the logic,

You have two inputs, A and B, and two outputs A' and B',
and what happens to A' and B' depends upon the two inputs A and B
AND the current state of A' and B'

Thus your table needs 4 inputs and two outputs,
whilst the one you have drawn has 2 inputs, with 4 states.

you actually need to take account of 16 states, not 4.

draw that table, then you can make the logic.

#### jpanhalt

Joined Jan 18, 2008
11,088
@Blaizer
There are some states for which the desired result is not clear to me:
1) Both buttons pressed simultaneously to give an arbitrary state, say it's A'. Whatever button corresponds to that state is released (A). Do you want the thing to change state to B', stay A', or go back to zero? (I assume you want a change to B'.)
2) Assume A is pressed to give A'. B is pressed to give B' only. B' is then released while A is held. I assume you want to go back to A' . Correct?

#### andrewmm

Joined Feb 25, 2011
1,468
@Blaizer
There are some states for which the desired result is not clear to me:
1) Both buttons pressed simultaneously to give an arbitrary state, say it's A'. Whatever button corresponds to that state is released (A). Do you want the thing to change state to B', stay A', or go back to zero? (I assume you want a change to B'.)
2) Assume A is pressed to give A'. B is pressed to give B' only. B' is then released while A is held. I assume you want to go back to A' . Correct?
We need the 16 states defined,

#### jpanhalt

Joined Jan 18, 2008
11,088
Looking at the requirements,
you have multiple buttons,
are they going to be need to be debounce ?
Maybe, maybe not. The "maker" has not given any clue to that. I tried to get a handle on that by asking what was meant by "simultaneous," but the response was not quantitative.

Are you going to want to keep count of who pressed first / second ?
are you going to want to display the information ?
THAT is an essential part of the problem.

Only one X' can be active at a time. That depends on which input was last. For example, A --> A' , B -->B', A followed by B gives B', and B followed by A gives A'. My question above asks what happens if A gives A' and if followed by B --> B', but what if B is then de-asserted? I am guessing the TS wants A'.

As for a display, I did not see that criterion in the original specification.

A processor is very much the answer to all these and many more options,
I agree for simplicity. But since MCU's are not magic, anything they can do, discrete logic can do too. I am just not one to try doing that.

I am working on a short Assembly program (MPASM), and if the TS responds with some clarifications, I will post it here. Even a tiny PIC10F3xx can do it, but I suspect an 8-pin 12F1xxx might be preferred.

#### Blaizer

Joined Oct 18, 2020
12
@Blaizer
There are some states for which the desired result is not clear to me:
1) Both buttons pressed simultaneously to give an arbitrary state, say it's A'. Whatever button corresponds to that state is released (A). Do you want the thing to change state to B', stay A', or go back to zero? (I assume you want a change to B'.)
2) Assume A is pressed to give A'. B is pressed to give B' only. B' is then released while A is held. I assume you want to go back to A' . Correct?
1. Whenever only one button is held, the output is is just that button, so yes after releasing B it will go back to A.

2. Same thing, at the end only one button is held so that button gets output.