Electrical – logic circuit for 2 push buttons bitshift

digital-logicled

I'm trying to understand how I could implement, using logic ICs (and not a uC), the following:

there are two momentary push buttons and 3 leds.
The leds indicates the logic "state", that can be 0 (initial), +1 and -1.
Pressing the push buttons, you change the state.

I drawn this little diagram that should help to better understand the topic.

So at the beginning you are on state 0 (and the middle led is lit), if you press +1 you go to state +1 (and only the +1 led is lit). If you press again +1 nothing happens. And so on..

How can I get that using a logic circuit?
so far I only understand how to make the switches to latch using D-FlipFlop

enter image description here

Best Answer

I'd recommend abstracting things first:

  • You have three states (two bits are enough to represent that). The output is three LEDs. You can directly infer which LEDs should be on from the state.
  • You know about logic gates (AND, OR, NAND and so on). You thus know how to have two inputs (the two bits of the state) and three outputs (LEDs). If that's not clear, draw a truth table, and find the minterms needed to turn on the right LEDs.
  • The next state only depends on the current state + one bit (namely, which one of the two buttons was pressed).

So, what you need is a

  1. two flipflops to store the state
  2. Logic gates to light up the LEDs corresponding to the two state bits
  3. Logic gates to determine the next state based on the current state + which button has been pressed
  4. a "clock" input that says "ok, now evaluate the state transition logic and go into the next state".

Let's roll it up from the bottom:

The clock is easiest. Just use an OR gate on both buttons. When either button has been pressed, the next state transition should be loaded into the fliflops:

+ button \
          OR ---> Latch of flipflops
- button /

The LED logic is easy, too: for example, assume the internal stat 00 is your initial state. So you just build a NOR gate on the initial state that lights up center LED. You do that for all LEDs.

The "next state" logic is easy, too: just have the same logic as for the LEDs, but ANDed with the right button to produce the next internal state.