Using State Machines as Control Circuits Lecture L













- Slides: 13
Using State Machines as Control Circuits Lecture L 9. 3 Section 9. 3
Using State Machines as Control Circuits • Designing a Game: Simon-nomi. S • Implementing Simon-nomi. S using ABEL
Simon-nomi. S
Simon-nomi. S Iteration Counter, C
Simon-nomi. S
S I M O N N O M I S
Using State Machines as Control Circuits • Designing a Game: Simon-nomi. S • Implementing Simon-nomi. S using ABEL
MODULE Simonnomi. S TITLE 'Simon-nomi. S - A twisted game of the traditional Simon' DECLARATIONS " INPUT PINS " PB PIN 74; clear PIN 70; [R, Y, B, G] PIN 4, 3, 2, 1; I = [R, Y, B, G]; Simon. abl " push-button switch SW 1 (clock) " push-button switch SW 2 "Switches S 7: 1 -4 " OUTPUT PINS " O 3. . O 0 PIN 40, 41, 43, 44 ISTYPE 'com'; " LED 13. . 16 O = [O 3. . O 0]; " 4 -bit output vector Q 3. . Q 0 NODE istype 'reg'; Q = [Q 3. . Q 0]; C 2. . C 0 NODE istype 'reg'; C = [C 2. . C 0]; Iteration counter
Simon. abl (cont. ) " Definitions QSTATE = [Q 3, Q 2, Q 1, Q 0]; Show. Red = [0, 0, 0, 0]; Show. Blue = [0, 0, 0, 1]; Show. Green = [0, 0, 1, 0]; Show. Yellow = [0, 0, 1, 1]; User. Input 1 = [0, 1, 0, 0]; User. Input 2 = [0, 1, 0, 1]; User. Input 3 = [0, 1, 1, 0]; User. Input 4 = [0, 1, 1, 1]; Lost. Game = [1, 0, 0, 0]; Won. Game = [1, 0, 0, 1];
Simon. abl (cont. ) state_diagram QSTATE state Show. Red: if C == 0 then User. Input 1 with C : = 1; else Show. Blue with C : = C; state Show. Blue: if C == 1 then User. Input 2 with C : = 2; else Show. Green with C : = C; state Show. Green: if C == 2 then User. Input 3 with C : = 3; else Show. Yellow with C : = C; state Show. Yellow: goto User. Input 4;
Simon. abl (cont. ) state User. Input 1: if (I == 8) & (C == 4) then Won. Game if I == 8 then Show. Red with C : = C; else Lost. Game; state User. Input 2: if I == 2 then User. Input 1 with C : = else Lost. Game; state User. Input 3: if I == 1 then User. Input 2 with C : = else Lost. Game; state User. Input 4: if I == 4 then User. Input 3 with C : = else Lost. Game; state Won. Game: goto Won. Game; state Lost. Game: goto Lost. Game; with C : = 0 else C C C
Simon. abl (cont. ) EQUATIONS Output O is a function of the state @radix 16; WHEN QSTATE == Show. Red then O = 8; ELSE WHEN QSTATE == Show. Blue then O = 2; ELSE WHEN QSTATE == Show. Green then O = 1; ELSE WHEN QSTATE == Show. Yellow then {O = 4; C : = 4; } ELSE WHEN QSTATE == Won. Game then {O = 0 F; C : = 0; } ELSE WHEN QSTATE == Lost. Game 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