Week 6

Embedded Programming

Introduction:

This week we were tasked with programming our Hello World board with a novel program.

Workflow

Plan: Develop a Finite State Machine as a baseline, and make a simple LED toggle.

FSM Design

I was introduced to Finite State Machines in an intro to Electrical Engineering a few years ago, and I love the scalability. They let you easily diagnose and understand problems in a circuit. Starting a program with the FSM infrastructure also makes things very easy to plan.

The way this looks in code, is that there is a set number of cases (states) in the loop portion of a program, and some switch logic that determines the flow. Before the switch, there is some code that happens at every time step to ensure the switch logic is completed.

For this specific program, I began with simple logic that would keep the LED on if the button was pressed.

I then added logic to treat the button as a toggle. I did this by introducing a state variable that was toggled when certain actions were introduced.

Programming

I then added it all to the board to test it out. It seemed to work well!

Its hard to tell, but the LED is on here.

After programming the board, I found that the button was not debounced at all. That is, one button press for a human did not seem to translate to one button press for the code. I thought about adding some sort of delay into the reading of the button to alleviate this problem. I didn't get around to testing it, but my thought was to have a delay between each state evaluation, and swap states if there was ever a button press detected.

What I would do differently

  • I plan on trying out my debouncing idea
  • I also did some online research on other debouncing methods, and want to try those as well. They mostly have the same delay idea, but implemented in different ways.