Debouncing Switches. The non-ideal behavior of the contacts that creates multiple electrical transitions for a single user input.

Similar documents
ELM409 Versatile Debounce Circuit

Monostable multivibrators

High Current MOSFET Toggle Switch with Debounced Push Button

Model 305 Synchronous Countdown System

Course Introduction. Content 20 pages 3 questions. Learning Time 30 minutes

The rangefinder can be configured using an I2C machine interface. Settings control the

PAiA 4780 Twelve Stage Analog Sequencer Design Analysis Originally published 1974

INTEGRATED CIRCUITS. For a complete data sheet, please also download:

The physics of capacitive touch technology

Sequential Logic Circuits

Lab 12: Timing sequencer (Version 1.3)

Electronic Instrumentation

Note 1: A 3A version to the LT1005 is also available. See LT1035 LT V, 35mA AUXILIARY REGULATOR

ULTRASONIC TRANSMITTER & RECEIVER

ADC Bit µp Compatible A/D Converter

INTEGRATED CIRCUITS. For a complete data sheet, please also download:

ASTABLE MULTIVIBRATOR

MAINTENANCE MANUAL AUDIO MATRIX BOARD P29/

Embedded Systems. Oscillator and I/O Hardware. Eng. Anis Nazer First Semester

Once the DS1821 comes up as a thermostat it will not return to 1-wire mode until it receives a special signal sequence, as follows:

I2C Encoder. HW v1.2

EE-110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Lab Timer: Blinking LED Lights and Pulse Generator

νµθωερτψυιοπασδφγηϕκλζξχϖβνµθωερτ ψυιοπασδφγηϕκλζξχϖβνµθωερτψυιοπα σδφγηϕκλζξχϖβνµθωερτψυιοπασδφγηϕκ χϖβνµθωερτψυιοπασδφγηϕκλζξχϖβνµθ

Module 4: Combinational Logic Glitches and Hazards

Microcontrollers and Interfacing

TAPR TICC Timestamping Counter Operation Manual. Introduction

HIGH LOW Astable multivibrators HIGH LOW 1:1

Module -18 Flip flops

ANALOG TO DIGITAL CONVERTER

+15 V 10k. !15 V Op amp as a simple comparator.

Sequential Logic Circuits

ADP1043A Evaluation Software Reference Guide EVAL-ADP1043A-GUI-RG

DEPARTMENT OF ELECTRICAL ENGINEERING LAB WORK EE301 ELECTRONIC CIRCUITS

Additional Programs for the Electronics Module Part No

8-bit Microcontroller with 512/1024 Bytes In-System Programmable Flash. ATtiny4/5/9/10

DIGITAL UTILITY SUB- SYSTEMS

Low Skew CMOS PLL Clock Drivers

EE445L Fall 2014 Quiz 2A Page 1 of 5

Hello, and welcome to this presentation of the STM32G0 digital-to-analog converter. This block is used to convert digital signals to analog voltages

EE283 Electrical Measurement Laboratory Laboratory Exercise #7: Digital Counter

Lab 1.2 Joystick Interface

EE445L Fall 2014 Quiz 2A Page 1 of 5

Description and Instructions for the Firmware of Processing FPGA of the ADC250 Boards Version 0x0C0D. 20 February Hai Dong

1 Second Time Base From Crystal Oscillator

Design and build a prototype digital motor controller with the following features:

Counter/Timers in the Mega8

SRVODRV REV7 INSTALLATION NOTES

Berkeley Nucleonics Corporation Model 725 Multi-Trigger Digital Delay Generator User Guide. Documentation for the Model 725 and timerpro Software

). The THRESHOLD works in exactly the opposite way; whenever the THRESHOLD input is above 2/3V CC

The Basics Digital Input

HAZARDS AND PULSE MODE SEQUENTIAL CIRCUITS

16.1 ADC ADC ADC10

Application Note. PWM Control for PC Fans AN-CM-248

DS1869 3V Dallastat TM Electronic Digital Rheostat

ELG3331: Digital Tachometer Introduction to Mechatronics by DG Alciatore and M B Histand

