Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

Flowchart for Pushbutton

Status
Not open for further replies.

ansh11

Member level 4
Joined
Feb 27, 2018
Messages
71
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
659
I am trying to understand switch bounce technique. I have seen tutorials and I have come up with some idea and I have created one flow chart


Push Button.jpg



  1. Set periodic timer for 10ms
  2. read the button state at every 10ms and store into variable CurrentState
  3. Save the state of button into variable LastState
  4. Compare previous state with current state of button
  5. if both are same increment count
  6. check if counter has reached its maximum value
  7. if we get continues same state, button press was considered valid state
@KlausST I hope you can help me with flowchart
 

Hi,

some issues:
* it seems to be an infinite main loop. While this is possible.... it´s a waste of 100% processing power. The processor can´t do anything else.
* in the 3rd box you set LastState=CurrentState; in the next box you do an "IF LastState == CurrentState" ... there never can be "NO"
* you don´t initialize count. Let´s guess it starts with 0. In box 5 you increment it. Now it´s 1. In the next box you do an "IF count > 5". --> the answer is: NO. Then you set it to 0 again. The value of count can never be 2......is this what you want?
* in the bottom box you say "Button pressed". This is not true. It can also be "button released"
... and when you have a command "button pressed" in your code, then you always need code for anything else than "button pressed".
* count will be incremented every loop.... until rollover

******
I recomend to use a sheet of paper an a pencil and go step by step through your chart. In each loop write down all the values, do all the compares...

Klaus
 
  • Like
Reactions: ansh11

    ansh11

    Points: 2
    Helpful Answer Positive Rating
Do you want the button considered pressed if it just meets the count or
do you want to consider it a legit button once released, bounced out,
as well ?


Regards, Dana.
 
  • Like
Reactions: ansh11

    ansh11

    Points: 2
    Helpful Answer Positive Rating
Do you want the button considered pressed if it just meets the count or
do you want to consider it a legit button once released, bounced out,
as well ?
I am not fully confident in the basics right now. I see there are the two case, pressed and released. I think When we press or release the button both the time switch will debounce for few millisecond.

I will check the push-button value every 10 mS: I will accept a change only if the new value remains stable five times,
 

Take a look at this, various methods, algorithms as well.

Attached.

Note I see folks using various delays. I had a case where I measured > 300 mS in a
part, crappy to say the least. More often I see folks using 100 mS for de-bounce design
work.

Regards, Dana.
 

Attachments

  • debouncing.pdf
    333.3 KB · Views: 125

Hi,

Bouncing time depends on the switch. Older, high current, spring loaded tend to higher bouncing time.
Modern switches should not bounce more than 10ms.

For inputs when one wants a value to count up, one get almost 10 pulses per second. So in ideal case 50ms / 50ms.
I usually go to 20ms debouncing time.

There is no single "best" solution.

Klaus
 

Debounce time, if you can, play it safe, use 100 mS or more. Some use short time on
bounce in, and longer time on bounce out. That way key task is triggered rapidly, and
bounce out covers any longer poor switch bouncing times in and out.

If its a rapid switch rep rate, like used on industrial processes, then qualify the component
by looking at DSO captures of bounce.

Play it safe, especially in human safety applications.


Regards, Dana.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top