Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Button debounce tips?

Status
Not open for further replies.

ltg

Member level 4
Joined
Feb 24, 2002
Messages
76
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
533
button debounce

Hi,

Can anybody give me a smart button debounce algorithm without using time delays? Thanks!

Best regards,
ltg
 

ME

Advanced Member level 4
Joined
Mar 14, 2002
Messages
1,309
Helped
55
Reputation
112
Reaction score
40
Trophy points
1,328
Activity points
14,861
debounce button

For which MCU and which language, C or assembler?
 
  • Like
Reactions: keeloq

    keeloq

    points: 2
    Helpful Answer Positive Rating

ltg

Member level 4
Joined
Feb 24, 2002
Messages
76
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
533
pic debounce

Hi,

Sorry for unclear information. It for 8-bit and 16-bit MCU and in language C.

Best Regards,
ltg
 

cozturk

Advanced Member level 4
Joined
Apr 2, 2002
Messages
105
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Activity points
904
debounce in c

I use it by detecting DTMF tones. kt3170.. and 16f84..

It is not important long press or short presss for any time:

for example:

loop:
....
....

if button=0 then loop

if button=1
pause 50ms
if button=0 then loop

loop2:
if button=1 ?
goto loop2

..
..
..

end
 

C-Man

Advanced Member level 4
Joined
Jul 19, 2001
Messages
1,059
Helped
90
Reputation
180
Reaction score
17
Trophy points
1,318
Activity points
10,191
button debouncing

If you are using interrupts simply read your button(s) periodically (for example 50 times per second).

All you have to do is take the last button state, compare it to the current button state and if anything has changed report it to your main program and keep the current button state as last button state.

hope this helps
 

bogdanm

Advanced Member level 4
Joined
Jun 24, 2003
Messages
106
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Activity points
1,215
debounce c

If you want something different, take a look at a smart routine here:

hxxp://www.dattalo.com/technical/software/pic/debounce.html
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
637
Reputation
1,272
Reaction score
88
Trophy points
1,328
Location
USA
Activity points
33,183
debounce algorithm

I agree with C-Man. In most applications, the simplest solution is to sample the button at a steady rate. Use a D-flop and clock, or a software timer interrupt. I usually set the sampling period to be at least twice the worst-case bounce duration. If the button bounces 10 ms, I'll set the clock to 50 Hz.
 

luben111

Advanced Member level 1
Joined
Mar 2, 2002
Messages
491
Helped
111
Reputation
223
Reaction score
107
Trophy points
1,323
Location
UK
Activity points
3,907
how to debounce a button

Hello,

I'm using RTOS and never had such problems. The task that scans the keyboard, wakes up every 10-20ms and read the key status. If there is toggle 1-0 I report key pressed. Using RTOS is very easy to build "long press" buttons, where you can change the functionality of the same key - fast press - INC/DEC, long press - ENTER.
Trust me, for keys and buttons scan RTOS is one excellent solution.

While the task is waiting (10-20ms) other tasks continue working. The whole project becomes very reliable, with smooth operation.

Best regards
Luben
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top