Tutorial: De-bouncing circuits By Ibrahim Kamal Last update: 7/5/08

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

Measuring Resistance Using Digital I/O

CHAPTER 11: Flip Flops

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

Degree programme in Automation Engineering

MAS.836 HOW TO BIAS AN OP-AMP

Unit 24: Applications of Pneumatics and Hydraulics

Programming Logic controllers

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

Designing VM2 Application Boards

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

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

Digital to Analog and Analog to Digital Conversion

Table 1 Comparison of DC, Uni-Polar and Bi-polar Stepper Motors

Interfacing Analog to Digital Data Converters

Operating instructions Diffuse reflection sensor. OJ50xx / / 2004

Harmonics and Noise in Photovoltaic (PV) Inverter and the Mitigation Strategies

Recognizing and understanding schematic symbols will enable you to comprehend a circuit s function.

Lab 7: Operational Amplifiers Part I

A Lesson on Digital Clocks, One Shots and Counters

Using the JNIOR with the GDC Digital Cinema Server. Last Updated November 30, 2012

Whale 3. User Manual and Installation Guide. DC Servo drive. Contents. 1. Safety, policy and warranty Safety notes Policy Warranty.

Designing Gain and Offset in Thirty Seconds

HANDLING SUSPEND MODE ON A USB MOUSE

Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module

Servo Info and Centering

conventional system operation

DIGITAL-TO-ANALOGUE AND ANALOGUE-TO-DIGITAL CONVERSION

Programmable Single-/Dual-/Triple- Tone Gong SAE 800

CHAPTER 11 LATCHES AND FLIP-FLOPS

Chapter 6: From Digital-to-Analog and Back Again

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

Ocean Controls RC Servo Motor Controller

Analog Servo Drive 25A8

AAT3520/2/4 MicroPower Microprocessor Reset Circuit

How to design and implement firmware for embedded systems

LAB4: Audio Synthesizer

Bi-directional level shifter for I²C-bus and other systems.

Current Loop Tuning Procedure. Servo Drive Current Loop Tuning Procedure (intended for Analog input PWM output servo drives) General Procedure AN-015

Rotating Machinery Diagnostics & Instrumentation Solutions for Maintenance That Matters

Selecting and Implementing H-Bridges in DC Motor Control. Daniel Phan A

Introduction to Electronic Signals

How To Calculate The Power Gain Of An Opamp

Servo Motors (SensorDAQ only) Evaluation copy. Vernier Digital Control Unit (DCU) LabQuest or LabPro power supply

cs281: Introduction to Computer Systems Lab08 Interrupt Handling and Stepper Motor Controller

Having read this workbook you should be able to: recognise the arrangement of NAND gates used to form an S-R flip-flop.

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

ARRL Morse Code Oscillator, How It Works By: Mark Spencer, WA8SME

Pulse Width Modulation

Working with microcontroller-generated audio frequencies (adapted from the Machine Science tutorial)

1.5A Very L.D.O Voltage Regulator LM29150/29151/29152

Fundamentals of Signature Analysis

PID Control. Proportional Integral Derivative (PID) Control. Matrix Multimedia 2011 MX009 - PID Control. by Ben Rowland, April 2011

A Lesson on Digital Clocks, One Shots and Counters

Controlling a Dot Matrix LED Display with a Microcontroller

UPS PIco. to be used with. Raspberry Pi B+, A+, B, and A. HAT Compliant. Raspberry Pi is a trademark of the Raspberry Pi Foundation

Supply voltage Supervisor TL77xx Series. Author: Eilhard Haseloff

1ED Compact A new high performance, cost efficient, high voltage gate driver IC family

A Digital Timer Implementation using 7 Segment Displays

Analysis of Micromouse Maze Solving Algorithms

PHYS 2P32 Project: MIDI for Arduino/ 8 Note Keyboard

Procidia Control Solutions Dedicated Backup in a Single Variable Control Loop

Analog Signal Conditioning

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

THE INPUT/OUTPUT SYSTEM. Key Points

Inductors. AC Theory. Module 3

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

TwinCAT NC Configuration

Operational Amplifier - IC 741

Hands On ECG. Sean Hubber and Crystal Lu

Mach3 Tutorial Setting up a basic three axis milling machine. Based on Mach3 2.0

Digital to Analog Converter. Raghu Tumati

