Rowfour inputs41 returns 0b1111 no buttons pressed in

This preview shows page 10 - 12 out of 17 pages.

RowFour = Inputs<4:1>; // returns 0b1111 (no buttons pressed in row 4) Pseudo code showing the detection of the “6” key. It is important to note, that using a matrix keypad and a “scanning” architecture, it is not possible to always uniquely determine which of multiple keys are pressed, so in this lab we are going to assume that Dr. Doofenshmirtz is confined to a locked cell and no one is going to conspire to press more than one key at a time during this lab (way to go Perry the Platypus). Switch Bounce As previously mentioned in EE1301, real-world switches suffer from a phenomenon called “bounce”. This is a physical effect where the metal contacts of a switch rapidly open and close for a short period of time after the switch has been depressed. Here’s a picture of the typical square “tactile” microswitch. Scope output of a switch bouncing Page 10
EE 2361 - Lab # 3 ECE Department The timescale is very important for this discussion, notice how all the bouncing occurs in a <2ms window. From the observational point of view of a typical person, this switch is ideal. It would turn on and off an LED with no noticeable bounce. However, for a microcontroller making observations at a rate of one every 62.5ns, it is completely unclear what the state of this switch is for 1.2ms (or about 20 cycles.): is Superwoman sending a secret message in Morse code? Or a regular person is trying to turn a switch on? It should also be made clear, these “tactile” microswitches are some of the best and fastest switches available. During the EE1301 lab, we were able to safely hide behind the fact that the Photon (in Automatic Mode) waits at least 1ms between iterations of loop(). From the user code point of view, the switch state was never unknown. For the PIC24FJ64GA002, however, this is not the case. We must develop some type of filter to determine the state of our buttons during the “bounce” period. There are three methods usually used to debounce switches: Existing program delay State-based debouncing Hardware RC filter The simplest of these filters is to utilize existing program delay to sample the switch state once during an extended period of time. The Photon from EE1301, used this method, loop()’s max update rate was 1ms in Automatic mode. Generally speaking, if you are interfacing with human beings, then it is likely some other part of your code also updates at a relatively slow rate. In the case of this lab, the display frame rate is also in the millisecond range. This method has the disadvantage that all user input will be delayed by the sample rate of the switch. State-based debouncing utilizes interrupts (or a fast polling loop) to run an internal state machine. The state machine effectively “locks out” further changes in the value of the pin after it has initially transitioned. This allows for the input to be observed within about one clock cycle. The disadvantage of this method is it requires the use of semi-limited resources (interrupts and timers). This method is often used in simple hardware (like FPGAs where timers and

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture