??? 07/19/04 16:29 Read: times |
#74463 - RE: Push Button Bouncing Time Method Responding to: ???'s previous message |
If you can afford a timed interrupt, just wait for the button to be in the pressed state for N interrupt where :
N*(delay beetween interrupt)>= 40ms Just : - increment a variable each time the button seems to be pressed - put it at zero else -When the variable is at N you can consider that the button is pressed, if the button is still pressed store the info somewhere use most significant bit of the counter for example if you dont use it for counting, but i don't think it will be very interesting speaking in term of performances (beware, dont forget that 8 bit variables loop FAST ) the longer you wait, the better is the debouncer (as long as you don't mind having a laggy button Never designed this on 8152 but worked perfectly for a whole raw matrix keyboard on a ยต68010/PIT system if you still have problems use a less bouncing button (i ve seen some .4 sec bouces on very old and very much used buttons) your program will look like //do some stuff //wait for the button while(!ButtonState) ; //do some other stuff Regards, Benjamin (I wanted to conclude on the regards like everyone else ;-)) |