Presentation is loading. Please wait.

Presentation is loading. Please wait.

BR 1/991 Dice Game (Chapter 22) The dice game in Chapter 22 is a good example of a Finite State Machine controlling a Datapath. –The combined FSM/Datapath.

Similar presentations


Presentation on theme: "BR 1/991 Dice Game (Chapter 22) The dice game in Chapter 22 is a good example of a Finite State Machine controlling a Datapath. –The combined FSM/Datapath."— Presentation transcript:

1 BR 1/991 Dice Game (Chapter 22) The dice game in Chapter 22 is a good example of a Finite State Machine controlling a Datapath. –The combined FSM/Datapath implement a Dice Game. Dice Game Rules: –After 1st roll of dice, player wins if roll if 7 or 11. Player loses if roll is 2, 3 or 12. Anything else is saved as the players “POINT”. –On subsequent rolls, player loses if roll is a 7. Player wins if the dice roll is equal to their “POINT”. You must keep rolling until you win or lose.

2 BR 1/992 What do we need: A Dice Roll Some way to simulate a dice roll. Dice have values of 1,2,3,4,5,6. We could generate a “random” number between 1-6. –Could use a psuedo random sequence generator in the form of a shift register for this. –Can be difficult to test if using psuedo random sequences An easier way is to use a counter whose count sequence is 1,2,3,4,5,6,1,2, etc. –Even though count sequence is NON-RANDOM, a high speed clock and a user pushing buttons to stop/start the roll will make the dice roll look random!!!

3 BR 1/993 1-6 Counter S0 S1 S2 S3 Q = 1 Q = 2 En=0 En=1 En=0 En=1 Q = 3 En=0 En=1 Q = 4 En=0 En=1 Q = 5 En=0 En=1 Q = 6 En=0 En=1 S4 S5 Need two counters, one for each dice. Need an ADDER to sum the two 3-bit dice outputs to produce a four bit sum that we can test!

4 BR 1/994 “dpatha” Details Clk C 3 EN R Cntr Q Roll (from control) Reset C 3 EN R Q Logic Roll Clk Reset Cntb Cnta AdderAdder 4 dicesum 3 Ena Ena = 1 when Cntb = 6 and Roll = 1 Counters count 1,2,3,4,5,6,1,2, etc Cntr

5 BR 1/995 What else do we need??? We need to save the “POINT” value from the first roll somewhere. –Use a Register! We need to compare our POINT value and the current dice roll to several values –Compare Current dice roll to POINT value: Use a comparator –Compare Current dice roll to values of 7, 11, 2, 3, 12: Use comparator logic Need inputs to start the dice roll, stop the dice roll.

6 BR 1/996 “dpathb” Details DIN 4 C LD Register Point 4 R Dicesum (from dpatha) sp (from control) Compare Clk Reset Eq (1 if point = sum) Test Logic D7 (1 if sum=7) D11 (1 if sum=11) D2312 (1 if sum=2,3 or 12) “sp” (save point) loads value of dicesum into register.

7 BR 1/997 Dice Game Chap 22 1-to-6 Cntr Adder CntbCnta Point Register Comparator dicesum Test Logic ControlControl Roll D7 D11 D2312 eq Dpathb.vhd Dpatha.vhd control.vhd Rb Ra sp win lose

8 BR 1/998 Dice Game Flow Chart Roll Dice Sum=7 or 11? Sum=2,3 or 12? Store Sum in Point Register Roll Dice Sum= Point? Reset? Lose Sum= 7? Reset? Win YN Y Y YY Y N N N NN

9 BR 1/999 Rb?Ra? D7 or D11? Roll D2312? Sp Rb?Ra?Eq?D7? Roll Lose Win 0 1 0 1 1 0 0 0 0 0 0 1 1 1 1 1 S0 S1 S2 S4 S3 S5 Dice Game ASM Chart

10 BR 1/9910 Dice Game Implementation Dice game implemented in three 22V10 PLDs –control.vhd (Finite State Machine) –dpatha.vhd (two 1-6 counters, adder) –dpathb.vhd (point register, comparator, test logic) The Control FSM is implemented using one-hot encoding. –Outputs q0, q1, q5 are states S0, S1, S5. Output “win” is state S2, output “lose” is state S3. Outputs q0,q1,q5 are available just for debugging purposes.

11 BR 1/9911 Finite State Machine Changes Asynchronous Reset now use to exit states S2, S3. Resets back to State S0. S2 Win S3 Lose

12 BR 1/9912 Finite State Machine Changes (cont). Because we don’t have debounced switches, added extra “roll” input called “Ra”. Changed States S1, S5 to use Ra, not Rb. S1 Ra 0 1 Roll S5 Ra 0 1 Roll This means that to roll the dice, you use flip switch Rb up, then down. This starts the dice rolling. To stop the dice, Flip Ra switch up then down.


Download ppt "BR 1/991 Dice Game (Chapter 22) The dice game in Chapter 22 is a good example of a Finite State Machine controlling a Datapath. –The combined FSM/Datapath."

Similar presentations


Ads by Google