Vous êtes sur la page 1sur 9

DSD Laboratory 5

ECSE 323 Fall-2009


Group #31

Jorge Puente De La Vega


260234031
Jiaqi Yan
260218451

G31_mastermind_controller:
The g_31_mastermind_controller circuit has two main modes. We have the
User guessing mode and the system-guessing mode. To accomplish the back
and forth switching between the two modes, we implemented one of the
dipswitches on the Altera board. The mode dipswitch output controls the
input, steering the controller (FSM) to the different sequences in the different
modes on the state diagram. In order to be able to play the mastermind
game in the user guessing mode, we created a new random pattern
generator that will be generating a random pattern on a button press (on the
Altera board). Now, the user will input a guessed pattern using the switches
on the Altera board and that guessed pattern will be displayed on the board.
Once the user guessed pattern is displayed on the board, the computer
(system created) will output the score of the guess. The score, as discussed
in previous laboratories, will be displayed on two 7-segment LEDs of the
Altera board. We can repeat this as many times as we want until we match
the hidden random pattern. Since we already know what the hidden pattern
is, we can input as the guessed pattern the actual pattern.

The second functionality of the Mastermind game is the system guessing


mode. In this mode, we first choose a random number and write it down.
This number will be the hidden pattern. The system generates the guessed
patterns and each time the patterns are generated, we need to input on the
Altera board the score obtained using switches. The guessed patterns
generated by the computer will be displayed on the Altera board. The score
computer (by the user) will also be displayed on the board. The system is
able to guess the pattern because of the FSM implemented in laboratory 4.
Thanks to this controller the system will take around 5 guesses to find the
true hidden pattern. We will repeat the same steps of inputting and
displaying the score in the board, to let the system compute the true hidden
pattern.

Figure 1: Complete datapath of the mastermind game

Figure 2, is the circuit implemented to allow the game to display all the
numbers needed to play the game. The score, the hidden pattern and the
guessed pattern will be displayed depending on the mode that we are
playing.

ECSE 323- Digital System Design—Fall 2009


Figure 2: Display circuit
The Led display is made of 4 7-segment LEDs decoder and the graph is
shown below (Figure8). This was implemented in lab 3. This is the rippleblank
in order to display without zeroes in front of the numbers.
g31_7_segment_decoder
l4[3..0]
code[3..0] RippleBlank_Out
RippleBlank_In segments[6..0]

inst5
l4[3..0] INPUT
VCC

l3[3..0] INPUT
VCC

l2[3..0] INPUT
VCC
g31_7_segment_decoder
l3[3..0]
code[3..0] RippleBlank_Out INPUT
l1[3..0]
VCC
R ippleBlank_In segments[6..0]

inst6 OUTPUT Out4[6..0]

g31_7_segment_decoder OUTPUT Out3[6..0]


GND
l2[3..0]
code[3..0] RippleBlank_Out
RippleBlank_In segments[6..0] OUTPUT Out2[6..0]

inst7
OUTPUT Out1[6..0]

g31_7_segment_decoder
l1[3..0]
code[3..0] RippleBlank_Out
RippleBlank_In segments[6..0]

inst8

Figure 8: g31_Ledboard

Figure 3, Mastermind controller, takes the inputs and controls the states. This
controller was created in laboratory 4. We added muxes in order to increase
the controllability of the game and we encapsulated everything in a block
diagram called g31_mastermind_controller.

ECSE 323- Digital System Design—Fall 2009


g31_mastermind_controller

totalRST SR_SEL
SC_CMP P_SEL
TC_LAST GR_SEL
START GR_LD
READY SR_LD
CLK TM_IN
MODE TM_EN
guessPush TC_EN
inputPush TC_RST
RPGorInput SOLVED
Lef tOrRight Genable
userGuess[2..0] Ienable
publishScoreEnableIn LORout
scoreOrGuessIn scoreOrGuess
TM_OUT userScoreOut[5..0]
userScore[5..0] outputSelect[1..0]
userGuessOut[2..0]
ROIout
loadit
MODEout
publishScoreEnableOut

inst7

Figure 3: mastermind controller

The random paten generator will generate, as the name states, a random
pattern. We used the possibility table and a latch to create the generator. We
grounded the TM_IN and TM_EN since we did not need them for the random
pattern generation. Each time we press the button KEY0 on the Altera board
(if we are in the user guessing mode).

q[11..9]
OUTPUT LED4[2..0]
q[8..6]
OUTPUT LED3[2..0]
q[5..3]
OUTPUT LED2[2..0]

q[2..0]
OUTPUT LED1[2..0]

g31_possibility _table

VCC TC_EN TC_LAST


lpm_latch0
q[11..0]
TC_RST TM_ADDR[11..0] data[11..0] q[11..0]
CLK INPUT CLK TM_OUT gate
VCC
TM_IN
inst
TM_EN
GND
inst2

GND

enable INPUT
VCC

Figure 4: Random pattern generator

The g31_usergus circuit will get the input from the users and input it into next
block which will be the g31_mastermind_score circuit (Figure6). The input
inputcode[2..0] will take the numbers that the user will be entering as the
guessed pattern( user guessing mode). Since we are displaying the 4 digits in
only 2 LEDs, we will need the KEY3 that will switch and display the first two

ECSE 323- Digital System Design—Fall 2009


digits and the last two digits of the user guess pattern, this will be taken care
by outputSelect[1..0].

g31_usergus

inputCode[2..0] LED4[2..0]
outputSelect[1..0] LED3[2..0]
enableLine LED2[2..0]
CLK LED1[2..0]

inst54

Figure 5: userguess

The g31_mastermind_score circuit (implemented in laboratory 3) will


