Designing an FSM Controller and Simulating in Logism

Posted by : at

Category : logic


TL;DR: final logism circuit downloadable file

This will be a game implementation. In this game, we will use 7 LEDs and two buttons for two players. The game starts with the led in the middle turned on. One user tries to shift the ON led to left while the other tries to push it to right. The one pushing the button faster wins the game. Winning occurs when the turned on led is at the rightmost or at the leftmost position.

We shoul also consider the cases when both players push the buttons at the same time or they do not push at all. Our FSM controller has two button inputs as B1 and B2. It has 7 outputs one for each led. Also there will be a reset input to start a new game.

I have started by drawing how the game will be looked when it finished. And name the components. That looks like the image at the top.

The LED moves next when the button released. Implementing FSM this way, will make the diagram complicated, since there must be a wait state for every button and extra transitions to consider. Therefore I decided to implement another controller for buttons. This controller will be responsible of sending 1 for a clock period only the moment a button is pressed.

State diagram of the buttons

Truth table of this controller;

s1 s0 B n1 n0 o
0 0 0 0 0 0
0 0 1 0 1 0
0 1 0 1 0 1
0 1 1 1 0 1
1 0 0 0 0 0
1 0 1 1 0 0

In the truth table we can see that o (output) is same as n1. Thus we can use n1 as output.

n1 = s1’s0 + s1s0’B
n0 = s1’s0’B

The final circuit design is as follows;

Circuit design of button

Drawing State Diagram

There is 2 inputs which comes from output of the circuit shown in figure 3 (Captures the moment of button releases). We can name them as i1 for button 1 and i2 for button 2. For the states L2, L3, L4, L5, L6 as long as both buttons is pressed or both buttons are not pressed, it will stay in the same state. This statement represented by XNOR (). For the states L1, L7 we will consider only reset button. When the reset button pressed, it will go to initial state which is L4.

In total there are 7 states and they can be represented by 3 bits. Since the first state will be L4 I labeled it to 000.

State diagram of the buttons

Truth Table

There are 3 bits for current state 2 bits for inputs and a reset button. In total there are 6 inputs. In this case if I had consider all the cases, truth table will consist of 64 rows. To avoid using too much gates and to simplify truth table, I have decided not to consider reset button. I could simply connect the reset to clear pin of the state register, so that it could go to initial state any time reset button is clicked.

s2 s1 s0 i2 i1 n2 n1 n0
0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 0
0 0 0 1 0 0 0 1
0 0 0 1 1 0 0 0
0 0 1 0 0 0 0 1
0 0 1 0 1 0 0 0
0 0 1 1 0 0 1 0
0 0 1 1 1 0 0 1
0 1 0 0 0 0 1 0
0 1 0 0 1 0 0 1
0 1 0 1 0 0 1 1
0 1 0 1 1 0 1 0
0 1 1 0 0 0 1 1
0 1 1 0 1 0 1 1
0 1 1 1 0 0 1 1
0 1 1 1 1 0 1 1
1 0 0 0 0 1 0 0
1 0 0 0 1 1 0 0
1 0 0 1 0 1 0 0
1 0 0 1 1 1 0 0
1 0 1 0 0 1 0 1
1 0 1 0 1 1 0 0
1 0 1 1 0 1 1 0
1 0 1 1 1 1 0 1
1 1 0 0 0 1 1 0
1 1 0 0 1 1 0 1
1 1 0 1 0 0 0 0
1 1 0 1 1 1 1 0

Boolean Expressions

Logism is able to show simplified versions of boolean expression from table and draw the circuit. (Window > Combibational Analysis)

n2 = s1’s0’i2’i1 + s2s1’ + s2i2’ + s2i1
n1 = s2’s1’s0’i2’i1 + s0i2i1’ + s2’s1i1’ + s1i2’i1’ + s1i2i1 + s1s0
n0 = s2’s0’i2i1’ + s0i2’i1’ + s0i2i1 + s1i2’i1 + s1 s0

Schematic on Logism and Testing

After putting them together, the circuit is working flawlessly, although there is a requirement. To transmit the status, button or pin must be on stage when the rising edge of the clock arrives.

I have used 7 leds and AND gates (inputs: n2, n1, n0 or inverses, output is the led itself) to show current state.

Some of the test cases;

  • Both buttons are pressed: stays on the current status

  • While first button is pressed, second button pressed and released constantly: LED shifts as expected, second user wins the game.

  • Reset pressed on intermediate stages: resets the game to initial state.

(To test the circuit I have used pins instead of a button)

final logism circuit downloadable


About Fatih Kaan Salgır

Student at Gebze Technical University