Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

KEY PAD LOCK

Robert Huschak
Sec W
Student ID:976697201

The task assigned for the project was to create a key pad lock that has a four-digit

passcode with possible inputs of 1, 2, 3, or 4. The circuit would not display anything if there has

not been a button pressed, and would clear the code after the 4 buttons was pressed. There had to

be a clear function, so the user could clear the input code as well as a full system reset that would

reset the code in the system to the original passcode of 1, 1, 1, 1. With a switch the door could

be locked and unlocked when the correct code was input into the system. Finally, the system

would have a counter to track the number of attempts up till 5 when the door would be locked

until the system was fully reset.

The first thing I did was to create a diagram of all the blocks I would need to build in

order to create the design. I knew I would need 5 major blocks, the top left in the diagram would

store the user code then display if on the 7 segment blocks. The code would be compared to the

original code stored in the system. After if the codes matched then the door unlocks when the

unlock switch is flipped.


(figure 1.1)

The first task I attempted to accomplish was to get the code written to a memory location

where it would be read from displayed, and then cleared from the display after a certain amount

of time to allow the user to clear the code if they input the wrong combination without counting

as an attempt. The block created was called 4bitinpit, in my final diagram on the front page.

(figure 1.2)

The block above was made up of 4 different smaller blocks to create the entire user input

storage. The buttons signals’ where cleaned up using a denouncer block given to us in lab, each

of the buttons where then denounced to prevent 1 press to show up in more than 1 location.

Those denounced signals then feed into a block called button to binary. The block is effectively

an encoder that looks for an input on one of the positions then associates that button with a 4-bit

binary number. It would then output that number to 4 signals A, the most significant bit, to D, the

least significant bit. That block also took the buttons to create a clock signal for the button press

counter and the input storage registers in the diagram above (figure 1.2). The diagram below is
the binary to button block and my handwritten design before I built it in quartus.

(figure 1.3)
(Figure 1.4)

The counter circuit used the button clock signal from the previous figure to then move the

counter up 1 digit, each digit of the count would allow the signal from the button to binary to be

written to 1 register at a time. The counter would then see a 1 on the 1st and 3rd bit of the counter
then locks the count till the system has been cleared or reset. The figure below is the button

counter block and my hand drawn design.

(figure 1.5)

(figure 1.6)

In order to store the code, I created a block called input storage which used an enable

signal from the counter to write to the registers one at a time. Each input storage was made up of

4 of the registers shown below. The clock signal was fed from the same clock signal to the

counter because the system clock moved too fast for the system to save the signal in the register,

when the button would be released it would then clear the register, so by using the button press

as my clock it would hold the code correctly. The 2 to 1 block is just a 2 to 1 multiplexor that I

created inside Quartus.


(figure 1.7)

The following diagram is missing the 4th register from the file but the concept is still the

same by having 4 registers 1 for each bit in the output signal to the 7 segments. 4 bits where used

for the ability to change the numbers allowed for inputs instead of limiting it to 3 only.

(Figure 1.8)

I then used the same counter for the button presses as well as the clock generator to create

a input clear. There is an enable signal that checks if the register has any input stored in that

register, if so then it enables the 7-segment display. That same enable signal is checked against
the output of a second counter that once it counts it will clear the displays while keeping the

code. That same signal gets fed into an output called write enable which is used the final design.

When creating the design in figure 1.2, I struggled to get the enable signals to work

properly, when checking them individually, the write signals for each register where correct but

it would still write to the registers in the incorrect order. To fix this I added to the enable signal

for bit 3 so it wouldn’t write to the 3rd bit until the 2nd was written to as well as adding to the last

bit and enable check so it wouldn’t write to the last register after a button has been assigned to it.

The next part I worked on was fixing the 7-segment decoder to add an enable signal to

the display. This will prevent the display from showing anything until a button was pressed and

stored in the register. The code below was used for the 7-segment.

(Figure 1.9)

The next block that was created was called 16-bit storage that was used to store the code

after the write enable signal is high clearing the code from the 4bitstorage block. The purpose

was to use it as a temporary memory location to compare the code stored in the memory against.

The block was made up of 4 blocks called code memory(figure 1.) which is like the blocks used

in the stored code part of the circuit but is different as when the reset switch is flipped it will set

that stored code to 0000 instead of 1111 like the other.


(figure 1.10)

There is no clear signal to this block because of how the signal is fed into the registers.

The code input by the user will not be loaded in till the last register in 4bitstorage is input then it

loads all those bits into the 16bit registers. If the user inputs a clear signal to the 4-bits, it will

load the new set once the new input automatically without needing to be cleared.

To build the stored code part of the design I realized I could use the same 4-bit storage.

When running the wires, I could send a 1 signal to the clear input to keep it from being written to
but when the correct code is input, and the code write switch is flipped it would then output a 0

allowing that register to hold the new code. Which would then be written to the same 16-bit

storage register when the last bit is written to. The code memory block in figure 1.10 is shown

below for the stored code part of the circuit.

(Figure 1.11)

Finally, there is a code comparison checker that looks at all 16 outputs for each of the

16bitstorages. It compares register 1 of the user input against register 1 of the stored code. It does

that for each set of registers and sends 1 signal out called correct code. If that is a 1 and the door

unlock switch is toggled, then the door unlocks. The diagrams below is both elements of the

comparison block of design.

(Figure 1.12)

(figure 1.13)

The only part of the design I did not get finished in time was to implement the attempt

counting part of the design working correctly. The design did not work correctly so I have not

added it to the report. The concept behind the design was to use 3 t flip flops to create a 3-bit up

counter that when it sees a 101 on the bits and the correct code signal is a 0 it would then send a

signal to the clear functions on both the 4bitinputs to send a constant high until a reset signal was

sent to the reset pins on the t flip flops allowing the count to restart and allowing the user to

continue to input codes.

The issues occurred during this project include, board errors in the lab. Many of the

things written before putting the design into Quartus had to be changed greatly to work properly

on the boards in class. I have my own personal board that is a cyclone V and the same codes
worked very differently. Then during the last week of lab my files got entirely corrupted, so I

had to rebuild the entire design from scratch again.

In summary, my design will work for most applications except for those who require a

system lockout. My files allow for all the necessary functions as well as an automatic lock after

the new code is input so the system must always have the correct code to lock and unlock. The

final design is on the final page of this report.

You might also like