Ignition Alert Anti-Theft Security System for Motorbikes with Remote Control Amit Yadav, Anushri Jha, Neelesh Gupta

How To Program An Nxt Mindstorms On A Computer Or Tablet Computer

Flash Corruption: Software Bug or Supply Voltage Fault?

RS-485 Protocol Manual

LAB 7 MOSFET CHARACTERISTICS AND APPLICATIONS

2 : BISTABLES. In this Chapter, you will find out about bistables which are the fundamental building blocks of electronic counting circuits.

GLOLAB Two Wire Stepper Motor Positioner

EET272 Worksheet Week 9

25. AM radio receiver

PS 155 WIRELESS INTERCOM USER MANUAL

T-SERIES INDUSTRIAL INCLINOMETER ANALOG INTERFACE

An Introduction to MPLAB Integrated Development Environment

ends of transmission line are used for relay operation [70]. Another type of

SL720 GYRO/PC INTERFACE MANUAL

PICNet 1. PICNet 1 PIC18 Network & SD/MMC Development Board. Features. Applications. Description

LUCCI AIRFUSION QUEST II CEILING FAN

CONSTRUCTING A VARIABLE POWER SUPPLY UNIT

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

RGB for ZX Spectrum 128, +2, +2A, +3

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

Pulse Width Modulated (PWM) Controller for 12 Volt Motors

BUILD YOUR OWN RC SWITCH (Issue 3)

AN3265 Application note

Neonixie 6 Digit Nixie Clock Controller Introduction and Assembly

Design and Applications of HCPL-3020 and HCPL-0302 Gate Drive Optocouplers

PLL frequency synthesizer

ezsystem elab16m Project 1F: Alarm System (Full Project description)

GETTING STARTED WITH LABVIEW POINT-BY-POINT VIS

Transcription:

