Question: Non-blocking Switch Debounce question Implement and test non-blocking switch de-bouncing. The program will use the Teensys 8-bit timer in normal mode, with overflow interrupt handling.

Non-blocking Switch Debounce question

Implement and test non-blocking switch de-bouncing. The program will use the Teensys 8-bit timer in normal mode, with overflow interrupt handling. You will implement a timer overflow interrupt handler which will sample the state of a designated switch at uniform intervals, and from these measurements determine if the switch has settled into an open or closed state.

Firstly, the use of an interrupt means that de-bouncing is carried out behind the scenes without holding up the main event loop of a program. Secondly, the interrupt handler will be to triggered at a pre-defined uniform frequency, so that computations in the main event loop do not affect the de-bouncing procedure.

Non-blocking Switch Debounce question Implement and test non-blocking switch de-bouncing. The program

will use the Teensys 8-bit timer in normal mode, with overflow interrupt

handling. You will implement a timer overflow interrupt handler which will sample

USE THE CODE BELOW & REFER TO DOCUMENTATION

Documentation: https://www.dropbox.com/s/dcjimas882st4w4/documentation.docx?dl=0

Only need to complete part H a - e.

// (h) Define an interrupt service routine to process timer overflow

// interrupts for Timer 0. Every time the interrupt service

// routine is called, state_count should:

// (h.a) Left-shift state_count one place;

// (h.b) Bitwise AND with a mask in which the 5 bits on the right

// are 1 and the others are 0.

// (h.c) Use bitwise OR to add the current open/closed value of the

// joystick left switch to the history.

// (h.d) If state_count is equal to the bit mask, then the switch has been

// observed 5 times in a row to be closed. Assign the value 1 to

// is_pressed, indicating that the switch should now be considered to be

// officially "closed".

// (h.e) If state_count is equal to 0, then the switch has been observed

// to be open at least 5 in a row, so store 0 in is_pressed,

// indicating that the switch should now be considered to be officially "closed".

The central idea of this algorithm is as follows: The state of the switch is read at regular intervals, giving a time series of (011) values: 0 when the switch is open, 1 when the switch is closed. When the switch goes from open to closed or vice-versa, transient high-speed on-off transitions may be observed, causing spurious clicks to be detected. The transient effects can be removed by smoothing the time series Instead of considering a single on-off value at any given time, we consider a sum of recent values, taken over an interval leading up to that time. This is similar to a moving average as used in statistics or stock analysis The example in Lecture 9 maintained separate sums for on and off observations, counting upwards with one or the other as appropriate switch states were detected, and swapping to the other when a transition was observed. It is possible to simplify the state machine: For each switch that we want to read we keep an unsigned integer in which we store the recent history of the switch state o The mechanism is similar to a Lecture 9: Appendix ?: Bit-packed boolean arrays, but we will not access the individual bits once they are stored in the history. Each time we read the state of the switch, we delete the oldest historical state, and add the new state If the history fits into a single byte, then extremely fast bitwise operations can be used to update the history. Every time we get a new value, we push it into the "right-hand" end (i.e. least significant bit) of the history To make room for the new bit, we shift the existing bits one place to the left (using the left-shift operator

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!