Pages: [1] 2   Go Down
Author Topic: [Solved, Thanks] Buggy Circuit - Please help me identify possible causes  (Read 1793 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 2
Posts: 713
a, b = b, a+b
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So (as some of you who have been a lot of help to me already have probably figured out...) I am working on this massive sensor array thingy.

I have my PCB's etched, my smd components soldered, all I am waiting for is for some more multiplexers before the whole thing is done. (for some reason customs or sparkfun or somebody does not want me to finish this. Its been in the mail for almost 3 weeks :-(...)

Anyway, I do have one multiplexers which I put into the circuit, and I should be able to test 16 sensors at a time. It does not work as expected.

About half of the sensors give me the readings I expect. The other half give readings which look reasonable: i.e. the arduino usually outputs ~1024 and when exposed to ambient light, the values drop more or less as one would intuitivly assume they should.

In truth however, there appears to be some sort of leakage. For example: Sensor 2 will just stay at around 1024. Even if I should get readings of 100 or less, it stays at 1024. But if Sensor1 is activated (i.e. Sensor1 value sinks to under 100), then sensor2 to will also respond, sink to about 200, even if it should not.)

Ok, here is a sketch of the circuit, so you know what I am talking about:



(the multiplexer circuit is just copied off of the sparkfun brakout board: http://www.sparkfun.com/datasheets/BreakoutBoards/Analog-Mux-Breakout-v10.pdf)

Possible reasons that I can think of:

a) There is a problem with my logic, and this circuit is wrong.
b) There is a problem with my PCB, I have some connections which should not be there. (dont think thats the case. I checked this extensivly. Everything seems as it should be)
c) I am pulling more power than the arduino can handle (in retrospect, maybe I should have used stronger resistors for the voltage dividers?).
d) I fried some sensors when soldering (sort of doubt that).
e) I fried the multiplexer when soldering it (How fragile are they? I have no experience how a semi-fried multiplexer could behave...)
f) The code is whack. (pretty sure that is not the case. I used a modified version of this code: http://bildr.org/?s=mux)

*

Ok, about the power options. The sensor I am using is actually an IC with a led and a photodiode. The led is controlled by a separate circuit with its own power, that’s why Its not in the sketch I posted above. However, because of this, the datasheet confuses me, cause I never know which values refer to the sensor and which to the emitter. The datasheet can be found here: http://www.fairchildsemi.com/ds/QR/QRE1113.GR.pdf

These are the values which I *think* are relevant, but I am not realy sure:

Collector Emitter Voltage 30V
Emitter Collector Voltage 5V
Collector Current 20ma

I am running all of the sensors in parallel, so its 320ma, so I should be fine for now, right? The arduino can supply that current with the 5v pin, correct? I just double-checked the specs of the arduino mega and did not actually find any information on that. But then there are those 10k resistors which I don’t really know how to factor in :-/

*

Ok, I guess this already is quite a large "help me" post. If someone could take a look at this and help me eliminate the possible problems, or even point out new ones, that would be great. I am waiting until I get the other multiplexers tomorrow, before I do more trouble shooting, but any suggestions which will help me solve this are appreciated.

Thanks

P.
« Last Edit: August 03, 2011, 11:05:14 pm by fkeel » Logged


Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 533
Posts: 26951
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How fast are you going thru the analog readings? I didn't look at the code. It is often suggested here to read the same input twice, throw away the first one, give the selected input a chance to drive the A/D circuit in the ATMega correctly.
You have the grounds from your various supplies all connected to each other?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
God Member
*****
Karma: 2
Posts: 713
a, b = b, a+b
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

yep. all grounds connected.

*

I am reading them as fast as possible - I am not doing any intentional timing - just cycling through my sketch. Do you mean something like this:

(assuming I have a function, readMux(int) which sets the control pins to read the desired sensor)

Code:

trash = readMux(1);
sensor1 = readMux(1);
trash = readMux(2);
sensor2 = readMux(2);
trash = readMux3);
.... etc

Logged


Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 533
Posts: 26951
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, exactly.
Don't have to give it a new name if you don't want to, I wasn't being literal smiley-cool
sensor1 = readMux(1);
sensor1 = readMux(1);
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

'round the world...
Offline Offline
Faraday Member
**
Karma: 42
Posts: 3244
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you using the USB port to power this up?

It is always a good idea to use a standalone power supply when working outside of the Arduino. The 10K resistors make the currents going through them small enough for this not to be a problem for the USB port, but you never know. And I have no idea what other hardware you may have installed.

Try disconnecting most of the 16 sensors and get the mux out of the equation and test. Them put the same sensors, through the mux and test. See the differences. Then get all sixteen of them and see the differences. That's the only way you can see which part of the circuit is holding you.

Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 300
Posts: 26219
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
trash = readMux(1);
sensor1 = readMux(1);

aka

Code:
(void) readMux(1);
sensor1 = readMux(1);
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

'round the world...
Offline Offline
Faraday Member
**
Karma: 42
Posts: 3244
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
trash = readMux(1);
sensor1 = readMux(1);

aka

Code:
(void) readMux(1);
sensor1 = readMux(1);

Is there any difference in terms of speed by using the second form?
Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

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

Quote
Is there any difference in terms of speed by using the second form?
No, the whole point is that you don't want it to be faster as you are giving the sample and hold capacitor on the A/D chance to settle down to the correct voltage.
It doesn't use a memory location though and it looks like you mean it when reading the code where as:-
sensor1 = readMux(1);
sensor1 = readMux(1);
looks like you might not mean it without any comments.

As to the OPs problem you need to do more measurements with a scope to see exactly what is going wrong, on the face of it there should be no problem.
« Last Edit: August 03, 2011, 09:38:35 pm by Grumpy_Mike » Logged

'round the world...
Offline Offline
Faraday Member
**
Karma: 42
Posts: 3244
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is there any difference in terms of speed by using the second form?
No, the whole point is that you don't want it to be faster as you are giving the sample and hold capacitor on the A/D chance to settle down to the correct voltage.
It doesn't use a memory location tough and it looks like you mean it when reading the code where as:-
sensor1 = readMux(1);
sensor1 = readMux(1);
looks like you might not mean it without any comments.

As to the OPs problem you need to do more measurements with a scope to see exactly what is going wrong, on the face of it there should be no problem.

I know why it is read twice. I had never seen that form of using a function that we do not care about and therefor asked if there was a difference in speed, as it looks like it will take the same memory as the above form does.
Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

Offline Offline
God Member
*****
Karma: 2
Posts: 713
a, b = b, a+b
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yay! I got it to work.

Turns out there where two independent things going on

a) I simply did not do a very good job soldering the multiplexer to the circuit. Thats why Sensor2 gave out the same reading as Sensor1, because Sensor2 was simply not physically connected to the multiplexer

b)The power supply I was using for the external power for the LEDs was bad. As in the output apparently fluctuated in voltage, and the LEDs would therefore pulse. This was not visible to eye (or to my IR camera) but produced a whole lot of noise. From now on I will not use old/second hand power sources for my project, as the first two power sources I used, which all had the correct ratings, and where in *working condition* had voltage (or amperage? or both?) fluctuations. As soon as I had a clean power source, everything worked like a charm.

*

About the double readings: My code works fine and I am only reading once. However, I read 4 multiplexers all together, which may have the same effect.
Just for completeness, here is my code:



Code:
/****************************************/
/*  Code For Reading 4 Multiplexers     */
/*   and sending the values to serial   */
/*                                      */
/*     Code by paul strohmeier          */
/*   http://fkeel.blogspot.com          */
/*                                      */
/* Feel free to use and destribute      */
/* Give me credit if you feel like it :-)
/*****************************************/

// I use this multiplexer:
// http://www.sparkfun.com/products/299

//This code is based on this tutorial:
//http://bildr.org/2011/02/cd74hc4067-arduino/

//Control pins for all multiplexers
int s0 = 2;
int s1 = 3;
int s2 = 4;
int s3 = 5;


//Signal pin for each individual multiplexer
int mux1 = 3;
int mux2 = 2;
int mux3 = 1;
int mux4 = 0;

void setup(){

//set control pins to output
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);

//not sure if this is actually necesary
  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);

//initate serial
  Serial.begin(9600);
}

void loop(){


//read the multiplexers & display the values

/* Attention:
I only use 8 pins of multiplexer 4, thats why
I have two different conditions for i < 8 and i < 15
Depending on how many sensors you are reading, you will
probably want to change this.
*/


  for(int i = 0; i < 16; i ++){
    if (i < 8) {
     // read all 4 multiplexers
     setMux(i);
      Serial.print(analogRead(mux1));
      Serial.print(",");
      Serial.print(analogRead(mux2));
      Serial.print(",");
      Serial.print(analogRead(mux3));
      Serial.print(",");
      Serial.print(analogRead(mux4));
      Serial.print(",");
    }
       else  if (i < 15) {
         //read multiplexer 1,2 & 3 only
     setMux(i);
      Serial.print(analogRead(mux1));
      Serial.print(",");
      Serial.print(analogRead(mux2));
      Serial.print(",");
      Serial.print(analogRead(mux3));
      Serial.print(",");
    }
     else {
       //read multiplexer 1,2 & 3 and then start new line
         setMux(i);
      Serial.print(analogRead(mux1));
      Serial.print(",");
      Serial.print(analogRead(mux2));
      Serial.print(",");
      Serial.print(analogRead(mux3));
      Serial.println(" ");
    }
  }
}


//function for setting control pins
void setMux(int input){
  int controlPin[] = {s0, s1, s2, s3};

/* Attention:
I made my own brakeout boards for my multiplexers.
If you are using the sparkfun multiplexer brakout boards
You will need to change the order. The correct order for
the Sparkfun brakeout are noted in the comment
*/

  int muxInput[16][4]={
    {0,0,0,0}, //SparkFun Input # 0
    {0,0,1,0}, //SparkFun Input # 4
    {0,0,0,1}, //SparkFun Input # 8
    {0,0,1,1}, //SparkFun Input # 12
    {1,0,0,0}, //SparkFun Input # 1
    {1,0,1,0}, //SparkFun Input # 5
    {1,0,0,1}, //SparkFun Input # 9
    {1,0,1,1}, //SparkFun Input # 13
    {0,1,0,0}, //SparkFun Input # 2
    {0,1,1,0}, //SparkFun Input # 6
    {0,1,0,1}, //SparkFun Input # 10
    {0,1,1,1}, //SparkFun Input # 14
    {1,1,0,0}, //SparkFun Input # 3
    {1,1,1,0}, //SparkFun Input # 7
    {1,1,0,1}, //SparkFun Input # 11
    {1,1,1,1}  //SparkFun Input # 15
  };

  //loop through the 4 sig
  for(int i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxInput[input][i]);
  }
}

*

Thanks for all the input, everyone.

(and AWOL, sorry for the snappy replies in the pm about that other thread - you just sort of hit a sore spot... :-/...)
« Last Edit: August 03, 2011, 11:31:18 pm by fkeel » Logged


'round the world...
Offline Offline
Faraday Member
**
Karma: 42
Posts: 3244
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

However, I read 4 multiplexers all together

Are you sure?
Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

Offline Offline
God Member
*****
Karma: 2
Posts: 713
a, b = b, a+b
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

um. yes?

edit: what makes you think I might not be sure?
Logged


'round the world...
Offline Offline
Faraday Member
**
Karma: 42
Posts: 3244
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino has 1 Analog to Digital converter. Which means that you cannot read 4 analog signals at the same time. I may be picky about this, but it isn't right to say you read them at the same time.
Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

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

In the setMux(int input) function you define your array every time you call it. This is going to take gob loads of time and is best done once only in the setup().

The code is a bit pedestrian and you would be better using loops rather than plodding through the same thing each time.

Finally look at bit maths to eliminate the need for that two dimensional matrix altogether.

Logged

Offline Offline
God Member
*****
Karma: 2
Posts: 713
a, b = b, a+b
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@bubulindo - ok, point taken. what I meant to say is that I am recieving signals from all together 4 multiplexers. I am very aware of the fact that its not simultanious (its actually really slow right now... )

@grumpy mike - as said. the code is slow, I will try improving what you suggested and post it again - if you could give me some more feedback then, that would be super cool.

I am not sure how bit maths can help me - I have never used bitwise operations, but I'll look into it. Probably a valuable learning experience as well.
Logged


Pages: [1] 2   Go Up
Jump to: