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

Thread: Read analog inputs in a matrix with multiplexer 4051

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    13

    Read analog inputs in a matrix with multiplexer 4051

    Hi All

    I know I can read an 8x8 matrix of buttons using two 4051 multiplexers and a lot of diodes. Can one do the same for analog inputs (potentiometers)? What I am thinking is that the +V of the pots are the columns to which I send a value of 1023 via one multiplexer and then I the pot outputs are the rows, using the same reading method as for the button matrix. Is this feasable? Do I need diodes and if so on the input or the output side?

    What about timing? Do the pots have a lag time once powered (via the columns) before I can read them?

    Cheers

    Chris

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,323
    Normally a matrix is NOT used for pots.

    See this page for info. Scroll down to "Connecting Many Buttons & Knobs/Sliders"

    http://www.pjrc.com/teensy/td_midi.html

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    13
    Quote Originally Posted by PaulStoffregen View Post
    Normally a matrix is NOT used for pots.
    Normally maybe not, but can it be done? I have seen that page but using that method I would need loads of 4051's and space is an issue.

  4. #4
    Senior Member
    Join Date
    Mar 2013
    Posts
    651
    Quote Originally Posted by ChrisLaurie View Post
    Normally maybe not, but can it be done? I have seen that page but using that method I would need loads of 4051's and space is an issue.
    Its possible(not easy), what are you trying to do and how fast do you need to do it?

  5. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    13
    I'm building a midi controller. Due to space constraints I can fit the teensy and 4 multiplexer on the board. So 2 of them in a matrix drives 64 buttons that's cool. I need more than the 16 that 2 x 8 demux will give me. It does not need to be superfast just fast enough to detect a user moving a joystick that in turn will cause a moving head to move, or a fader to come down on the lighting software.

  6. #6
    Senior Member
    Join Date
    Mar 2013
    Posts
    651
    After looking a little harder i'm not sure it can be done, if you hook them up as I have done the second row will always interfere with the first row during reads. Even if you could set the input/gnd to high impedance it would still interfere since you have pots in series/parallel with each other.

    If you wired several pots to 1 input and had the top/bottom of the pots tied to a logic IC that could give +/- and High inpedance it could be done.
    I could go into more detail but I just noticed im late for work.....


  7. #7
    Junior Member
    Join Date
    Mar 2014
    Posts
    13
    Thanks Donziboy - please don't be late for work!! Thats whet we need to keep doing this stuff

    So, It does not look good. Would a diode on the data line not fix the issue?

  8. #8
    Senior Member
    Join Date
    Mar 2013
    Posts
    651
    At work
    Adding diodes will not work if you do a column of pots, if you had 8 pots in series the last one would have a max voltage of 1/8*vcc and a minimum of whatever the diode drop is.
    Which most likely would be higher then the voltage on pot #8 could go.

  9. #9
    Senior Member
    Join Date
    Mar 2013
    Posts
    651
    Have you considered external ADC's? Like the MCP3208, there are tons of External ADC's on the market

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,323
    Quote Originally Posted by ChrisLaurie View Post
    I'm building a midi controller. Due to space constraints I can fit the teensy and 4 multiplexer on the board.
    These large-number-of-input MIDI controller projects can be made easier or terribly frustrating by how easy or difficult your physical construction allows accessing the wires and parts. Almost all builds end up needing something fixed. If your wires plug and unplug easily with connectors you can access, and if the pots and buttons all produce 0 to 3.3V analog voltages you can easily check with a multimeter, troubleshooting is much easier. Likewise for a layout that is clear and easy to see which things go where.

    Sometimes optimizing circuity with matrix scanning and compressing everything into a tight space makes troubleshooting very hard.

  11. #11
    Junior Member
    Join Date
    Mar 2014
    Posts
    13
    Well an external DAC would give me the same, 8 values and 8 values. I'm looking at creating a matrix of 64 pots. What I had in mind is something like the image below. Where C1 and C2 are the first 2 columns of the "sending" mux and W1 to W8 are the inputs of the receiving mux. The "sending" mux sends a value of 1023 to each column in sequence and the receiving mux reads the rows one by one for each column.

    Click image for larger version. 

Name:	mux_pots.png 
Views:	156 
Size:	9.9 KB 
ID:	6528

  12. #12
    Senior Member
    Join Date
    Mar 2013
    Posts
    651
    Sadly it wont work that way. If C1 is on and C2 is off you will have a path from R1 center to R9 Center and to ground again, then add C3-C8 to the mix and things get interesting. Which will screw up your reads. You would have to rapidly read all of the pots in the entire matrix then do a crap load of math to determine where everything is. And you would still have a lot of play in your readings leading to needing a lot of software filtering.

    If your mux chips where capable of High Impedence output then it would be much easier. Your C and GND side do not have to be mux chips. If you replace them with a logic chip that can produce 3.3V/GND/High Z you could do it much easier. You basically have to limit the paths back to GND and 3.3V to only the column you want to read.

  13. #13
    Senior Member
    Join Date
    Mar 2013
    Posts
    651
    I keep saying use a Tri-state device but im actually having a hard time finding an 8 output device that can have its outputs individually set to High Z...

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,323
    That circuit won't work. Matrix scanning this way works for pushbuttons because they fully disconnect when not pressed. The pots continue to have a resistive connection all the time. In terms of matrix scanning buttons, think of ALL the buttons always pressed. Will not work.

Posting Permissions

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