Hello, and welcome to this presentation of the STM32L4 comparators. It covers the main features of the ultra-lowpower comparators and some

EE445L Fall 2014 Quiz 2B Page 1 of 5

Lecture 11: Clocking

Due date: Sunday, November 8 (midnight) Reading: HH sections , (pgs , )

+5V, Low-Power µp Supervisory Circuits with Adjustable Reset/Watchdog

Peripheral Sensor Interface for Automotive Applications

LM555 and LM556 Timer Circuits

Electronic Instrumentation ENGR-4300 Fall 2004 Section Experiment 7 Introduction to the 555 Timer, LEDs and Photodiodes

Hardware Flags. and the RTI system. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

University of California at Berkeley Donald A. Glaser Physics 111A Instrumentation Laboratory

Fig 1: The symbol for a comparator

Basic Logic Circuits

Section 35. Output Compare with Dedicated Timer

7I30 MANUAL Quad 100W HBridge

CMOS Serial Digital Pulse Width Modulator INPUT CLK MODULATOR LOGIC PWM 8 STAGE RIPPLE COUNTER RESET LOAD FREQUENCY DATA REGISTER

1X6610 Signal/Power Management IC for Integrated Driver Module

Fixed-function (FF) implementation for PSoC 3 and PSoC 5LP devices

HW D2: Sequential Logic, Counters, Debounce

Monitoring of Intravenous Drip Rate

Multiplexer for Capacitive sensors

Instrument Cluster Display. Grant Scott III Erin Lawler Mike Carlson

PWM System. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Course Introduction Purpose: Objectives: Content Learning Time

Debugging a Boundary-Scan I 2 C Script Test with the BusPro - I and I2C Exerciser Software: A Case Study

Digital Logic Troubleshooting

Capstone Design Course

Process Components. Process component

ANLAN203. KSZ84xx GPIO Pin Output Functionality. Introduction. Overview of GPIO and TOU

Fixed-function (FF) implementation for PSoC 3 and PSoC 5 devices

The SOL-20 Computer s Cassette interface.

Embedded Systems and Software

COMP 4550 Servo Motors

Setup Period. General Description

DIGITAL INTEGRATED CIRCUITS A DESIGN PERSPECTIVE 2 N D E D I T I O N

ENGG1015: lab 3. Sequential Logic

Peripheral Sensor Interface for Automotive Applications

KNX manual 1-channel flush-mounted switch actuator SU 1

To design/build monostable multivibrators using 555 IC and verify their operation using measurements by observing waveforms.

Peripheral Sensor Interface for Automotive Applications

MICROCONTROLLER TUTORIAL II TIMERS

CMOS Serial Digital Pulse Width Modulator INPUT CLK MODULATOR LOGIC PWM 8 STAGE RIPPLE COUNTER RESET LOAD FREQUENCY DATA REGISTER

Pololu TReX Jr Firmware Version 1.2: Configuration Parameter Documentation

Module 3. Embedded Systems I/O. Version 2 EE IIT, Kharagpur 1

Current-Mode PWM Multiple Output Flyback Converter

HC900 Hybrid Controller

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.

Falling and rising edge switch bounce from a pushbutton switch

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 100s 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 100us-10ms Specifications for Panasonic EVP-BD6C1A000 pushbutton switch

One possible solution - Analog filtering RC network filters out the rapid changes in switch output Choose R and C so input threshold is not crossed while input is still bouncing in R1 10k R2 10K S1 v5.0 U1 is a schmitt trigger inverter similar to a 74HC14 U1 R3 in out 470 C1 0.1uF Vth 0V out t RC filter is formed by R1,R2 and C1. R2 also protects S1 from excessive current when S1 is closed. R3 protects U1 from capacitor dumping current into input pin when power is removed. v5.0 10k 0V t U1

