120 likes | 235 Views
Designing State machines for a numeric Keypad. EE 316 Computer Engineering Junior Lab. Topics. Designing a state machine to detect key press PLD based design Mealy or Moore? Is clock frequency an issue? Debouncing issues. Keypad Hardware. State Machine. Column Scan. 9 Outputs?. 1. 1.
E N D
Designing State machines for a numeric Keypad EE 316 Computer Engineering Junior Lab
Topics • Designing a state machine to detect key press • PLD based design • Mealy or Moore? • Is clock frequency an issue? • Debouncing issues
Keypad Hardware State Machine Column Scan 9 Outputs? 1 1 } Code for Key press: Output of the State machine 1 GAL22V10 1 Detection of Key press=> input to the state machine Ready or Enable Clock http://www.webopedia.com/TERM/n/numeric_keypad.html
Design alternatives • Which of the two state machines, Mealy or Moore, should we use? • Since we need 9 outputs for the state machine, 9 flip-flops are used up. Can we fit the keypad state machine on a single GAL chip?
GAL22V10 • Max 22 inputs • Max 10 outputs • 8-16 Product terms 8 Product terms for this macrocell Ref: Digital Design Principles & practices, John Wakerly
State-machine structure (Mealy) Output can change asynchronously with the change of input. • Do we need to add debouncing circuits? • Or, should we use a pipelined version of Mealy? Ref: Digital Design Principles & practices, John Wakerly
State-machine structure (Moore) • Do we need keypad debouncing circuits? • How many flip-flops do we need? Ref: Digital Design Principles & practices, John Wakerly
Fitting the State Machine on a GAL chip 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 5 V 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 4.7 K Key press detect
A Moore State machine Input State Output key code, Ready Scan 1111 One input is 0 One input is 0 Resolved 4 code/1 Key press Detect Key detect 4 1111/0 Key detect 1 1111/0 Key detect 1 1111/0 State 1 1111/0 Valid Output One input is 0 1111 1111 Resolved 1 code/1 12 States? 4 or more Flipflops? 0111 - 7 1011 - 11 1101 - 13 1110 - 14 0011 - 3 0001 - 1 1001 - 9 1000 - 8 1100 - 12 0100 - 4 0110 - 6 0010 - 2 State 4 1111/0 State 2 1111/0 1111 1111 Resolved 3 code/1 One input is 0 1111 1111 State 3 1111/0 Key detect 2 1111/0 Key detect 2 1111/0 Key detect 3 1111/0 Resolved 2 code/1 One input is 0 1111
Fitting the State Machine on a GAL chip 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 State 1? State 2? State 3? 5 V State 4? 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 4.7 K Key press detect We use part of the state variables as outputs of the state machine to be used for column scan.
A Mealy State machine Input/key code, Ready One input is 0/code, 1 One input is 0/code, 1 1111/1111, 0 One input is 0/1111, 0 Key detect State 4 Key detect State 1 State 1 1111/0 One input is 0/1111, 0 1111/1111, 0 1111/1111, 0 00111 - 7 01011 - 11 01101 - 13 01110 - 14 10111 – 3 11011 – 9 11101 - 12 11110 - 6 1111/1111, 0 State 4 1111/0 State 2 1111/0 One input is 0/1111, 0 1111/1111, 0 1111/1111, 0 1111/1111, 0 State 3 1111/0 Key detect State 2 Key detect State 3 One input is 0/code, 1 One input is 0/code, 1 One input is 0/1111, 0 1111/1111, 0
How to choose the proper clock frequency • The clock frequency should be slow enough so that period is comparable to or larger than the keypad bouncing times. • The clock frequency should be fast enough so that it will be able to detect the key press even if it is released very quickly