Hello,
I am trying to debounce a button via software but I am some how stuck. Would appreciat if someone could give me a pointer to a solution.
Microcontroller board:
Xmc4500-1024, infineon
Relax kit, arm cortex m4
>>1063845
what I do to debounce buttons is I use two separate functions in the main loop.
one disables all button-input upon pressing and sets an indicator variable, and the other re-enables all button-input and the indicator variable if the desired time delay has passed
the rest of the code is set inside a if--then statement, that checks if button-input is true
Draw a state diagram to help you visualize what's going on.
>>1063845
> debouncing in software
What is this homework or something?
Do people really do this?
>>1063960
yes, why have extra components when you don't have to
>>1063927
This is a link to a debounce arduino sketch I posted a while ago for somebody else here.
http://pastebin.com/bm8BjyT4
One aspect of this is that since the button-reset-timer function is separate from everything else in the main loop, the rest of the program continues to run while it is waiting to accept more button input.
Many of the crappy ways just put a delay() call in there, and the arduino can't do anything else while it's waiting for the button-press time to expire.
>>1063960
> debouncing in software
>What is this homework or something?
>Do people really do this?
It ends up being easier & cheaper than using a debounce chip, plus you can link different button-press delay/repeat times to different buttons or other program states
>>1063845
pointer? you want a pointer?
just sample the level every 5ms (you have the GPIO setup for input on the pin and a timer correct?)
and if it's pressed 5 or more times in a row then declare it debounce pressed
if it loses it it's unpressed
draw a state diagram because your job depends on it