Another solution would be to use a latch U1 is a schmitt (MC14044) trigger inverter U1 Logic gates lock change in 2t pd using R3 a inspdt switch R2 470 C1 Both switch ($3.69) and chip 10K ($0.38) are expensive S1 Momentary click switches (AVR board) are ($0.12) R1 10k v5.0 0.1uF similar to a 74HC14 RC filter is formed by R1,R2 and C1. R2 also protects S1 from excessive current when S1 is closed. R3 protects U1 from capacitor dumping current into input pin when power is removed. out v5.0 10k S1 U1 output 10k U2 usage model

Software solutions Need to minimize CPU usage and be independent of CPU clock speed Use constant defines in makefile to remove speed dependencies Don t use interrupt pins, only periodic polling Don t synchronously scan noisy devices Quickly identify initial switch closure (100mS max)

Count-based software solution // source : Jack Gansel, " Guide to Debouncing " // returns 1 once per button push, detects falling edge uint8_t debounce_pulse () { static uint16_t switch state = ( state << 1) (! bit_is_clear ( PIND, 2)) 0 xe000 ; if ( state == 0 xf000 ) return 1; return 0; } Which pass Value of state Return value 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

Solution based on digital 1st-order recursive low-pass filter // Acts like RC filter followed by schmitt trigger // continuous output like an analog switch // 0.25=0 x3f, 0.75=0 xc0, 1.0=0 xff int8_t debounce_cont (){ static uint8_t y_old =0, flag =0; uint8_t temp ; } // digital filter : y_old = x_new *0.25 + y_old *0.75 temp = ( y_old >> 2); // yields y_old /4 y_old = y_old - temp ; //( y_old *0.75) by subtraction // if button pushed, add 0.25 if( bit_is_clear ( PIND,2)){ y_old = y_old + 0 x3f ;} // software schmitt trigger if (( y_old > 0 xf0 ) && ( flag ==0)){ flag =1; return 1;} if (( y_old < 0 x0f ) && ( flag ==1)){ flag =0; return 0;} return ( -1); // no change from last time

Behavior of the digital filter debouncer with schmitt trigger First Order Digital Filter Debouncer Behavior PIND, 2 output 250 3F 63 6F 111 93 147 6F 111 93 147 6F 111 93 147 AE 174 C2 194 D1 209 DC 220 E4 228 EA 234 EF 239 F3 243 F6 246 B9 185 CA 202 D7 215 E1 225 E8 232 ED 237 F1 241 upper threshold 200 y_old 150 100 50 15 lower threshold

falling edge Debouncing Switches output = 1 PUSHED Sometimes we want an output that is continuous for as long as the debounce_cont = 1 always switch contacts are in their active state. For example, the keys on an electronic keyboard. output = 0 output = 0 Other times we want a momentaryidle or pulsed output, WAITsuch as a button that increments the hour alarm on a clock. The first count-based debouncer (Gansel) gave a pulsed output. debounce_cont = 0 The digital filter algorithm gives a continuous output. raw button push pulsed output continuous output

How would you convert between types of debouncer output? Use a state machine to get a pulsed output from a continuous debouncer. // state machine returns one pulse for each push and release static enum button_state_type { IDLE, PUSHED, WAIT } state ; switch ( state ){ case ( IDLE ) : output =0; if( debounce_cont ()){ state = PUSHED ;} break ; case ( PUSHED rising ): edge output =1; state = WAIT ; break ; case output ( = 0WAIT ) : output output =0; = 1 if( debounce_cont ()){ state = IDLE ; } break ; default OFF : PUSH break ; }// switch falling edge PUSHED output = 1 debounce_cont = 1 always output = 0 IDLE WAIT output = 0 debounce_cont = 0

A state machine for continuous output from a pulsed debouncer. This scheme requires rising and falling edge detection. // 2 state state machine returns continuous output static enum button_state_type { OFF, PUSH } state ; switch ( state ){ case ( OFF ) : if( debounce_fpulse ()){ state = PUSH ;} break ; case ( PUSH ): output =1; if( debounce_rpulse ()){ state = OFF ;} break ; default : break ; }// switch rising edge output = 0 output = 1 OFF PUSH falling edge PUSHED output = 1 debounce_cont = 1 always