Debouncing Switches Mechanical switches are one of the most common interfaces to a uC. Switch inputs are asynchronous to the uC and are not electrically.

Slides:



Advertisements
Similar presentations
Button Input: On/off state change Living with the Lab Gerald Recktenwald Portland State University
Advertisements

ECE 382 Lesson 14 Lesson Outline Polling Multiplexing Intro to Logic Analyzer Debouncing Software Delay Routines Admin Assignment 3b due BOC today Assignment.
Programmable Interval Timer
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
Switch Debouncing. Switches connected to sources of constant logic 0 and 1 are often used in digital systems to supply “user inputs”. In high speed digital.
I/O Unit.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
ECE 372 – Microcontroller Design Parallel IO Ports - Interrupts
CSE 140L Lecture 6 Interface and State Assignment Professor CK Cheng CSE Dept. UC San Diego 1.
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
1 Sequential Circuits Registers and Counters. 2 Master Slave Flip Flops.
ECEN 248 Lab 6: De-Bouncing, Counters & LCD Display Control
16-Bit Timer/Counter 1 and 3 Counter/Timer 1,3 (TCNT1, TCNT3) are identical in function. Three separate comparison registers exist. Thus, three separate.
Clocked Synchronous State Machine Design
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
Revised: Aug 1, EE4390 Microprocessors Lessons 29, 30 Welcome to the Real World!
Digital Design Strategies and Techniques. Analog Building Blocks for Digital Primitives We implement logical devices with analog devices There is no magic.
Ch. 9 Interrupt Programming and Real-Time Sysstems From Valvano’s Introduction to Embedded Systems.
System Clocks.
MICROPROCESSOR INPUT/OUTPUT
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
PHY 202 (Blum)1 Analog-to-Digital Converter and Multi-vibrators.
COMP3221: Microprocessors and Embedded Systems Lecture 18: Computer Buses and Parallel Input/Output (II) Lecturer: Hui.
PIC16F877 ISR Points to note Interrupt Triggers –Individual interrupt flag bits are set, regardless of the status of their corresponding mask bit, PEIE.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Switch Debouncing Paul MacDougal TriEmbed.org meeting 5/11/15.
Khaled A. Al-Utaibi  The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy”
Lecturers: Professor John Devlin Mr Robert Ross
SEQUENTIAL CIRCUITS Component Design and Use. Register with Parallel Load  Register: Group of Flip-Flops  Ex: D Flip-Flops  Holds a Word of Data 
© BYU 18 ASYNCH Page 1 ECEn 224 Handling Asynchronous Inputs.
8279 KEYBOARD AND DISPLAY INTERFACING
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
Introduction to Sequential Logic
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
The PC Game Adapter. The game adapter card typically contains a DB15 connector into which you plug an external device. The digital joystick is probably.
8279 KEYBOARD AND DISPLAY INTERFACING
I NTRODUCTION TO PIC PROGRAMMING By : S HERIF H ARHASH.
CSCI1600: Embedded and Real Time Software Lecture 9: Input Output Concepts Steven Reiss, Fall 2015.
CSCI1600: Embedded and Real Time Software Lecture 16: Advanced Programming with I/O Steven Reiss, Fall 2015.
TIMERS AND INTERRUPTS AVI SINGH KEVIN JOSE PIYUSH AWASTHI.
Penn ESE370 Fall DeHon 1 ESE370: Circuit-Level Modeling, Design, and Optimization for Digital Systems Day 20: October 25, 2010 Pass Transistors.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
Microprocessors A practical approach..
Digital Control CSE 421.
Microcontrollers, Basics Tips and Tricks with PIC MCUs
Microprocessor Systems Design I
EI205 Lecture 8 Dianguang Ma Fall 2008.
BRX Technical Training
Digital Fundamentals Floyd Chapter 7 Tenth Edition
CPU Sequencing 6/30/2018.
AVR Addressing Modes Subject: Microcontoller & Interfacing
Subject Name: Microprocessors Subject Code:10EC46 Department: Electronics and Communication Date: /10/2018.
CSCI1600: Embedded and Real Time Software
Chapter 7 Latches, Flip-Flops, and Timers
Interrupts, Tasks and Timers
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
Wireless Embedded Systems
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
CPU Sequencing 7/20/2019.
Interrupts.
Presentation transcript:

Debouncing Switches Mechanical switches are one of the most common interfaces to a uC. Switch inputs are asynchronous to the uC and are not electrically clean. Asynchronous inputs can be handled with a synchronizer (2 FF's). Inputs from a switch are electrically cleansed with a switch debouncer. What is switch bounce? -The non-ideal behavior of the contacts that creates multiple electrical transitions for a single user input.

Debouncing Switches Switch bounce from a single depress/release of mega128 pushbutton switches

Debouncing Switches The problem is that the uC is usually fast enough to see all the transitions -uC acts on multiple transitions instead of a single one The oscilloscope traces showed bounce durations of uS -our mega128 uC runs at 62.5nS per instruction -a 10uS bounce (short) is (1x10 -5 /62.5x10 -9 ) 160 instructions long! -a 100uS bounce could be sampled as a valid true or false 100’s of times -results are incorrect behavior as seen by user Characteristics of switch bounce: -nearly all switches do it -the duration of bouncing and the period of each bounce varies -switches of exactly the same type bounce differently -bounce differs depending on user force and speed -typical bounce frequency is.1-5mS Effective switch debouncing can also reject EMI and static charge effects -EMI can be periodic (so don't sample synchronously!) -false triggering on static electricity is like a single random input

Debouncing Switches Solutions -Analog filtering -usually an RC delay to filter out the rapid changes in switch output -task is to choose R and C such that the input threshold is not crossed while bouncing is still occurring Vth inout in out 0V

Debouncing Switches Solutions -Cross coupled gates (MC14044) -logic gates lock in one transition with a single-pole, double-throw switch -both switch ($3.69) and chip ($0.38) are expensive -momentary click switches (mega128 board) are ($0.12) Vd d

Debouncing Switches Solutions: -Software -need to minimize CPU usage -independent of clock speed -do not connect to interrupt pins, only programmed I/O -multiple interrupts will tie up processor -don't scan synchronously to noisy devices -identify initial switch closure quickly (100mS max) -Two approaches (of many) -Count based (identify initial closure AND wait AND check for same value) OR (identify initial closure AND check for same value for X cycles) -watch for -CPU speed dependencies (use constant defines) -loop execution times (suggesting the use of timer interrupts) -Digital filter based -mimics an analog filter with first-order recursive low pass filter -includes a software schmitt trigger -good EMI filtering, quick response risky! safer!

Debouncing Switches Solutions: -Count based -from Gansel's “Guide to Debouncing” -routine called from timer interrupt or delay loop -check Port D, bit 2, pushbutton depression, (bit will be grounded) -returns “1' only once per button push, “pulsed output” -looks for a falling edge int8_t debounce_switch() { static uint16_t state = 0; //holds present state state = (state << 1) | (! bit_is_clear(PIND, 2)) | 0xE000; if (state == 0xF000) return 1; return 0; } value of state first pass after reset: return 0 second pass after reset: return 0 after 12 false passes: return 0 after 7 true passes: return 0 after 12 true passes: return 1 after many true passes: return 0 after 5 false passes: return 0

Debouncing Switches Solutions: -Digital filter based -acts like analog RC filter followed by schmitt trigger -nearly continuous output like an analog circuit = 0x3F, 0.75=0xC0, 1.0 = 0xFF uint8_t output=0; //external variable indicating switch state uint8_t debounce_switch2() { static uint8_t y_old=0, flag=0; uint8_t temp; //digital filter part y_old = x_new* y_old*0.75 temp = (y_old >> 2); //this gives y_old/4 y_old = y_old – temp; //do (y_old*0.75) by subtraction //if button is pushed, add 0.25 (3F) of new value (1.0) if(bit_is_clear(PIND, 2)){y_old = y_old + 0x3F;} // //software schmitt trigger if((y_old > 0xF0)&&(flag==0)){flag=1; output=1;} if((y_old < 0x0F)&&(flag==1)){flag=0; output=0;} }

Debouncing Switches Behavior of the digital filter debounce with schmitt trigger

Using Others Code I just showed you several code snippets that you can use. You should understand how they work. You may (wink, wink) probably be tested on them in the future. I offer other pieces of code in the coming weeks. Learn what they do before you use them. In general, don't use code from somewhere else without knowing how it works. An exception would be a well used, well tested library of functions (libc).

Debouncing Switches Types of debouncer output Sometimes we want a continuous output, e.g., organ keyboard. Other times we want a pulsed output, e.g. increment hour alarm. The first counting algorithm (Gansel) gives a pulsed output. The digital filter algorithm gives a continuous output. button push pulsed output continuous output

Debouncing Switches Converting between types of debouncer output To get a pulsed output, from a continuous debouncer: pushed=1 always pushed=0 idle pushe d waitin g output = 0 output = 1

Debouncing Switches Converting between types of debouncer output To get a continuous output, from a pulsed output: Note that this requires sensing rising and falling edges. pushed=rising edge pushed=falling edge idle pushe d output = 0 output = 1