Lab 3: Keypad Scanner

Introduction

In this lab you will learn how to use an FPGA to scan inputs from a keypad.

Learning Objectives

By the end of this lab you will have…

  • Designed a circuit interface to read a matrix keypad.
  • Understood and implemented a solution to deal with switch bouncing.
  • Implemented robust digital design strategies to ensure appropriate behavior with a variety of different user inputs.

Requirements

Design and construct a circuit on your FPGA to read a 4-by-4 matrix keypad. Display the last two hexadecimal digits pressed on your dual seven-segment display, with the most recent entry appearing at the right. The keypad and your display should be in the same orientation.

Each key press should be recorded exactly once, at the time the key is pressed, no matter how long or short a time the user holds the key down. If additional keys are pressed while still holding down the first key, these inputs should be ignored. The seven-segment displays should not flicker and should be the same brightness regardless of how many segments are displayed.

Be sure to reuse substantial portions of your lab 2 design to reduce the total effort required for this lab. Notably, the keypad and LED hardware from lab2 can be helpful here. The scanning module, the seven-segment decoder, and the multiplexing logic can be reused in your Verilog.

Discussion

Mechanical switches are prone to a phenomenon called switch bounce, where the switch makes and breaks its connection repeatedly on a time scale of microseconds to a few milliseconds. You should design your system in such a way that a single keypress registers only once even if there is some momentary bounce. You can observe bounce with an oscilloscope and an appropriate test setup (power supply on a keypad row, pulldown on keypad column, for example) to help design your system.

This is a thinking person’s lab. If you thoroughly understand the problem and design a simple scanner circuit, you can complete the lab fairly efficiently. If you go by trial and error, you may find yourself in lab indefinitely. You will need to generate rather complex stimuli to simulate your keypad scanner. Many students have been tempted to skip simulating and debug on the real hardware. Almost all have regretted it. Similarly, some students have been lured down the path of asynchronous design, at their peril.

Hints

Look at your RTL schematic in your synthesis tool (Tools -> Netlist Analyzer). Understand why your code produces the hardware you see. Be sure your combinational logic doesn’t have any registers. Be sure your logic has no latches or tristate buffers. The oscilloscope is handy for tracking down timing problems.

AI Prototype and Reflection

Don’t forget to complete the AI Prototype and reflect on it in your lab 3 writeup.

Share Your Feedback

NoteShare Your Feedback!

If you caught any typos or have any suggestions for this page, please open an issue on the website Github repository. Click the link here for instructions on how to create an issue.