Debounce Swt. input to Micro

This is the place for any magazine-related discussions that don't fit in any of the column discussion boards below.
Post Reply
bsparky
Posts: 84
Joined: Mon Aug 09, 2004 1:01 am
Location: Binghamton,NY
Contact:

Debounce Swt. input to Micro

Post by bsparky »

What is the best way to debounce a switch input micro, lest amount of caponents or by software. Tought of checking pin input then pauseing short amount then rechecking. I want to use the dry contacts of a relay for the switch input. Tried it with a momentery swt to ground with the pin tied to +5v thru 10k res. Any other sugestions, Thanks
Engineer1138
Posts: 458
Joined: Thu Feb 05, 2004 1:01 am
Location: Minneapolis, MN
Contact:

Post by Engineer1138 »

The question really can't be answered correctly without knowing your architecture.

There are two methods I normally use:
1) Read switch. Pause .05 second and read again. Accept new state only if the readings match.

2) Software is running in a paced loop or periodic. Read switch each pass through the loop and keep a variable that has the switch state so I only need to read that variable instead of the actual switch when I need to know its state.

HTH
Newz2000
Posts: 507
Joined: Wed May 18, 2005 1:01 am
Location: Des Moines, Iowa, USA
Contact:

Post by Newz2000 »

The technique I've heard of, but haven't had any luck with, supposedly works with an rc circuit. The R value slows down the charge of c so that the ontime is delayed long enough for the contacts to settle down.

I'd like to see a working example of this.

I tried this last fall and gave up, although maybe too quickly. Instead, I found a button debouncing IC from maxim that worked for me.

If you don't mind loosing a little board space, maybe this will be helpful? (can you guess where I got this from?)
Image

{edit}By the way, when I read your post originally I thought you'd asked for a solution that didn't use software... I now understand what you truly said and I suggest using software when available.{/edit}
bsparky
Posts: 84
Joined: Mon Aug 09, 2004 1:01 am
Location: Binghamton,NY
Contact:

Post by bsparky »

Short excerpt from my program its in basic on a Basic Stamp 2 from Parallax.
'-------------------------- Count -------------------------------------------

Counter:


SEROUT Lcd,Baud,[5,1,5,2,1,1,"Parts <---> Pieces"]
SEROUT Lcd,Baud,[3,3,DEC2 Parts,3,17,DEC2 Piece]

Counter1:

DO WHILE Cnt = 0
LOOP
PAUSE 100
Piece = Piece + 1
SEROUT Lcd,Baud,[3,3,DEC2 Parts,3,17,DEC2 Piece]
IF Piece = PieceCnt THEN PartCom


GOTO Counter1

The Do While Loop is were its waiting for the relay contacts to close. Problem I'm also having is if the contact stay closed to long it goes thru the loop many times. I want the program to stay in the counter routine till the if statement is equal. I know I need to redue this counter routine, but not sure how yet. Thanks
bsparky
Posts: 84
Joined: Mon Aug 09, 2004 1:01 am
Location: Binghamton,NY
Contact:

Post by bsparky »

Rat Shack Tech Books :grin: :grin: :grin:
Robert Reed
Posts: 2277
Joined: Wed Nov 24, 2004 1:01 am
Location: ASHTABULA,OHIO
Contact:

Post by Robert Reed »

There are DIP common logic chips available just for this purpose. They are rather pricey though.
JPKNHTP
Posts: 488
Joined: Wed Jun 29, 2005 1:01 am
Location: Missouri
Contact:

Post by JPKNHTP »

-JPKNHTP
-God Bless
bsparky
Posts: 84
Joined: Mon Aug 09, 2004 1:01 am
Location: Binghamton,NY
Contact:

Post by bsparky »

Thanks for the info guys. Will try pausing then rechecking pin and see if that works for me. Wish I know C++ seems to be the universal langauge for a lot of Microcontrolers out there. Let you know how I make out.
User avatar
philba
Posts: 2050
Joined: Tue Nov 30, 2004 1:01 am
Location: Seattle
Contact:

Post by philba »

I've posted it before. Jack Gansle's Guide to Debouncing is just about the bible. A good clear read with lots of great information. http://www.ganssle.com/debouncing.pdf
Robert Reed
Posts: 2277
Joined: Wed Nov 24, 2004 1:01 am
Location: ASHTABULA,OHIO
Contact:

Post by Robert Reed »

Philba
How did you ever find that website? What a wealth of information! Does John Gansle have other topics on the web?
User avatar
philba
Posts: 2050
Joined: Tue Nov 30, 2004 1:01 am
Location: Seattle
Contact:

Post by philba »

for some reason it doesn't come up in google. but i had saved a link.

Jack Ganssle has to be about my favorite technical author these days. great insight and a strong bent for "cost appropriate tools". He does a column in "Embedded System Design" called "breakpoints". Here's the most recent one: http://www.embedded.com/showArticle.jht ... =187203692

He also does a blogish thing called "embedded pulse". You can read his back ones here: http://www.embedded.com/columns/ep/;jse ... CCJUMEKJVN

I warn, you. His stuff is great and you could waste a lot of time reading it.
Engineer1138
Posts: 458
Joined: Thu Feb 05, 2004 1:01 am
Location: Minneapolis, MN
Contact:

Post by Engineer1138 »

I gotta do it :-)

If you want to improve as an embedded developer, do two things:
subscribe to Jack's email newsletter "The Embedded Muse" and buy his first book:
_The Art of Programming Embedded Systems_ It's over 10 years old now, but still extremely relevant. I refuse to part with my copy.
User avatar
philba
Posts: 2050
Joined: Tue Nov 30, 2004 1:01 am
Location: Seattle
Contact:

Post by philba »

published in 1992, I think. it is however, very pricey - $115 new on amazon though i thought it was out of print. even used copies are pretty expensive.
bsparky
Posts: 84
Joined: Mon Aug 09, 2004 1:01 am
Location: Binghamton,NY
Contact:

Post by bsparky »

Exellant sites I'll be reading for awhile. But to let you know what I did with my software, loop till transition high then pause and check agian, if still high go thru loop till it goes low to increase the count, found out the relay my stay closed for differant amounts of times. Seem to work great now, but will test for awhile longer. Thanks guys..........
Engineer1138
Posts: 458
Joined: Thu Feb 05, 2004 1:01 am
Location: Minneapolis, MN
Contact:

Post by Engineer1138 »

philba wrote:published in 1992, I think. it is however, very pricey - $115 new on amazon though i thought it was out of print. even used copies are pretty expensive.
Holy Cow!!! I'm rich!!!

I paid about $30 for mine with the 10% discount I got for being an IEEE member. Never would have thought it was that expensive now!
Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests