BR 1/991 Dice Game Chap 22 1-to-6 Cntr Adder CntbCnta Point Register Comparator dicesum Test Logic...

6
BR 1/99 1 Dice Game Chap 22 1- to-6 Cntr 1- to-6 Cntr Adder Cntb Cnta Point Regist er Comparat or dicesum Test Logic C o n t r o l Roll D7 D11 D231 2 eq Dpathb.vhd Dpatha.vhd control.vh d Rb Ra sp win lose

Transcript of BR 1/991 Dice Game Chap 22 1-to-6 Cntr Adder CntbCnta Point Register Comparator dicesum Test Logic...

Page 1: BR 1/991 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.

BR 1/99 1

Dice GameChap 22

1-to-6 Cntr

1-to-6 Cntr

Adder

CntbCnta

PointRegister

Comparator

dicesum

TestLogic

Control

Roll

D7

D11D2312

eq

Dpathb.vhd

Dpatha.vhd

control.vhd

Rb

Ra

sp

win

lose

Page 2: BR 1/991 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.

BR 1/99 2

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.

Page 3: BR 1/991 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.

BR 1/99 3

Finite State Machine Changes

Asynchronous Reset now use to exit states S2, S3. Resets back to State S0.

S2 Win

S3 Lose

Page 4: BR 1/991 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.

BR 1/99 4

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

1Roll

S5

Ra 0

1Roll

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.

Page 5: BR 1/991 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.

BR 1/99 5

“dpatha” Details

ClkC 3

EN

R

Cntr

Q

Roll(from control)

Reset

C 3

EN

R

QLogic

Roll

Clk

Reset

Cntb

Cnta

A

dder

4

dicesum

3

Ena

Ena = 1 when Cntb = 6 and Roll = 1

Counters count 1,2,3,4,5,6,1,2, etc

Page 6: BR 1/991 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.

BR 1/99 6

“dpathb” Details

DIN4

C

LD

Register

Point

4

R

Dicesum(from dpatha)

sp(from control)

Compare

Clk

Reset

Eq(1 if point = sum)

TestLogic

D7 (1 if sum=7)

D7 (1 if sum=11)

D2312 (1 if sum=2,3 or 12)

“sp” (save point) loads value of dicesum into register.