EE 205 – DIGITAL DESIGN TERM PROJECT Keypad Scanner & Sequential Adder/Subtractor Project Objectives: For this semester’s project, you will design and implement a sequential adder/subtractor module. The module will keep track of the latest two numbers entered via a keypad. Then it will either add or subtract them with respect to the mode chosen. Finally the numbers to be operated and result will be displayed on the 7- segment displays of FPGA card. You will write Verilog codes and simulate them in Xilinx ISE and implement your design on FPGA Spartan3E100 card. The project will be split into two parts.
Project Part 1: For the first part, you will only display the number pressed on the keypad in one of the seven segment displays of FPGA. The block diagram for this part is as below;
Figure 1: Part1 Block Diagram Input numbers for the module will be given by a keypad. The keypad you will use should be a 4x4 matrix keypad. All the buttons are connected to each other with wires in a matrix formation, in other words 4 wires for each row and 4 wires for each column. Row and column wires do not touch each other initially. Once a button is pressed, the wires crossing that button
1/6
touches each other. So, a link appears in between respected row and column wires of that button.
Figure 2: 4x4 Numeric (HEX) Keypad and Inner Wiring (the resistors are added externally) Please do not forget to inspect the datasheet of your keypad for more detailed information. To summarize, the keypad will give you the location of the number pressed instead of the number itself. To decode the number, you need to write a Keypad scanner Verilog code which will send voltage through the rows or columns of the keypad and search for the button pressed. Be careful that you should take into account a small amount of pressing and releasing the button time (~100ms for pressing & ~20ms for releasing). Finally, this code block should convert the address of the button to the number pressed. Once you retrieved the number pressed, it will be sent to seven segment decoder block, which will basically convert the number into 7-bit vector seven segment input. All possible 7-bit vector inputs for numbers should be defined here. Then the seven segment input will be sent to the driver code block, which will, as its name suggests, display the number on a chosen seven segment. To be able to synchronize all the blocks and to create many different frequency clocks you will write a clock divider code block which will take the main 50MHz clock of FPGA as input. Finally one of the switches on the board will be chosen as reset switch. Once turned on, it should make the number displayed 0.
2/6
To be able to further visualize the task given, let’s inspect the below sequential button press cases;
Default 1st number 2nd number Reset switch on 3rd number
Buttons Pressed
Reset Switch
Number Displayed
initially 5 7 X 8
0 0 0 1 0
0 5 7 0 8
Table 1 Here third seven segment is chosen to display the numbers. Initially, before any buttons are pressed, the number displayed is 0 by default. Then 5 is pressed while reset switch is off (0), hence 5 is displayed on third segment. When 7 is pressed, the number on third segment will change to 7. Then reset switch is turned on (1), so 0 will be displayed on the third segment not matter what buttons are pressed. Once reset switch is turned off and 8 is pressed, third segment will display 8.
Default, initial case
First button, 5, is pressed. Reset switch: 0
Second button, 7, is pressed. Reset switch: 0
Reset switch is turned on (1). 0 is displayed.
3/6
Reset switch turned off and then third button, 8, is pressed.
Project Part 2: For the second part you will improve your code so that it will track the latest two numbers pressed and display them orderly on two of the 7-segments of FPGA. Then these numbers will be subjugated to either addition or subtraction operations with respect to one of the switches on the FPGA. When off, or 0, the operation will be subtraction and when on (i.e. 1) the operation will be addition. With respect to the switch, the resultant will be displayed on the other 7-segments. If a smaller number is to be subtracted from a greater number, the answer should be displayed with a minus sign in front. For example, if 2 and then 7 are pressed with operation switch in off position, the result will be –5 and – sign will be displayed on third 7segment while 5 is being displayed on the fourth 7-segment. Just like part 1, there should be a reset switch, which, when turned on, should forget the stored numbers, display 0’s and turn back to initial default stage. Let’s examine the following case. The user’s sequential key presses and switch alignments are given in the table below;
Default 1st number 2nd number 3rd number 4th number 5th number Reset switch on
Buttons Pressed
Operation Switch (add:1/sub:0)
Reset Switch
Operation
Resul t
initially 1 3 2 5 9 X
0 0 0 0 1 1 X
0 0 0 0 0 0 1
0–0 0–1 1–3 3–2 2+5 5+9 X
0 –1 –2 1 7 14 0
Table 2 Initially all the seven segments will display 0s and since switch is off (0) the operation will be 00, hence 0. When 1 is pressed, the second seven segment will be 1 and first seven segment is 0 and again the operation is 0-1, hence third segment is – and fourth one is 1. Next, 3 is pressed, so the second segment becomes 3 and first one 1. Still the operation is subtraction so 1-3 is -2, third segment – and fourth one 2. Then 2 is pressed, first segment is 3 and second segment is 2. The switch is off still, so 3-2 is 1, so third segment is off and fourth segment is 1. Then the switch is turned on (1), and 5 is pressed on the keypad. Now first segment is 2 and second segment is 5. The operation is now sum, so 2+5 is 7, which makes, third segment off and fourth segment 7. 4/6
After that, 9 is pressed while switch if on. First segment is 5 and second segment is 9. The operation 5+9 is 14, hence third segment is 1 and fourth segment is 4. Finally, the reset switch is turned on (1). With reset active, the stored numbers 5 and 9 are lost and the code turns back to initial stage (i.e. 0). Unless the reset switch is turned off, no matter which buttons are pressed, the seven segments will display 0’s.
Default, initial case
First button, 1, is pressed. Operation switch: 0(subtract)
Second button, 3, is pressed. Operation switch: 0(subtract)
Third button, 2, is pressed. Operation switch: 0(subtract)
Fourth button, 5, is pressed. Operation switch: 1(add)
Fifth button, 9, is pressed. Operation switch: 1(add)
5/6
Reset switch is turned on (1). The previously stored numbers are lost (Back to initial case).
6/6