I spent a fair amount of time a few weeks back looking at hardware debouncing for multiple quadrature encoder's inputs to a low power MCU. I didn't want to spend clock cycles working out if a mechanical encoder output was bouncing. I prototyped an R/C -> Schmitt trigger inverter circuit (after working out the resistor components for the time delay) and it worked flawlessly. Throughout the process I learnt more about 74xxx CMOS IC's and electronics so it was a win for me. I was also able to use the same circuit (different component values for more debounce) on some very noisy push button switches.
My project is a model train layout control board (I have mentioned this project in other threads) and will have upwards of 45 momentary push buttons (SPST) to debounce. I know now that there will be significant hardware / PCB design (for me anyway) to implement debounce using the above circuit (given the 74HC14 has only 6 Schmitt triggers for IC) so I am now looking at ways to debounce that number of switches in software - I will be using a Teensy 3.6 that runs a 180MHz ARM processor so I won't (shouldn't) be constrained by clock cycles.
I have used debounce code in previous Arduino projects to debounce a couple of switches and understand how it all works ie. waiting for successive input signals over a period of time before deciding in code if a button is pressed. What I am looking at now is using multiple 74HC165 PISO shift registers to read in 8 buttons at a time. I have read many pages on the net about debounce with shift registers and have read some sample code that I don't quite understand but I think I get the gist of.
Considering just one 8-bit shift PISO register here, if I were to set up a timer based interrupt and read the shift register ever 10ms. If I wanted a 20ms debounce test I would read the 8-bits every 10ms, store them, and then when I had 2 successive reads where the individual bit (in a particular placeholder from the two reads) was a 1 I would then know the button has gone high, likewise two successive 0's would indicate the button is low meaning a 0 and a 1 for a particular bit shows that input as bouncing.
I have written no code yet as I am at the stage of getting an understanding of how to process 45 buttons in an efficient manner. I am not asking anyone to code this for me - I'm asking for some direction before I have a go at it myself.
I'm thinking I could read in two bytes from the shift register over a 20ms period - 2 x interrupt cycles(or whatever the buttons actually needed) and store the byte in a structure/s were I could perform the necessary analysis.
ie. switch1_input = B10010001 //buttons 8,5,1 pressed
switch2_input = B10000000 //buttons 8, pressed
So from the above - button 8 (MSB) is a genuine press and buttons 5 and 1 are bouncing (or changing state).
Can I process these two bytes at once (using bitwise maths) and essentially perform the bounce analysis of 8 buttons at once without iterating through each of the 8 bits - this is what I meant above when I said I was after an efficient manner of debouncing.
I would have another array that held button "state" and when the buttons were found to be pressed just update that array - thats what the rest of my code would look at to read button state.
I don't know enough about bitwise maths to know if I can do this or not. Another thing I noticed was that if I added the bits vertically, a '2' would indicate the HIGH state over two cycles, a "0" a LOW state and "1" would mean its bouncing (or changing state) but to use this method would mean that I would have to go through each byte and do integer maths on each - this sounds inefficient compared to working on 8bits at once.
45 inputs would mean 6 x 74HC165 IC's and it would be nice to perform just 6 bitwise operations each 10ms to perform analysis on the current and previous byte from that register.
Or am I just way off ?