Again, in designing the keypad module, we broke up the problem into managable parts.
This is the state machine the controls the components of the keypad module. Its general functions are:
This is basically a counter to implement a debouncing delay. The counter has a preset value of 100 with preset being held high normally. When a keypress is detected, the keypad controller drops the preset signal. The counter then counts down to zero and signals the keypad controller when finished.
For a clock speed of 3.579MHz (out system clock), this translates to a delay of 0.0279ms. This delay length turned out to be insufficient for consistent keypad debouncing. Due to the frequency requirements of our sensor unit, we could not lower the clock frequency. Also, due to space limitations, we could not expand the size of the counter to give us the required delay. For instance, with the same clock speed, a delay of approximately 3ms would require an inital counter value of 10000, or a 14-bit wide counter.
Available documentation:This is a 4-bit counter/register that is used to scan the keypad. It asserts all 1's except for a single 0 bit that cycles through (i.e. 0111, 1011, 1101, 1110: this is similar to one-hot encoding, except with a 0). This pattern is used to scan the rows of the keypad. The '0' enables one row at a time to allow key presses to be detected on the columns. The '1's disable the other rows. The scanner also has an enable signal which allows the keypad controller to hold the scanner value in order to determine to coordinates of the keypress.
Available documentation:We used two look up tables (LUT) in order to convert the keypad coordinate bit pattern to a BCD value and a decimal ten's digit binary value. The BCD value is used to display output on 7-segment LED's (using external 7447 BCD to 7-segment drivers). The binary value is used by the compare module for comparison with the sensor input.
Available documentation:An adder was required to add the most significant digit (MSD) value and the least significant digit (LSD) value to calculate the binary value of the incoming number.
Available documentation:Different sized registers were required in our design. They have reset and enable capabilities.
Available documentation:We required flip flops in order to prevent glitches on some of the keypad controller outputs. Specifically, the keypad controller outputs that are hooked up to level-sensitive inputs (i.e. an active high reset) cannot have glitches. Otherwise the operation of the device would be unpredictable.
Available documentation: