Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using State Machines as Control Circuits Lecture L9.4.

Similar presentations


Presentation on theme: "Using State Machines as Control Circuits Lecture L9.4."— Presentation transcript:

1 Using State Machines as Control Circuits Lecture L9.4

2 Using State Machines as Control Circuits Designing a Game: Simon-nomiS Implementing Simon-nomiS using ABEL

3 Simon-nomiS

4 Iteration Counter, C

5 Simon-nomiS

6 SIMON-NOMISSIMON-NOMIS

7 Using State Machines as Control Circuits Designing a Game: Simon-nomiS Implementing Simon-nomiS using ABEL

8 MODULE SimonnomiS TITLE 'Simon-nomiS - A twisted game of the traditional Simon' DECLARATIONS " INPUT PINS " PB PIN 74; " push-button switch SW1 (clock) clear PIN 70;" push-button switch SW2 [R,Y,B,G] PIN 4,3,2,1;"Switches S7:1-4 I = [R,Y,B,G]; " OUTPUT PINS " O3..O0 PIN 40,41,43,44 ISTYPE 'com'; " LED 13..16 O = [O3..O0]; " 4-bit output vector Q3..Q0 NODE istype 'reg'; Q = [Q3..Q0]; C2..C0 NODE istype 'reg'; C = [C2..C0]; Simon.abl Iteration counter

9 " Definitions QSTATE = [Q3, Q2, Q1, Q0]; ShowRed = [0, 0, 0, 0]; ShowBlue = [0, 0, 0, 1]; ShowGreen = [0, 0, 1, 0]; ShowYellow = [0, 0, 1, 1]; UserInput1 = [0, 1, 0, 0]; UserInput2 = [0, 1, 0, 1]; UserInput3 = [0, 1, 1, 0]; UserInput4 = [0, 1, 1, 1]; LostGame = [1, 0, 0, 0]; WonGame = [1, 0, 0, 1]; Simon.abl (cont.)

10 state_diagram QSTATE state ShowRed: if C == 0 then UserInput1 with C := 1; else ShowBlue with C := C; state ShowBlue: if C == 1 then UserInput2 with C := 2; else ShowGreen with C := C; state ShowGreen: if C == 2 then UserInput3 with C := 3; else ShowYellow with C := C; state ShowYellow: goto UserInput4;

11 state UserInput1: if (I == 8) & (C == 4) then WonGame with C := 0 else if I == 8 then ShowRed with C := C; else LostGame; state UserInput2: if I == 2 then UserInput1 with C := C else LostGame; state UserInput3: if I == 1 then UserInput2 with C := C else LostGame; state UserInput4: if I == 4 then UserInput3 with C := C else LostGame; state WonGame: goto WonGame; state LostGame: goto LostGame; Simon.abl (cont.)

12 EQUATIONS @radix 16; WHEN QSTATE == ShowRed then O = 8; ELSE WHEN QSTATE == ShowBlue then O = 2; ELSE WHEN QSTATE == ShowGreen then O = 1; ELSE WHEN QSTATE == ShowYellow then {O = 4; C := 4;} ELSE WHEN QSTATE == WonGame then {O = 0F; C := 0;} ELSE WHEN QSTATE == LostGame then {O = 9; C := C;} ELSE O = 0; Q.C = PB; Q.AR = clear; C.C = PB; C.AR = clear; Remember – O is combinational – C is registered Simon.abl (cont.) Output O is a function of the state

13 test_vectors([PB,clear,I] -> [Q,C,O]) [.c.,1,.X.] -> [0,0,8]; [.c.,0,.X.] -> [4,1,0]; [.c.,0,8] -> [0,1,8]; [.c.,0,.X.] -> [1,1,2]; [.c.,0,.X.] -> [5,2,0]; [.c.,0,2] -> [4,2,0]; [.c.,0,8] -> [0,2,8]; [.c.,0,.X.] -> [1,2,2]; [.c.,0,.X.] -> [2,2,1]; [.c.,0,.X.] -> [6,3,0]; [.c.,0,1] -> [5,3,0]; [.c.,0,2] -> [4,3,0]; [.c.,0,8] -> [0,3,8]; [.c.,0,.X.] -> [1,3,2]; [.c.,0,.X.] -> [2,3,1]; [.c.,0,.X.] -> [3,3,4]; [.c.,0,.X.] -> [7,4,0]; [.c.,0,4] -> [6,4,0]; [.c.,0,1] -> [5,4,0]; [.c.,0,2] -> [4,4,0]; [.c.,0,8] -> [9,0,0F]; "--winning [.c.,0,.X.] -> [9,0,0F]; "--winning "[.c.,0,4] -> [8,0,9]; "[.c.,0,.X.] -> [8,0,9]; " -- replace the last two with the two " -- above for Losing a game END SimonnomiS Simon.abl (cont.)


Download ppt "Using State Machines as Control Circuits Lecture L9.4."

Similar presentations


Ads by Google