DOC PREVIEW
U of U CS 5780 - Debouncing switches

This preview shows page 1-2-3-4-5 out of 16 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Page 1 1 CS 5780 School of Computing University of Utah CS/ECE 6780/5780 Al Davis Today’s topics: • Debouncing switches • e.g. matrix keypad • lab4 issues 2 CS 5780 School of Computing University of Utah Basic Concepts • Switches are often mechanical  move something and » contact is made or broken  in either case » metal rebounds • causing “hash” oscillations in the observed signal • source of massive ISR confusion if you’re not careful • Problem  make multiple events look like one event  usual solution » hardware debounce • extra logic » software debounce • focus for this weeks lab • See “debouncing.pdf” on the class web site  figures in the next few slides come from this document » thanks to Jack Ganssle for an interesting readPage 2 3 CS 5780 School of Computing University of Utah Switch Anatomy • Lots of types  SPST, SPDT, DPDT, and beyond • How long does a switch bounce  varies with switch type and often assymetric w/ open vs. close » typical a few ms but can be as bad as 100’s of ms » also varies even for a single switch • min to max can vary by 2x or so • Ganssle’s findings (bounce times in usec) 4 CS 5780 School of Computing University of Utah Switches and TTL Sampling Levels • Aliasing happens in the analog to digital transition TTL no man’s land .8 – 2v supposed to be illegal for TTLPage 3 5 CS 5780 School of Computing University of Utah Switch G 6 CS 5780 School of Computing University of Utah Switch OPage 4 7 CS 5780 School of Computing University of Utah Switch Q 8 CS 5780 School of Computing University of Utah Bottom Line • In general  characterize the switches before you use them » a thorough test takes a lot of time • vary how you activate • take scope traces • use multiple versions of the same switch  PCB mounted switches are often better than these somewhat pathological examples » but it is wise to check  weird behavior or intermittent failure » suspect your debounce methodPage 5 9 CS 5780 School of Computing University of Utah SR Latch HW Debouncer Why does it work? What switch property is required? Downside? 10 CS 5780 School of Computing University of Utah SR Software Equivalent • Simplest possible code  examine both inputs » one will bounce the other won’t » simple loop » problems • 2 input capture pins required • SPDT switches are more costly and bulky – rarely found on PCB’s these daysPage 6 11 CS 5780 School of Computing University of Utah RC Debouncer • Simple  but hides a lot of complexity  need to characterize hash time to know desired RC time constant What’s tricky here? 12 CS 5780 School of Computing University of Utah A Better RC Debouncer • Why is this one better?Page 7 13 CS 5780 School of Computing University of Utah Schmitt Trigger Debounce 14 CS 5780 School of Computing University of Utah 2R Schmitt Debounce Similar slew decoupling issue but w/ hysteresisPage 8 15 CS 5780 School of Computing University of Utah Switch Interfaces • HW debouncers make SW’s life easier  but adds to cost  so let’s consider a direct SPST interface w/ SW debounce » 6812 style 16 CS 5780 School of Computing University of Utah 6812 Ports • Ports AD, J, M, P, S and T  support both internal pull-ups and pull-down resistors » note to use port AD as a digital port • corresponding bits in ATDDIEN must be set  Port Pull Select Register must be set » PPSAD, PPSJ, PPSP, PPSM, PPSS, PPST • pull-up =0, pull-down=1  Pull Enable Register » PERAD, PERJ, PERP, PERM, PERS, PERT • enables the pull-up or pull-down function  Note » first set PPSx then PERx » if enable happens before select then get signals in possibly the wrong polarityPage 9 17 CS 5780 School of Computing University of Utah Port AD Initialization Example 18 CS 5780 School of Computing University of Utah Software Debounce Model • Assume bounce time <10msPage 10 19 CS 5780 School of Computing University of Utah Software Debounce w/ Gadfly Timer 20 CS 5780 School of Computing University of Utah SW Debounce Version 2 This version returns a new value every time switch position changes Unified press and release functions Same <10ms hash assumptionPage 11 21 CS 5780 School of Computing University of Utah Timer Control & Output Compare • Use  create squarewaves, generate pulses, implement time delays, generate periodic interrupts • 6812 has 8 output compare modules  Each module has » external ouput pin (Ocn) » flag bit, interrupt mask bit, and 16-bit output compare register » force output compare bit (FOCn) » two mode bits (OMn Oln) MC9S12 reference manual 22 CS 5780 School of Computing University of Utah Output Compare Process Example • Basic steps  read the current 16-bit TCNT  calculate TCNT+delay  set output compare register to TCNT+delay  clear the output compare flag  wait for the output compare flag to be set • Essentially another SW debounce approachPage 12 23 CS 5780 School of Computing University of Utah Output Compare 24 CS 5780 School of Computing University of Utah Debouncing Multiple SwitchesPage 13 25 CS 5780 School of Computing University of Utah Interfacing Multiple Keys • 3 basic methods  direct – input pin per switch » downside is what happens if you have more switches than input pins » upside – you can recognize every possible switch combination • note this doesn’t matter in a keyboard where one switch is pressed at a time – or very few – e.g. Shift, CTL, FN, …  scanned » keys belong to a matrix • know the row and column and you know which key • 6812 drives one row low at each step (enables the row) – column values indicate which key in that row was pushed  multiplexed » same idea but uses less pins (e.g. log2n) • put out binary value of the row • demux generates the one-hot code similar to the scanned mode • mux on the way back in does the symmetric function 26 CS 5780 School of Computing University of Utah 3 Approach ViewPage 14 27 CS 5780 School of Computing University of Utah 4x4 Scanned Keypad 28 CS 5780 School of Computing University of Utah 4x4 Keypad •


View Full Document

U of U CS 5780 - Debouncing switches

Documents in this Course
Lab 1

Lab 1

5 pages

FIFOs

FIFOs

10 pages

FIFOs

FIFOs

5 pages

FIFO’s

FIFO’s

12 pages

MCU Ports

MCU Ports

12 pages

Serial IO

Serial IO

26 pages

Load more
Download Debouncing switches
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Debouncing switches and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Debouncing switches 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?