Lecture Slides on Debouncing Switches | ECE 473, Study notes of Microprocessors

Material Type: Notes; Professor: Traylor; Class: MICROPROCESSOR SYSTEM DESIGN; Subject: Electrical & Computer Engineer; University: Oregon State University; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 08/30/2009

koofers-user-rjm
koofers-user-rjm 🇺🇸

10 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Lecture Slides on Debouncing Switches | ECE 473 and more Study notes Microprocessors in PDF only on Docsity!

Mechanical switches are one of the most common interfaces to a uC. Switch inputs are asynchronous to the uC and are not e lectrically 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 the mega128 board pushbutton 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 input threshold is not crossed while bouncing is still occurring Vth in out in out 0V

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 (ala AVR board) are ($0.12)

Solutions: -Count based -From Gansel's “Guide to Debouncing” -routine called from timer interrupt or delay loop -checks for Port D, bit 2, pushbutton depression, (bit will be grounded) -returns “1' only once per button push, “ pulsed output ” -acts like an edge detector 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 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_new0.25 + y_old0. temp = (y_old >> 2); //this gives y_old/ 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;} }

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 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: pushed= always pushed=

idle

pushed

waiting

output = 0 output = 0 output = 1