Debouncing Switches. Mechanical switches are one of the most common interfaces to a uc.

Similar documents
CHAPTER 11: Flip Flops

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

Timer A (0 and 1) and PWM EE3376

Monitoring of Intravenous Drip Rate

A Lesson on Digital Clocks, One Shots and Counters

ETEC 2301 Programmable Logic Devices. Chapter 10 Counters. Shawnee State University Department of Industrial and Engineering Technologies

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

A Lesson on Digital Clocks, One Shots and Counters

Voltage boost and buck circuits using Atmel AVR Tiny13V for driving a white LED.

Measuring Resistance Using Digital I/O

Chapter 9 Latches, Flip-Flops, and Timers

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

Master/Slave Flip Flops

DS1621 Digital Thermometer and Thermostat

Below is a diagram explaining the data packet and the timing related to the mouse clock while receiving a byte from the PS-2 mouse:

Nemo 96HD/HD+ MODBUS

DS1621 Digital Thermometer and Thermostat

Interfacing Analog to Digital Data Converters

Programming A PLC. Standard Instructions

1.1 The 7493 consists of 4 flip-flops with J-K inputs unconnected. In a TTL chip, unconnected inputs

How to design and implement firmware for embedded systems

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Real-Time Clock. * Real-Time Computing, edited by Duncan A. Mellichamp, Van Nostrand Reinhold

Lab Experiment 1: The LPC 2148 Education Board

LADDER LOGIC/ FLOWCHART PROGRAMMING DIFFERENCES AND EXAMPLES

3-Digit Counter and Display

AVR Timer/Counter. Prof Prabhat Ranjan DA-IICT, Gandhinagar

Serial Communications

Event counters in NOVA

EC313 - VHDL State Machine Example

CoE3DJ4 Digital Systems Design. Chapter 4: Timer operation

Command Processor for MPSSE and MCU Host Bus Emulation Modes

Scan a Keypad with the BS2 For Pushbutton User Input

How To Use A Watt Saver On A Microcontroller (Watt Saver) On A Cell Phone Or Mp3 Player

MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence :

To design digital counter circuits using JK-Flip-Flop. To implement counter using 74LS193 IC.

Flash Corruption: Software Bug or Supply Voltage Fault?

CHAPTER 11 LATCHES AND FLIP-FLOPS

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

On/Off Controller with Debounce and

Instructions for Setting the T560 Digital Delay Generator for the Target Delay

TRILOGI 5.3 PLC Ladder Diagram Programmer and Simulator. A tutorial prepared for IE 575 by Dr. T.C. Chang. Use On-Line Help

Hello, and welcome to this presentation of the STM32L4 reset and clock controller.

Section 29. Real-Time Clock and Calendar (RTCC)

PART B QUESTIONS AND ANSWERS UNIT I

Accurate Measurement of the Mains Electricity Frequency

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

Section 14. Compare/Capture/PWM (CCP)

Keil C51 Cross Compiler

ZL30136 GbE and Telecom Rate Network Interface Synchronizer

Dolphin In-Circuit programming Updating Firmware in the field

Computer-System Architecture

Procidia Control Solutions Dedicated Backup in a Single Variable Control Loop

16-bit ALU, Register File and Memory Write Interface

AN3265 Application note

Sequential Logic: Clocks, Registers, etc.

Lab #5: Design Example: Keypad Scanner and Encoder - Part 1 (120 pts)

HANDLING SUSPEND MODE ON A USB MOUSE

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

73M1866B/73M1966B FXOCTL Application User Guide November 2, 2009 Rev. 4.1 UG_1x66B_009

Simple Alarm System WIRELESS AND REMOTE CONTROLLED PERSONAL APPLIANCE CODE WORD ORGANIZATION TRANSMISSION FORMAT

Chapter 13. PIC Family Microcontroller

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

Timing Methodologies (cont d) Registers. Typical timing specifications. Synchronous System Model. Short Paths. System Clock Frequency

Digital Controller for Pedestrian Crossing and Traffic Lights

DS Wire Digital Thermometer and Thermostat

Microprocessor & Assembly Language

DNP Points List and Implementation

DS2155 T1/E1/J1 Single-Chip Transceiver

PROGETTO DI SISTEMI ELETTRONICI DIGITALI. Digital Systems Design. Digital Circuits Advanced Topics

DALLAS DS1233 Econo Reset. BOTTOM VIEW TO-92 PACKAGE See Mech. Drawings Section on Website

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

AXI Performance Monitor v5.0

A Practical Approach to Education of Embedded Systems Engineering

Glitch Free Frequency Shifting Simplifies Timing Design in Consumer Applications

Supply voltage Supervisor TL77xx Series. Author: Eilhard Haseloff

ASYNCHRONOUS COUNTERS

Cascaded Counters. Page 1 BYU

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

Computer Organization and Components

8051 MICROCONTROLLER COURSE

Serial Communications

Experiment # 9. Clock generator circuits & Counters. Eng. Waleed Y. Mousa

EE 472 Lab 2 (Group) Scheduling, Digital I/O, Analog Input, and Pulse Generation University of Washington - Department of Electrical Engineering

Small Hardware Development and Prototyping Board for the SX28

1. Memory technology & Hierarchy

Clocking. Figure by MIT OCW Spring /18/05 L06 Clocks 1

Technical Note. Micron NAND Flash Controller via Xilinx Spartan -3 FPGA. Overview. TN-29-06: NAND Flash Controller on Spartan-3 Overview

Flexible Active Shutter Control Interface using the MC1323x

Physics 226 FPGA Lab #1 SP Wakely. Terasic DE0 Board. Getting Started

AN141 SMBUS COMMUNICATION FOR SMALL FORM FACTOR DEVICE FAMILIES. 1. Introduction. 2. Overview of the SMBus Specification. 2.1.

Counters and Decoders

BINARY CODED DECIMAL: B.C.D.

DM74LS169A Synchronous 4-Bit Up/Down Binary Counter

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example

Modeling Sequential Elements with Verilog. Prof. Chien-Nan Liu TEL: ext: Sequential Circuit

路 論 Chapter 15 System-Level Physical Design

Consult protocol, Nissan Technical egroup, Issue 6

DIGITAL COUNTERS. Q B Q A = 00 initially. Q B Q A = 01 after the first clock pulse.

25. AM radio receiver

Transcription:

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.

Switch bounce from a single depress/release of mega128 pushbutton 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 10-300us -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

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 in in out Vth 0V out 0V

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 Vd d

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) risky! safer! -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

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: 1110 0000 0000 0001 return 0 second pass after reset: 1110 0000 0000 0011 return 0 after 12 false passes: 1111 1111 1111 1111 return 0 after 7 true passes: 1111 1111 1000 0000 return 0 after 12 true passes: 1111 0000 0000 0000 return 1 after many true passes: 1110 0000 0000 0000 return 0 after 5 false passes: 1110 0000 0001 1111 return 0

Solutions: -Digital filter based -acts like analog RC filter followed by schmitt trigger -nearly continuous output like an analog circuit - 0.25= 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*0.25 + 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;} }

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).

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

Converting between types of debouncer output To get a pulsed output, from a continuous debouncer: output = 0 idle pushed=1 pushed=0 pushed waiting output = 1 always output = 0

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