Pages: [1]   Go Down
Author Topic: [SOLVED] 40 channel 4051 multiplexer analog ins affect neighbours values  (Read 1939 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Kling Klang
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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);

}
« Last Edit: March 07, 2013, 05:56:01 pm by tmk_009 » Logged

* alright, what happened *

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
« Last Edit: February 25, 2013, 08:45:18 am by Grumpy_Mike » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
Kling Klang
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley so ok, i'm going to write it from scratch if this fix^^ isn't wiring.
Logged

* alright, what happened *

Offline Offline
Newbie
*
Karma: 0
Posts: 16
Kling Klang
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

* alright, what happened *

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
amx.SelectPin(pinno);
uint16_t reading = amx.AnalogRead();
Logged

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.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley
Try the reading twice bit with all the inputs connected.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
Kling Klang
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you both guys. step by step i'm getting into it. i'll post the results later!
Logged

* alright, what happened *

Offline Offline
Newbie
*
Karma: 0
Posts: 16
Kling Klang
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

* alright, what happened *

Pages: [1]   Go Up
Jump to: