*arg max *arg min
CSCE 236 Embedded Systems, Spring 2014
Lab 2 Pre-Assignment


Started: Wednesday, February 5, 2014
Due: Beginning of class Monday, February 10, 2014
Instructions: This pre-lab assignment is an individual assignment, collaboration is not allowed. If you discuss any problems with others, please note this on the assignment as described in the syllabus. Also note any materials outside of lecture notes, course textbooks, and datasheets that you used. Show your work and describe your reasoning to get partial credit if your solution is incorrect. This pre-lab is due on the date listed above before the start of class.

Name:
How much time did the total assignment take?

1  Detecting Button Bounces

In class, you saw how to use Timer1, configured with pin T1/PD5 as the button input to count the number of times the button was pressed. Download this code from the course website (in the assignments section next to pre-lab2). Examine this code and determine which pins the LEDs and button should be connected to. Connect everything and verify the functionality of the code by pressing the button and observing the counter output on the serial console.
As you saw in class, occasionally the counter incremented more than once for a single press due to the button "bouncing." Bouncing occurs when the button is being pressed and it rapidly oscillates between logical zero and one. In this section, you will look at two different ways to detect this.

1.1  Manual Delay

First, modify the code so that it only prints the value of the register TCNT1 when it changes. Be aware that TCNT1 may change at any point, so you should only read it once in each iteration of your main loop() to ensure that the value you are using is consistent.
One way to detect that the button bounced is if TCNT1 has increased by more than one since the last iteration. However, since the main loop runs very quick, you should add a delay in the main loop so that you only check it periodically, perhaps every 100 milliseconds.
Implement this approach and print a warning every time the button bounces. In addition to printing a warning, turn on the red LED for 500 milliseconds every time the button bounces.
Submit your code via handin (http://cse.unl.edu/~cse236/handin/) AND bring a printout of your code with your name on it to turn in at the start of class. Also remember to include the amount of time it took you to complete this assignment. In addition, please include a printout of the output of your programing showing an example where it bounced.

1.2  Checking Time

Using a manual delay is somewhat wasteful in that nothing else can occur during the delay. There is a preexisting Arduino sketch Examples->Digital->Debounce which implements debouncing by using the command millis() to record when the button was pressed and then to only check the state again after a fixed delay period. Look at this code to see how they implemented it and make sure you understands the code. Ask the instructors if you have questions on how it functions.

1.3  Datasheet on Timers

Read section 16.6 of the datasheet before lab.



File translated from TEX by TTH, version 3.89.
On 6 Feb 2014, 10:07.