` Home Store Products and Resources Forums Consulting About us Contact Username: Password: Remember me Login Home General electronics Follow us: Tutorial: De-bouncing circuits By Ibrahim Kamal Last update: 7/5/08 www.victorinox.com Ads by Google Overview This article deals with a very common problem that occurs in any circuit - more precisely digital circuits - that contains input from a mechanical switch. When a switch is operated by a human like a push button, or is operated by a machine like limit switches, spikes of low and high voltages will always occur across that switch resulting into a series of High and Low signals that can by interpreted by a digital circuit as more that one pulse instead of one clean pulse or transition from a logic state to another. The Problem Figure 1A shows a basic switch configuration with a pull up resistors, which will output 0V when pressed and 5V through the resistor when released. This switch configuration can be reversed to output 5V when pressed and 0V when released back, but we will study this configuration as it is a standard for all inputs of 8051 microcontrollers and any active low input. The problem with this configuration, as described briefly before is that, due to the mechanical nature of any switch that may contains spring return action of some kind, there wont be a clean transition from a state to another, but instead there will be a series of high and low states spikes as shown in figure 1B. This series of spikes can be interpreted by a microcontroller Fig. 1A: A simple switch configuration without a de-bouncing circuit

(or any digital circuit) as if the button was pressed many times. It may even have happened to you before when you connected a switch to a counter of any kind, and notice that on press on the button is sometimes counted as more than one push. Figure 1B also shows approximately the ranges of voltages where a signal is considered as a HIGH signal (Logic 1) or LOW one (Logic 0) The 'unknown' range can be recognized by some a digital circuit as 1 or 0, but in a completely random manner. Fig. 1B: Behavior of a switch without a de-bouncing circuit The Solution There are 2 common solutions to this problem. Analog solution, and digital micro-controller based solution. Both are commonly used, and sometimes, both are used at the same time to provide a very stable design. The analog de-bouncing circuit The analog solution relies principally on a capacitor, which plays the role of resisting the voltage changes on the output. In other words, this will prevent the the output to change too fast which will prevent High and Low pulses to appear on the output. A de-bouncing circuit can be tuned exactly to your requirements, it can be adjusted to choose which pulse is rejected and which one is accepted. Figure 2A shows how to assemble a switch de-bouncing circuit. The values of the resistor R1 and the capacitor C1 will determine the response speed of the switch. The more you increase R1 and/or C1, the more your circuit become immune to errors, but the more time it takes to react and give adequate output. It's up to you to chose the values of R1 and C1, using trial and error (or calculations) until you get the suitable response for you application. Good starting values for a general purpose de-bouncing circuit would be R1 = 10 K and C1 = 100nF ceramic capacitor. It is clear on figure 2B, that the addition of a capacitor made the voltages rise smooth and clean as compared to the spikes in figure 1B. But even though the addition of a capacitor, you can notice that, while rising from 0 to 5 v, the voltage passes through a range where the output is unknown (shaded in yellow in the figure), which will again cause some error pulses to appear on the output. Fig. 2A: A switch with a de-bouncing circuit This last minor problem can be fixed by adding a schmitt trigger. Shortly, a shmitt trigger will keep

its outputs unchanged during the passage through the 'unknown' zone, until the input have safely reached above or below some threshold values, which define the High and Low logic states. In other words, a schmitt trigger hocked to the output will eliminate the error pulses generated when the button was released and will give straight output, clean of any errors. Fig. 2B: A switch with a de-bouncing circuit Figure 2C shows the symbol of a schmitt trigger buffer. A very similar configuration is used as a power on reset circuit for many microcontroller, to provide them with a 'reset' pulse some milliseconds after the device have been turned ON. Fig. 2C: A switch with a de-bouncing circuit and schmitt trigger output The software based de-bouncing The approach for a software based de-bouncing circuit is totally different than what was discussed before. The idea here is not to prevent voltage spikes to occur, but rather to record them and analyze them in real-time using simple software routines. Fig.3A You should now be familiar with the digital pulses in the figure 3A. The timing T1, T2 and T3 corresponds to the low (logic =0) pulses being sent to the microcontroller from the switch. T1 and T2 are the length of the reading we want to get rid off, or more scientifically, that we want to filter. T3 is a valid reading that we want to take in account. It is clear that the difference between those three periods is their length, and that is how the micro-controller will be able to differentiate between valid and un-valid pulses. There are many ways to implement digital de-bouncing or filtering using a microcontroller, one simple method is to make a counter count up as long as the signal is Low, and reset this counter when the signal is High. If the counter reach a certain fixed value, which should be 1 or 2 times bigger than T1 or T2 (noise pulses), this means that the current pulse is a valid pulse (corresponds to T3 in our example) This algorithm can be implemented for 8051 microcontroller using C code as in the following example: Note that in this example, the signal to be filtered is connected to the first pin of Port 1 (P1_0)

Example C Code for 8051 microcontrollers #include <REGX52.h> #include <math.h> unsigned char counter; //Variable used to count unsigned char T_valid; //Variable used as the minimum duration of a valid pulse void main(){ P1 = 255; // Initialize port 1 as input port T_valid = 100; //Arbitrary number from 0 to 255 where the pulse if validated while(1){ //infinite loop if (counter < 255){ //prevent the counter to roll back to 0 counter++; if (P1_0 == 1){ counter = 0; //reset the counter back to 0 if (counter > T_valid){ // Code to be executed when a valid pulse is detected. //Rest of you program goes here. www.saleae.com Ads by Google Application of de-bouncing circuits The most famous application for a de-bouncing circuit is for cleaning the output of limit switch or push buttons. However, there are other situations where similar approaches may be used. For example, shaft encoders, that are essential in most robots are sometimes subjected to vibrations that can cause more pulses to be generated by the shaft encoder than the actual correct number of pulses corresponding to the movement of the shaft of the motor. Also linear position encoders are prone to the same problem. As you may have noticed before, the analog de-bouncing circuit, can be simply used as to filter the noise from a signal. but be careful, while using too big values for R and C will result in a very immune system, it will also cause very slow response, and valid pulses may as well be rejected with other noise. You have to tune your circuit with the suitable values of C and R to fit to your requirement. Any questions? find answers or ask your question in ikalogic forum Unless mentioned, all content is written and designed by Ibrahim Kamal, copying is prohibited and unethical Home Forums Store contact Check mail About Ibrahim KAMAL

Ads by Google Circuit Capacitor Relay Switch Bouncing Piezo Switch All content on this site is provided as is and without any guarantee of any kind. We cannot be held responsible for any errors, omissions, or damages arising out of use of information available on this web site. IMPORTANT COPYRIGHT NOTE: Electronics and Robotics Articles by Ibrahim KAMAL are licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.