Go Down

Topic: [SOLVED] 40 channel 4051 multiplexer analog ins affect neighbours values (Read 2 times) previous topic - next topic

tmk_009

hello,

i'm using 5 slave 4051 and 1 master 4051 to build a 40 channel multiplexer. 40 potentiometers (100k) are connected to the analog ins on each 4051.

the arduino is reading all the inputs, but is messing aroung with neighbour-inputs. e.g.: when i turn potentiometer #32 from 0 to 1023, then the value of potentiometer #31 is changing to (~)760... and the other way round. on different potentiometers the similar situation, sometimes more sometimes less affection...

each potentiometer is getting its ground and +5v from the arduino, the middle pins are connected to the slave 4051 analog inputs, each output of an slave 4051 is connected to the master 4051 analog input, just like in the basic description: http://playground.arduino.cc/learning/4051

Any idea how to clear the values?

I'm using this mux example to read out the values:

Code: [Select]

#include <analogmuxdemux.h>

#define READPIN 2 //analog in
#define NO_PINS 40 //40 inputs

// master selects
#define M_S0 10 //master digital pin
#define M_S1 11 //master digital pin
#define M_S2 12 //master digital pin

// slave selects
#define S_S0 2 //slave digital pin
#define S_S1 3 //slave digital pin
#define S_S2 4 //slave digital pin

AnalogMux amx(M_S0,M_S1,M_S2, S_S0,S_S1,S_S2, READPIN);

void setup() {
   // check in serial monitor what is happening
   Serial.begin(9600);
   Serial.println("Starting 4051 analog reader...");
   delay(1000);
}

void loop() {

 // go through each pin on the muxer in turn and just print out it's pin number
 // and it's reading then wait a bit and do it again
   
   for (int pinno=0; pinno< NO_PINS; pinno++) {
     amx.SelectPin(pinno);
       uint16_t reading = amx.AnalogRead();
       Serial.print("Pin: ");
       Serial.print(pinno);
       Serial.print(" Value: ");
       Serial.print(reading);
       Serial.println();            
   }
   Serial.println("---");
   delay(1000);

}
* alright, what happened *

Grumpy_Mike

Your problem is:-
Quote
40 potentiometers (100k) are connected to the analog ins on each 4051

You should have used 10K pots so that the impedance is lowered both for the multiplexer and the A/D.

What you can try is reading each channel twice and only using the second result. This allows extra sample acquisition time.

So this would look like:-
Code: [Select]

amx.SelectPin(pinno);
        uint16_t reading = amx.AnalogRead();
        reading = amx.AnalogRead();

However why on earth you are using a library like <analogmuxdemux.h> I don't know, it is simple enough to write code for this, and it might stop this fix from working.

tmk_009

Quote
What you can try is reading each channel twice and only using the second result. This allows extra sample acquisition time.

this i will check out back at home!

Quote
However why on earth you are using a library like <analogmuxdemux.h> I don't know, it is simple enough to write code for this, and it might stop this fix from working.

thought it would be faster then writing a own buggy one :) so ok, i'm going to write it from scratch if this fix^^ isn't wiring.
* alright, what happened *

tmk_009

Checked it. It really doesn't matter if its an 100k or 10k pot, I've tested them both.
The solution was so simple: I tested the 40 analog ins each only with one pot. Connecting all pots to the 40 inputs has removed the affection on the other neighbour inputs by approx 99%... Oh my.
* alright, what happened *

dc42

To remove the remaining 1%, try inserting a small delay (e.g. 10us to 100us) between these two lines:

Code: [Select]

amx.SelectPin(pinno);
uint16_t reading = amx.AnalogRead();
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Grumpy_Mike


Checked it. It really doesn't matter if its an 100k or 10k pot, I've tested them both.
The solution was so simple: I tested the 40 analog ins each only with one pot. Connecting all pots to the 40 inputs has removed the affection on the other neighbour inputs by approx 99%... Oh my.

See what you get if you don't describe what you have fully. I would have told you about un terminated inputs.  :)
Try the reading twice bit with all the inputs connected.

tmk_009

thank you both guys. step by step i'm getting into it. i'll post the results later!
* alright, what happened *

tmk_009

thank you guys! everything works like a charm! no errors, no bleedings. the values are accurate, even with 100k pots and 4051 multiplexers.

it took some time, i had to resolder the pot matrix, somewhere there was a tiny bugs messing up the whole thing... now i can go further to the next step: playing around with midi values by turning a knob in the matrix.
* alright, what happened *

Go Up