We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
whether the following debouncing logic will work well: the total cycle for code is 50ms and each function is executed only once during the cycle.
void main() { signed int deb_Counter=0; while(1) { input(); process(); output(); } } int debounce() { if(key_pressed) { deb_Counter++; } else { deb_Counter--; } if(deb_Counter>10) { deb_Counter=0; return(1); } else { deb_Counter=0; return(0); } }
this code is reffered from web with thanks, karthik
hello kartik.
you can call debounce function from main and debug it. you will come to know is the timing parameters you defined is correct or not.
Regards ankit thakkar
the fact that it does not even compile does not seem to disturb you...
this debounce function will be called in input function sorry for not mentioning it.
void main() { signed int deb_Counter=0; while(1) { input(); process(); output(); } } void input() { int status=debounce(); } int debounce() { if(key_pressed) { deb_Counter++; } else { deb_Counter--; } if(deb_Counter>10) { deb_Counter=0; return(1); } else { deb_Counter=0; return(0); } }
with thanks, karthik
Ahhem ...
You've done nothing to fix 'deb_Counter'.
And a glaring logic error ...
In 'debounce' you check for deb_Counter being greater than 10.
If it is, you reset to zero. If it isn't, you reset to zero.
How would it ever manage to get anywhere near 10?
Maybe you should return to first principals before embarking on a task such as this.
because you have no idea what you're doing - sorry.
void input() { int status=debounce(); }
and
void main() { signed int deb_Counter=0; while(1) {
But the input function doesn't do anything with the result!
As Tamir says, you need to set this aside and take a few steps back to actually learn how to program in 'C'.
this code is reffered from web
you have no idea what you're doing
If you do not fully understand code you grab from the web you are, in 99% of the cases, totally screwed.
Erik
PS it is, in my opinion, totally ridiculous not to use a timer for debounce, let alone the total uncertainty of the time a delay written in C takes.