Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 10 of 10

Thread: Midi - 8X8 diode matrix vs 16:1 MUX

  1. #1
    Junior Member
    Join Date
    Dec 2016
    Location
    South Africa
    Posts
    15

    Midi - 8X8 diode matrix vs 16:1 MUX

    Midi - 8 X 8 diode matrix vs 16:1 MUX

    What is the difference between using an 8X8 diode matrix, and the CD74HC4067 16:1 mux?

    On my other midi encoders, I use an 8X8 diode matrix to allow me to read 64 digital inputs (keys) but only use 16 wires to connect them to the midi interface. I have been told that you can use four CD74HC4067 16:1 mux's to do the same thing, or I am probably not understanding that fact. Could someone please be kind enough to explain this difference or similarity to me? Is it the same thing? If I use an 8X8 diode matrix to read 64 inputs, the code for that would be different to reading 64 inputs with four of the CD74HC4067 16:1 multiplexers. To use the four multiplexers, how many pins should I need on the Teensy LC? - I think to read the 8X8 diode matric, I would need 8 digital pins.

    Any explanation would be highly appreciated.

    Brian.

  2. #2
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,936
    Really depends on how many pins you have. The chip is a MUX
    https://www.sparkfun.com/products/9056
    So you can take a matrix keypad design and read it by stepping through with a MUX, using fewer pins but adding code complexity since each line read will need to change the MUX control pins.

    If your design works with the matrix of row/columns then no reason to change, but if you wanted to get more keys on the device then it's an option.

    There are lots of ways to read keys, another is http://lucidtronix.com/tutorials/15 using shift registers which gets the needed wires down to three, but adds more layers on the code side.

    Most of these solutions really only come into their own when you are mass producing stuff and being able to use cheap ICs start to matter. If this is a one off project and you needed more wires I'd tend to grab a Teensy LC or micro of your choice and the keypad library https://www.pjrc.com/teensy/td_libs_Keypad.html and interface it via whatever bus system I was already using in the design for a potential 100 or so buttons.

  3. #3
    Junior Member
    Join Date
    Dec 2016
    Location
    South Africa
    Posts
    15
    Thank You. I want to use Teensy LC to read all the notes and pedals played on an organ console, that I am going to 'midify'. I chose Teensy because it is compact and can do Midi out of the box. So typically, I would like to read the following number of keys:

    61 notes on Swell manual
    61 notes on Great manual
    61 notes on Choir manual
    32 pedals on Pedal division

    I have ready but cannot confirm that the Teensy LC which I have bought can be turned into a native midi device. Could you or somebody please confirm this fact please.

    I think I now understand how to connect the MUX's chips to the Teensy. In future I would probably experiment and try to use Teensy 3.6 in order to read the same number of keys and pedals, but also have it switch on or off SOME led's that show when a stop button has been pressed. My main application for now with Teensy will be midi projects - to enable me to play a VPO (virtual pipe organ) without the need to add a computer screen to see which stop has been selected or deselected.

    Brian.

  4. #4
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,372
    Teensy are USB MIDI native!
    All Teensys -- including the T2.x and the LC -- result in a usb-MIDI compliant device that needs no special divers for Mac or Windows when you choose Tools:USB type = "MIDI"

    MUX and Pin Count
    14 x 16 channel MUXs would take 14 return pins plus four to control the MUXs' inputs. You use the same control pins no matter how many MUX you use as each MUX is cycled through the same channel sequence simultaineously (if you use the 'series' configuration as in Paul's diagram).

    There are 32 channel MUX but they don't seem to be price competitive.

    The set-up for the MUXs would be just like the diagram on the usbMIDI page but with four controls instead of three because of the extra bit for 16 rather than 8 channels.

    DEBOUNCE switches
    The biggest challenge might be debouncing your contacts as the BOUNCE library isn't well suited to that many instances (I think!).

    You might want to try something like the suggestion from this thread on the Arduino form which suggests using four readings for each key and watching for the pattern of readings to be b1000 for falling edge and b0111 for rising (which is decimal 8 and 7 when converted to bytes).

    The poster uses macros to implement this and the bit-fiddling may be a bit confusing too:

    //macro for detection of raising edge and debouncing
    #define DRE(signal, state) (state=((state<<1)|(signal&1))&15)==7

    //macro for detection of falling edge and debouncing
    #define DFE(signal, state) (state=((state<<1)|(signal&1))&15)==8


    The state is the 'memory' for the debounce and the signal is the current bit reading from the MUX.
    The state shifts the previous reading one bit over each cycle "(state<<1)" and the signal is added to that with a bit of bit-fiddling.

    You could use these and call something like "if DFE(pinNo[i],pinState[i]) then usbMIDI.sendNote(...)"

    I don't have direct experience with this (yet) so I'm not sure whether the delay cycling through all those readings will be enough on it's own or if you also need to make sure you're only reading the next set of values after enough microseconds have lapsed to debounce your switches reliably.

    Diode switch matrix and MUX
    Diode switch matrix can be controlled with two MUX to cut the number of pins down still more. Two 16 channel MUX could control 16^2=256 switches but that's a lot of wiring if the diodes are not part of the switch mechanisms already.

  5. #5
    Junior Member
    Join Date
    Dec 2016
    Location
    South Africa
    Posts
    15
    Thank you Oddson,

    My thoughts are as follows:

    If I only use a lot of 16:1 mux's, then I could directly wire a switch from a note to a mux input pin, 16 per board, so I would need 4 mux's per manual of 64 notes (The standard of only 61 notes is normally used, it is 5 octaves on the audio range.) So I would need 14 mux's in order to connect the 3 X 61 note manuals, plus the 32 note pedalboard, leaving some 41 input's on the mux's unused, which could be used to control that many stops on the organ. But I am leaning towards using fewer mux's, and connecting an 8X8 diode matrix to each mux. This is done with 16 wires, perfectly partnering with the mux. The same number of notes, would then only require 4 mux's. Do you think this is possible to do? But even before I order the mux's, I need to first learn to talk to my teensy. I have no idea what 'language' the firmware is written in. Is there a resource that I could study that can infrom me about this? I was at a big bookstore yesterday, looking for 'Idiot's guide to Teensy', but all I could find was 'Idiot's guit to Arduinoe'.

    Brian.

  6. #6
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,936
    Normal method for working on a Teensy is Arduino, so most resources apply. Main hassle with your idea of matrixing to muxs is that you need layers of code to convert the button states into digital values. Which is fine if you are happy with the programing side but will add layers of complexity.

    If you have not yet brought anything, would suggest going to the download instructions getting Arduino and Teensy installed and having a look at the examples, and then trying to write code that would get a single mux to read a matrix and make sure it compiles. Won't tell you that it works, but will get your brain in the space of 'how do I actually do this'.

    http://www.pjrc.com/teensy/td_download.html make sure you get the version of Arduino that matches - Arduino is making frequent little updates at the moment,
    Make sure you select Teensy as the device, otherwise it will hide many of the examples, and when you do start programing you need to tell it to you want USB midi code.

    Some of the many learning places
    https://www.arduino.cc/en/Reference/HomePage
    https://learn.adafruit.com/category/learn-arduino
    https://learn.sparkfun.com/tutorials...uino-101-board

  7. #7
    Junior Member
    Join Date
    Dec 2016
    Location
    South Africa
    Posts
    15
    Thank you GremlinWrangler. I will do so.

    Brian.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,001
    Before you go to the trouble of connecting so many wires, I highly recommend first playing with the simpler examples, like File > Examples > Teensy > USB_MIDI > Buttons. That example uses 10 pins for 10 buttons, and you can give it a try by just touching a wire from GND to any of the first 10 pins. Building familiarity with how Teensy is programmed and how you'll get its data onto your PC/Mac will go a long way towards helping you do the more complex ways.

    The matrix approach lets you connect a large number of switches using only wires, and maybe diodes if you care about pressing more than 1 at a time and possible ghosting issues. If you go down that path, check out the examples in File > Examples > Keypad.

    Both of these are more complicated to troubleshoot than just connecting 1 button per pin. The mux approach is a bit simpler to diagnose wiring problems, if you can make it freeze with the mux set to the channel you're troubleshooting. Unless you have excellent craftmanship and tons of experience flawlessly connecting wires, often the thing that can make or break your entire project is not how good the tech is, but how well you are able to find and fix the simple little human mistakes that get made along the way.

  9. #9
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,372
    Quote Originally Posted by sweetbb View Post
    ...But I am leaning towards using fewer mux's, and connecting an 8X8 diode matrix to each mux. This is done with 16 wires, perfectly partnering with the mux. The same number of notes, would then only require 4 mux's...
    While I've not done diode-switching myself yet... I'm virtually certain it can't work like that as you need to read the value from the column while simultaneously activating the row (or vise versa)... a single MUX can only do one or the other.

    Five-eight channel mux could give you 256 switch capacity if you use one to control the active row while reading the columns from the four others.... there are many possible configurations that will work...

    Are you building the hardware from scratch or is this some kind of retrofit?

    You may get better advice if the hardware situation was clearer as the distributed wiring could be a major complicating factor compared with making a 16*16 button controller on a small surface.


    Quote Originally Posted by sweetbb View Post
    ...But even before I order the mux's, I need to first learn to talk to my teensy...
    Yup... don't wait just start.... do the tutorials... make a controller that sends notes from a handful of buttons... then try the peddle-board project you mentioned elsewhere or something like it.
    Then buy the MUX -- or at least one of them -- and spend some time with that making sure you understand how to use it to read (switches?) and write (LEDs?).


    Quote Originally Posted by sweetbb View Post
    ... I have no idea what 'language' the firmware is written in...
    Arduino and Teensyduino are based on C.

    Quote Originally Posted by sweetbb View Post
    ... I was at a big bookstore yesterday, looking for 'Idiot's guide to Teensy', but all I could find was 'Idiot's guit to Arduino'.
    Oxford Press recently published a book Arduino for Musicians that references Teensy specifically in the subtitle.

    I don't know you need it... the tutorials @PJRC.com are as good a place to start as anywhere.

  10. #10
    Junior Member TG626's Avatar
    Join Date
    Dec 2017
    Posts
    4
    I know this is old, but I just happened to come across it...

    I'm an old organ tech, and I've been thinking about this already. My mind keeps going back to Lowrey - their digital models in the 80s read the keys pedals and all the stop tabs by using parallel to serial shift registers. Each switch would go to a parallel input (there were many of these shift registers under the keyboards and behind the stop tab rail) the CPU could then command them all to load and then simple shift the resulting bits into a single input. Once it had clocked all the bit in, it would again send the command to all the registers to load, and the cycle would continue.

    Sadly I don't know what the CPU clock speed was, but being when it was it wasn't anything astronomical to be sure.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •