Debounce Swt. input to Micro
Debounce Swt. input to Micro
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
-
- Posts: 458
- Joined: Thu Feb 05, 2004 1:01 am
- Location: Minneapolis, MN
- Contact:
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
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
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?)
{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}
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?)
{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}
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
'-------------------------- 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
-
- Posts: 2277
- Joined: Wed Nov 24, 2004 1:01 am
- Location: ASHTABULA,OHIO
- Contact:
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
-
- Posts: 2277
- Joined: Wed Nov 24, 2004 1:01 am
- Location: ASHTABULA,OHIO
- Contact:
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.
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.
-
- Posts: 458
- Joined: Thu Feb 05, 2004 1:01 am
- Location: Minneapolis, MN
- Contact:
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..........
-
- Posts: 458
- Joined: Thu Feb 05, 2004 1:01 am
- Location: Minneapolis, MN
- Contact:
Holy Cow!!! I'm rich!!!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.
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!
Who is online
Users browsing this forum: No registered users and 33 guests