Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Encoder

We use 3 inputs for each option in the scissors-paper-rock game (T1, R1, P1). The truth table would
be equivalent for both encoders. We used the table and rules provided in the Part I to encode the 3
possible options into 2 bits (S0 and S1).

Result Logic
In the second table, we combine all the possible inputs of the two encoders (4 bits, 2^4 possibilities)
to obtain a winner that would be represented in 2 bits (4 possibilities: at least one player buttons
have not been activated, tie, player 1 wins, player 2 wins) using the logic rules provided in Part II of
the exercise.
VHDL

Firstly, we import the libraries and describe the entity with 6 inputs (3 for each player) and 2 outputs
(1 for each player) obtained from the truth table described before.

Secondly, we begin to code the architecture of this entity creating 2 types of intermediate signals
that will help to encode the encoders and the Result Logic in a cleaner way. The first type is a 3 bits
representation of the 3 buttons each player can push. The second type is described in the first truth
table of Part 1 and comprises the information of S1 and S0. The two first types are assigned directly
since we already have the information of the three buttons as inputs.

We define two identical processes for each player. The processes take srp signals as inputs and
defines the different cases using it, assigning the result to the two bits signal s. The process takes
advantage of the fact that 5 of the 8 possible combinations return S1S0 as ‘00’, leaving these
combinations in the last place and assigning them using the OTHERS clause.

Finally, we define the last process using if statements taking both s1 and s2 as inputs and comparing
them using the logic rules and the truth table of Part II to obtain a result and assign it to the outputs.
The process checks if one of the inputs is ‘00’, which means a player has not selected a valid option,
assigning ‘0’ to both outputs if so. If both s1 and s2 are equal, ‘1’ is assigned to both output diodes
since there is a tie. The third corresponds to the cases where the second player wins. Finally, ‘1’ is
assigned to g1 since all the other options have been discarded and the player 1 has won.
SIMULATION

We execute a functional simulation following the different steps explained in the workbook:

If we carefully look at the screenshot of the simulation, we observe that it corresponds with the
reality. We can describe the results dividing them in 4 different cases:

- None, two or three buttons corresponding to the three inputs of one of the players are
pressed. These cases correspond to the great majority of the simulation and explain why a
great part of it is occupied with null values in both g1 and g2, since the game has no winner
in this kind of cases.
- The type of button pressed by both players coincides, i.e. c1 and c2, p1 and p2 or r1 and r2.
In these cases, both outputs g1 and g2 have value ‘1’ and both diodes are switched on.
- The button pressed by the first player corresponds to an option that wins the button pressed
by the second player. For example, the first player selects scissors (c1), and the second
player selects paper (p2). Only the first output g1 is switched on.
- The button pressed by the first player corresponds to an option that wins the button pressed
by the second player. For example, the first player selects scissors (c1), and the second
player selects rock (r2). Only the second output g2 is switched on.
MODIFICATION

To create the second version of the circuit, we only need to modify the vhdl in two points. The first
point we need to change is the entity, adding 6 new inputs of rock-scissors-paper type for two new
players, and another one for SEL, the two bits vector that will select which player can play the game
and whose buttons are recognized when pressed. The players of the first team correspond to the
inputs with label 1 and 2, while the players of the second team have labels 3 and 4.

The other change we need to make, with respect to the first section, is the assignation of srp1 and
srp2. Since there are four players, we need to assign a combination of players to each possibility of
SEL. We decide to make the most significant bit of SEL select the player1 of the team A when it is ´1’,
the player2 of the team A is selected if the bit is ‘0’. The player3 of the team B is selected when the
less significant bit is ‘1’, otherwise the player4 of the team B is selected. Hence, we have 4 possible
combination of players since they are divided in 2 teams. Using this criterion, we assign the two
intermediate signals srp of each team combining the 3 bits representing the 3 buttons of each
selected player.
MODIFICATION SIMULATION

To check that the circuit design works correctly, we are going to simulate a series of situations.

To begin with, we simulate all the possible situations of player1 of team A and player3 of team B
when SEL is 11(3), which means both players are selected to play and if their buttons are pressed,
they are considered. We see that the result fits perfectly with the simulation of the first exercise of
the practice, which means the circuit design is correct.

It is clear that if we perform the same simulation with a similar combination but with one of the
players not being the selected one, the result would be always ‘0’ for both outputs. The same would
also occur if both players are not the selected ones.
We perform other simulation with other value of SEL and see that if we select the correct players
(player2 of the team A since the MSB is ‘0’, player3 of team B since the LSB is ‘1’), we obtain again
the same combination as in the first section.

From this, we deduce the circuit works properly. We do not simulate more cases since there are too
many and simulations when one player presses more than one button will be always ‘0’ for both
teams and if a player that is not selected presses a button, it would not affect the expected results as
shown in the next and last simulation where the rock button of the player4 is pressed when it is not
selected.

You might also like