compare the inputs from the user and the random pattern generated by the
system. Once the comparison is done, the system will display the score of the
user on the LEDs. This will tell us the number of color matches and exact
matches.

g31_mastermind_score

P1[2..0] exact_match_score[2..0]
P2[2..0] color_match_score[2..0]
P3[2..0] score_code[3..0]
P4[2..0]
G1[2..0]
G2[2..0]
G3[2..0]
G4[2..0]

inst36
Figure 6: mastermind_score

ECSE 323- Digital System Design—Fall 2009


The one bit extension will extend the input 1 more bit

my Ground,l4[2..0]
l4[2..0] INPUT OUTPUT Out4[3..0]
VCC

my Ground,l3[2..0]
OUTPUT Out3[3..0]
l3[2..0] INPUT
VCC

my Ground,l2[2..0]
OUTPUT Out2[3..0]

l2[2..0] INPUT
VCC

my Ground,l1[2..0]
OUTPUT Out1[3..0]

l1[2..0] INPUT
VCC

my Ground

GND

Figure 7: 1birextention

User Interface – User’s guide:


Since there are many ways the pins in the Altera board could have been
programmed. We will explain step by step the method on how to use the
mastermind game. We will divide into two parts. The first part is the system
guessing mode and the second part is the user guessing mode.

System guessing mode:


Step 1: The first thing to do here is to set the SW9 switch to high. This is the
totalRST switch. This switch will allow restarting the whole game when it
is high.
Step 2: Set the SW8 switch to low. This switch will control the mode of the
game. When the switch is low, it is in the system guessing mode.
Step3: Set the SW9 switch to low. When we are ready to start playing, the
switch needs to be set to low.

ECSE 323- Digital System Design—Fall 2009


Step 4: Set the SW6 to high. This will give the first guess of the system. The
system will always start with the 0011 guess (this is how the algorithm
works).
Step 5: In order to input the score of the system guess, we use switches SW5
to SW0. We will use this switched to input the score. The switches SW5 to
SW3 will represent the first 3 bits and switches SW2 to SW0 will represent the
last 3 bits. If the score is 20, it will be represented as “010 000”.
Step 6: We can toggle SW7 in order to see the score or to see the whole
system guessed pattern. For example, if the guess pattern is 5324 and the
score at that point is 20, we toggle the switch in order to see “5324” or
“2024”.
Step 7: Press key0. This key will let the system know that the score was
computed and that it is time to generate another system guess pattern.
Step 8: Go back to step 3 and repeat steps until the system is guesses the
correct hidden pattern.

User guessing mode:


Step 1: Switch SW9, SW8 and SW7 to high. SW9 is the total RST switch. SW8
is the mode. When SW8 is high it is in user guessing mode.
Step 2: Switch SW9 to low and press KEY0 to generate a random pattern. This
is the pattern generated by the computer. We can press KEY0 as many times
as we want.
Step3: KEY3 will allow us to change from the first 2 bits to the last two bits.
Since we are only displaying the random pattern in 2 different LEDs, we need
KEY3 to check the last two bits.
Step 4: Switch SW9 to high and SW7 to low.
Step 5: After switching SW7 to low switch SW9 to low.
Step 6: Set SW2 to SW0 to the desired input. This is where the user enters
the guessed pattern. In order to enter the 4 digits, we need the use of KEY1.
Step 7: Each time we input a new digit of the guessed pattern we need to
press KEY1. For example, if we want to input 5230, we will first enter first ‘5’
and then press KEY1 then enter ‘2’ and press KEY1 and so on. As stated
before, KEY3 will allow us to view the last 2 bits of the user input pattern.
Step 8: Switch SW9 and SW3 to high. SW3 will be used to display the score
that the system computed.
Step 9: Switch SW9 to low.

ECSE 323- Digital System Design—Fall 2009


Testing of the system:
The system was tested several times. We first tested the user-guessing
mode. Since we know what the hidden pattern the system generates is, we
can input the true pattern at the first guess and the game will be over or we
can input as many wrong guesses as we want. The user guessing testing was
tested several times and the system can easily compute the score at every
user guess.

For the system guessing mode, we played several times to make sure it was
working properly. We tested the system guessing mode and we computed
the average number of guesses it takes to get the right answer. As we can
see on table 1, the number of guesses varies between 3 and 6. The average
number of guesses over 10 trials is 4.8. We computed the average over 30
guesses and we get an average of 4.9 tries. We conclude that our system is
working properly.

Table 1: Testing of the system-guessing mode


User hidden pattern Guessed Pattern Number of guesses
3542 0011, 5555, 5444, 3543, 5

ECSE 323- Digital System Design—Fall 2009


3542
5530 0011, 5550, 5540, 5530 4
1453 0011, 5550, 5144, 1453 4
3120 0011, 5500, 4140, 3130, 5
3120
4542 0011, 5555, 5444, 4543, 5
4542
1532 0011,5550,5144,4430,1533 6
,1532
1234 0011,5550,4444,4144,1343 6
,1234
4150 0011, 5500, 4150 3
2233 0011,5555,4444,4433,3322 6
,2233
5432 0011, 5555 ,5444, 5432 4

Conclusion:
One of the main problems encountered was the fact that we had to scale the
circuits in order to make work in real time, slow down the clock. Fortunately,
thanks to conventional programming we were able to create counters that
will allow the circuit to work on a proper time. Another problem encountered
was the overheating of the board. This issue wasn’t a major one but it is goo
to address it for future reference.

A possible enhancement to the system could be to increase the number of


bits that can be displayed on the LEDs. Also, we could have boards that have
a few more LEDs in order to display a bigger range of number. Another
possibility for enhancement is to optimize the number of states in order to
have a minimum number of states.

ECSE 323- Digital System Design—Fall 2009

Vous aimerez peut-être aussi