The Ultimate StopWatch is intended to function as a second-counting timer with added functionality and feedback through various peripherals on the FRDM-KL46Z. Users can pause the watch or add 30 seconds by pressing the different switches and LED feedback indicates when the timer has reached capacity and resets.
My project mostly consists of conditional imperative C logic determining physical peripheral output. The LCD’s individual digits are each tracked using a different variable which makes implementing the stopwatch timing logic itself more streamlined. More precisely, I used a simple conditional digit carry logic base in an infinite loop with a volatile pause gaurd to block when paused but otherwise continuously add on a second-long delay. To interact with the switches, the main perhiperals, the GPIO module is enabled with interrupts for each of switches 1 and 2. Importantly, because a single press should induce the effect of pausing / adding without the need to hold, the interrupt service routine is enabled on the relevant port (port c) to allow for system interrupts to occur when the switches are pressed. The cover all cases, once the watch reaches capacity (‘9999’), a delay loop is entered, the red led flashes, and clock resets.
As mentioned in the video, a design choice I made that doesn’t align with expected behavior but that I found best suited the project was to schedule interrupt triggers on the falling edge of cycles. This approach is straightforward and I found it to be the most effective strategy in my dubugging process.
In general, my testing approach was incrementally adding onto the conditional logic and governed the watch and observing the LCD output to ensure that the code behaved as intended. This appraoch allowed me to continously find errors or edge cases (e.g. considering what should happen when the timer reaches capacity). Another particularly good example is that I found pressing switch3 (add 30) at values that would need to be carried over the most signifigant digit was causing errors in an early implementation. Finding niche cases such as that motivated me to be very thorough about observing switch behavior in all cases beyond the stagnant watch logic itself.
My project makes great use of the provided LCD and LED modules, and my code for intiializing the GPIO and Interrupts on both switches was heavily inspired by the switch_demo.c file.