General Code

Main Routine Block Diagram (Simplified)

Some of these blocks show paragraphs instead of if statements or multiple smaller boxes. This is done to group actions together and avoid excessive detail in the main routine, which could make it unclear. The four interrupt subroutines can be found below.

Interrupts:

Closed Box Interrupt

In this image, we can see the Close Box Interrupt Handler, which clears the interrupt immediately and locks the box if the user has already set a password. If the entered password includes extra inputs dedicated to unlocking the box, those inputs will also be cleared. If no password has been set, the box should not lock when closed.

FSR Fail Safe Interrupt

Forgetting passwords is a common problem, and it's only a matter of time before this password is forgotten or written down, which is not secure. Reusing the same password is also not secure. To address this issue, we've implemented a failsafe that allows the user to have a physical key. In this image, we can see the function that runs when the FSR is pressed and released. The interrupt type is all digital, and it works with the Tiva Board's preconfigured comparator value when it increases or decreases. The FSR ranges from around 300 Ohms to an immeasurable quantity. By reading the voltage divider value between the FSR and a 2000 Ohm resistor, we can use the Ti Tiva board's preconfigured comparator value.

Timer Interrupt

While not always necessary, I decided to practice implementing timer interrupts in this program. The interrupt allows the code to continue taking inputs while cycling through the LED lights. Although a small feature, it can greatly improve the lockbox's functionality. This particular interrupt is set to trigger every half second and cycles through the LEDs on the LED bar. If the Tiva Board enters deep sleep mode, all of the LEDs on the bar turn off. The interrupt turns off the deep sleep mode, but it's immediately re-enabled. If desired, the interrupt can be disabled while in deep sleep mode.

Wake up Interrupt

Notably, we do not want a lockbox that runs on batteries just to have the password reset when those batteries are empty. This will allow us to improve this lockbox in the future.

Interrupt Code

Wake up Interrupt Handler

This handler shows the code that is used to run the wake handler. Special code lines of code to consider which were not mentioned in the previous flow chart is the disabling and enabling of the wake interrupt.

Reset Handler

Reset Interrupt Handler. This interrupt has the debounce occur through the system delay. To clear the password I cast the integer number 0 onto the password character array in turn setting Null into the password array. The position is then set to 0 so that we can set the new password. This interrupt is triggered on both the rising and falling edges. 

Timer interrupt handler

This interrupt handler turns on all of the lights so long as the invalid password check is on. When the invalid password check is off, then it checks if the box is not locked. If so then the box turns on one light at a time. If the box is locked, then the counter is reset and all the lights turn off. 

Closed Box Interrupt

This interrupt is triggered when the box is closed. If the box is closed then we can lock the box and clear the entered password.

Initializations:

Initialization functions

The following lines of code can be found in the main function and are responsible for initializing the ports that will be used throughout the program:


Significant Functions:

Keypad Code

This code or function accepts a 32-bit integer as input for the purpose of debouncing. When the input goes high, it suggests the occurrence of a short circuit. In such a case, all outputs are switched to low and then each row turns high, one at a time, until the short circuit occurs again, indicating that the input has been located on the grid. The identified key is added to a password character array, and the position integer is incremented. A delay is included with each cycle, irrespective of whether it is on the rising or falling edge.

Check Inputs

The function is designed to collect inputs from the keypad as long as the Tiva board remains awake. The Tiva board goes to sleep after five million clock cycles, which is an arbitrary number chosen without any particular reason. The board requires a minimum of 10 seconds to enter sleep mode. Once the Tiva board is asleep, the timer interrupt is disabled and remains disabled until the wake switch is activated. This switch is activated by a rising edge signal for a positive logic switch. It could have been any keypad input, including a button, but for simplicity and availability, a switch was used.

Setting the password

This function executes only if the box is not locked and the password has not been set. It continuously adds the pressed values until the key phrase is identified. The key phrase consists of the '#' symbol triggered twice consecutively. The function returns a result of either 1 or 0, which is determined through the use of an if-logic function.

Clearing the password

This function sets the password values to the integer 0 on the ASCII table. This is expected to result in a null value.

Degrees to PWM

This function linearly converts the degrees from 0 to 180 into the respective PWM value.

Millisecond Delay

This function grabs the system clock time, divides it by three which results in seconds, then divides that by 1000 which means that the delay would be in milliseconds.

Main Routine

Main

In this function, we read in the password. If the box is locked, the servo moves to the locked position. The function then checks the inputs. Furthermore, if the correct password is entered, then the box is unlocked the sleep counter is reset and the timer interrupt is enabled.

GitHub Link: