Go Down

Topic: [SOLVED]: Analog values through multiplexer are very inconsistent! (Read 2 times) previous topic - next topic

dieselboris

Jun 16, 2012, 02:30 pm Last Edit: Jun 18, 2012, 10:48 am by dieselboris Reason: 1
Hi all,

I need to read 4 analog accelerometers. I thought of using a multiplexer for this (i took the CD74HC4067E for this). I wired everything up the way it should but my values are very inconsistent in comparison to reading the values directly.

These values come from the same sensor, the left ones come trough the multiplexer, the right ones are read directly.

Code: [Select]
x: 309 | y: 320 | z: 317 x: 331 | y: 329 | z: 273
x: 367 | y: 259 | z: 373 x: 331 | y: 329 | z: 273
x: 332 | y: 285 | z: 332 x: 331 | y: 329 | z: 273
x: 259 | y: 348 | z: 262 x: 331 | y: 329 | z: 273
x: 267 | y: 353 | z: 275 x: 331 | y: 329 | z: 273
x: 332 | y: 290 | z: 344 x: 331 | y: 329 | z: 273
x: 364 | y: 260 | z: 367 x: 331 | y: 329 | z: 273
x: 313 | y: 299 | z: 313 x: 331 | y: 329 | z: 273
x: 251 | y: 358 | z: 253 x: 331 | y: 329 | z: 273
x: 282 | y: 341 | z: 291 x: 331 | y: 329 | z: 273


I tried using delays in between reads from the multiplexer channels but no luck.

I'm in the dark here, please help!

RIDDICK

i use the 4067, 2...
and i dont c such big variations...
the capacitance and resistance introduced by the 4067 r quite small...

can u show us the program and cabling u use?

r u possibly reading from a wrong mux line?

what if u dont change the mux line and read again and again?
does it get stable then?
-Arne

Magician

How fast do you scan mux inputs?  Is analogRead and scan function synchronous?

Grumpy_Mike

Have you got decoupling on the multiplexer chips?
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Are you suffering from cross talk, that is one channel affecting the other?
To test:-
Start off with only one channel connected, connect it also through another chip analogue input look at the readings are they similar.
Then add more channels but don't look at them in the software. Do they now behave differently?

dieselboris

#4
Jun 16, 2012, 04:41 pm Last Edit: Jun 16, 2012, 05:03 pm by dieselboris Reason: 1
EDIT: I removed all references to any analog read and my program is just reading channel 0 at the mux and still a lot of deviation.....

EDIT 2: the chip was left unpowered, i'll run another test sorry about this.

Thanks to all for the quick replies!

Ok these values come out when using only one channel:

Code: [Select]
x: 330 x: 330 | y: 330 | z: 273
x: 91 x: 330 | y: 330 | z: 273
x: 100 x: 330 | y: 330 | z: 272
x: 330 x: 330 | y: 330 | z: 273
x: 143 x: 331 | y: 330 | z: 273
x: 325 x: 330 | y: 330 | z: 273
x: 48 x: 330 | y: 330 | z: 273
x: 119 x: 330 | y: 330 | z: 273
x: 330 x: 330 | y: 330 | z: 273
x: 133 x: 330 | y: 330 | z: 273
x: 60         x: 330 | y: 330 | z: 273
x: 330 x: 330 | y: 330 | z: 273
x: 133 x: 330 | y: 330 | z: 273
x: 330 x: 330 | y: 330 | z: 273
x: 121 x: 331 | y: 330 | z: 273
x: 47         x: 330 | y: 330 | z: 273
x: 330 x: 330 | y: 330 | z: 273


still all over the place.

So try to decouple the power source of the multiplexer. I put a capacitator from 0.047 uF from the power pin of the multiplexer to ground.

these are the values i get:

Code: [Select]
x: 331 x: 331 | y: 330 | z: 273
x: 135 x: 331 | y: 330 | z: 273
x: 68 x: 331 | y: 330 | z: 273
x: 331 x: 331 | y: 330 | z: 273
x: 163 x: 331 | y: 330 | z: 273
x: 331 x: 331 | y: 329 | z: 273
x: 121 x: 331 | y: 330 | z: 273
x: 91 x: 331 | y: 330 | z: 273
x: 331 x: 331 | y: 330 | z: 273
x: 158 x: 331 | y: 330 | z: 273
x: 331 x: 331 | y: 330 | z: 272
x: 97 x: 331 | y: 330 | z: 273


not much difference.

The wiring is in the attachment, hope it's clear.

Thanks again!

This is the code i'm using:

Code: [Select]

//////////////////////////////////////////////////////////////////
//©2011 bildr
//Released under the MIT License - Please reuse change and share
//Simple code for the ADXL335, prints calculated orientation via serial
//////////////////////////////////////////////////////////////////

//mux pins
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;

//Mux in "SIG" pin
int SIG_pin = 0;

//Analog read pins
const int xPin = A8;
const int yPin = A9;
const int zPin = A10;

void setup(){
 Serial.begin(57600); //does the speed matter?
}

void loop(){

 //read the analog values from the accelerometer
 int xRead = readMux(0);
 int xReadDirect = analogRead(xPin);
 //int yRead = readMux(1);
 int yReadDirect = analogRead(yPin);  
 //int zRead = readMux(2);
 int zReadDirect = analogRead(zPin);

 //Output the caculations
 Serial.print("x: ");
 Serial.print(xRead);  
 Serial.print("\t x: ");
 Serial.print(xReadDirect);
 Serial.print(" | y: ");
 Serial.print(yReadDirect);
 Serial.print(" | z: ");
 Serial.println(zReadDirect);
 
 delay(10);//just here to slow down the serial output - Easier to read
}


int readMux(int channel){

 int controlPin[] = {s0, s1, s2, s3};
 int muxChannel[16][4]={
   {0,0,0,0}, //channel 0
   {1,0,0,0}, //channel 1
   {0,1,0,0}, //channel 2
   {1,1,0,0}, //channel 3
   {0,0,1,0}, //channel 4
   {1,0,1,0}, //channel 5
   {0,1,1,0}, //channel 6
   {1,1,1,0}, //channel 7
   {0,0,0,1}, //channel 8
   {1,0,0,1}, //channel 9
   {0,1,0,1}, //channel 10
   {1,1,0,1}, //channel 11
   {0,0,1,1}, //channel 12
   {1,0,1,1}, //channel 13
   {0,1,1,1}, //channel 14
   {1,1,1,1}  //channel 15
 };
 delay(40);//maybe it helps??
 //loop through the 4 sig
 for(int i = 0; i < 4; i ++){
   digitalWrite(controlPin[i], muxChannel[channel][i]);
 }
 //read the value at the SIG pin
 int val = analogRead(SIG_pin);

 //return the value
 return val;
}

Go Up