I’m into electronics for two months now, so please bear with me.
I’m making an 8-step sequencer with the same functionality as intellijel metropolis (I hope) but instead for the pitch sliders, I’m using rotary encoders and a small i2c oled screen.
Each encoder features a button, so pressing each button changes the sequencer edit mode, and by using the encoders you can change the octave, the note length, the note pattern etc.
Right now the sequencer sends midi messages but I intent to change that to CV hopefully after understanding how to send specific voltages using a dac (I think I will manage after studying how CVpal works).
Another change I want to make is to get rid of the arduino I’m using to drive all these and use a barebones atmega, but right now, I feel that I need the input protection, the pin labelling, the usb powering/ programming.
Now, as I said, I’m using 8 encoders and I’m multiplexing their pinAs using an 4051, I’m multiplexing their pinBs using another 4051 and I’m multiplexing their pin their buttons using yet another 4051.
For each pin and button, in my code, I’m using a flag to mark every one that has been changed since the last loop. If so, utilising an array of timestamps for each item, I mark an do-not-read-again period for it. Thus I’m debouncing all my mechanical inputs.
The code works pretty good but it is using the arduino millis() function which is timer dependent and at some point I will have to use the atmega timers to make a precisely timed device.
So I though I could use a hardware (or hardware assisted) debouncing method. I 've read about using capacitors and a Schmitt trigger with hysteresis, and I’ve read something about a trick involving a shift register (I’ve read this in this forum).
You basically wait until all 8 bytes of the register fill up with the same digit and then you read its value.
I searched on avrlib and I found the debounced switch code uses this technique but I cannot understand it precisely as I’ve barely used C.
- The code says that the read function should be called at a rate of < 100Hz, how is this accomplished? In arduino we have a loop function. In barebones avr programming are we using another kind of loop function that can be timed, or are we using timers for calling some functions?
- If we have 8 encoders do we need 16 shift registers, or can we multiplex them using two muxes and have two shift registers?
- What are the principles of debouncing a switch/ button/ encoder using a shift register? Do we load the register as soon as we detect a change on the switch, or something else?
- How do we manage the clock pin of the register in order to load the values of the switch?
- Which module does use the encoders library, so I can try to study its code?