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

Thread Starter

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:

ABA'B'
0000
0101
1010
11**
*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.
 

jpanhalt

Joined Jan 18, 2008
10,515
*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.
 

Thread Starter

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
10,515
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.
 

Thread Starter

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.
 

andrewmm

Joined Feb 25, 2011
658
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,
 

djsfantasi

Joined Apr 11, 2010
6,962
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.
 

Thread Starter

Blaizer

Joined Oct 18, 2020
12
What about this.
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.
 

andrewmm

Joined Feb 25, 2011
658
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
10,515
@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
658
@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
10,515
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.
 

Thread Starter

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.
 
Top