CD74HC4067 MUX analog voltage readings not accurate?

Testing a CD74HC4067 mux...thru the mux get different voltage readings than direct.

Same sketch to read voltage...connect to channel 0 on mux with 500 reading average...same sketch direct connection and very different reading with no change in sketch.

Wondering if it has anything to do with the other channels...if channel is unused should it be connected to ground or VCC or ? Should other channels affect channel 0?

Already added delay, now 1000ms, after mux change and before reading.

Any ideas much appreciated.

Thank you!

Yes unused channels should not be left unconnected they should be connected to ground or 5V. Also have you got a 0.1uF decoupling cap on the supply Pins of the mux?

Grumpy_Mike:
Yes unused channels should not be left unconnected they should be connected to ground or 5V. Also have you got a 0.1uF decoupling cap on the supply Pins of the mux?

I did not know about the decoupling cap but have now spent some time reading up on them. I connected one (104?) between vcc and gnd. Is that correct?

I tried connecting all of the unused channels to ground and then when that didn't seem to make any difference I tried all of them to 5v.

I did not know about the decoupling cap but have now spent some time reading up on them. I connected one (104?) between vcc and gnd. Is that correct?

Yes but they have to be ceramic capacitors.

Thanks very much for the ideas!

Fortunately the one I had was a ceramic capacitor. Capacitor Ceramic 0.1uF - COM-08375 - SparkFun Electronics

The changes you've suggested (capacitor, unused channels to gnd) have certainly made some difference when I use an analog temp sensor tmp36 but do not seem to have corrected the reading for voltage.

Since both circuits measure analog voltage, although differently I wasn't expecting this. The main difference I see is that the temp uses a gain of 1 while the voltage uses a gain of 2/3 but this is addressed in software.

Perhaps I should explain that I am trying to (very) accurately measure voltage which first goes thru a voltage divider circuit and then to an external ADC (ADS1115). It works fine (same sketch) without the mux in between but when I insert the mux (volt divider to channel 0 and sig to ADC) what was reading (software adjusted) about 14v is now reading about 2v. So not even close. Would the mux possibly be adding a lot of resistance that could be impacting the reading of the ADC? If so is there a way to include it in the voltage divider circuit calculation? Would I just use multimeter to measure resistance to include in voltage divider circuit calculation? ...or possibly back into the value (calibrate) to calculate correctly? I'm not sure how to measure resistance thru the mux without a chance of damaging it.

Another observation, when the sketch cycles thru the other (unused) channels, whether connected to gnd or to 5v, the values are all over the place. This is true whether using temp or voltage. I guess I expected to get zero gnd or max (32k) with 5v. I'm wondering if the difference between vcc and the internal voltage reference of the external ADC might be causing this. I guess this is irrelevant as I typically would not be wasting cycles reading unused channels but thought it could shed some light on the problem.

Thanks again!

Would the mux possibly be adding a lot of resistance that could be impacting the reading of the ADC?

Well look at the data sheet for the one you are using ( the actual manufacturers data sheet ) but typically there is a 150R or so series resistance.

what was reading (software adjusted) about 14v is now reading about 2v. So not even close.

That would imply that either the resistor values on the potential divider is wrong ( not the ratio of the resistors but the absolute size ) or something else is not right.

I think it is time to post a schematic. Just a point, I hope you are not trying to do this on solderless bread board are you? They are notorious for bad joints.

Another observation, when the sketch cycles thru the other (unused) channels, whether connected to gnd or to 5v, the values are all over the place.

Again that is not to be expected and points to something major being wrong. The circuit is not actually how you describe it.

Wow some great insights. Clearly the capacitor was huge and I still can't find any of the examples with the mux that even mention this. I'm wondering if I also need one for other ICs like the ADS1115? The information I've been reading also talk about additional capacitors of other sizes too?

Grumpy_Mike:
Well look at the data sheet for the one you are using ( the actual manufacturers data sheet ) but typically there is a 150R or so series resistance.

The board is from Sparkfun, and is just a breakout of the chip from TI. The only datasheet provided is from TI and says "Low on resistance" 60-70 ohm but I don't doubt that there is more including the breakout board. ...guess I'm fortunate I didn't get this one from ebay.

I'm not sure how to calculate how much the additional resistance would affect the voltage reading going thru the mux vs going directly since it's not a textbook voltage divider circuit. Give me a little break, I'm just a software guy.

Grumpy_Mike:
That would imply that either the resistor values on the potential divider is wrong ( not the ratio of the resistors but the absolute size ) or something else is not right.

I did double check the resistor values on the voltage divider. They are 47k and 22k (sparkfun) for a factor of about .319. I doubt they are exact and my multimeter is not precise enough to confirm. However they do correspond to the actual (multimeter) voltage measurements. I don't understand how the values of the voltage divider resistors ... which I thought only important for the ratio that caused the output leg voltage to be lower, would make any difference when combined with the addition of the mux resistance...not that I disagree at all I just don't understand that science. Can you give me a concept to google or research because it's way past my education on this. ...and then there is the likelihood that it's ALSO something else that I've likely mucked up. I guess I was under the misunderstanding that since this was only a voltage measurement no current was actually flowing ...so therefore resistance would have very little affect on the voltage.

Grumpy_Mike:
I think it is time to post a schematic. Just a point, I hope you are not trying to do this on solderless bread board are you? They are notorious for bad joints.

Re the schematic - I haven't done this yet because they are just basic duplication of the example circuits ...so I'll have to install software to do this I guess. And even for a software guy this circuit was pretty straight forward. It will probably take a little time to do this. I'm certainly not disagreeing and greatly appreciate your willingness to have spent the time you have already spent in assisting.

Guilty as charged. Yes doing it on bread board...which is how I could use same sketch and move from mux to direct and back easily. ...but I'm not planning on relying on the data while on the breadboard just prototyping the circuit. ...and yes I agree my last major hair pulling session was caused by a bad connection so I probably just need to re-connect everything a few more times.

Grumpy_Mike:
The circuit is not actually how you describe it.

Ouch! OK it is certainly possible that it was not executed as designed and deserves to be reinspected by quality control.

Many thanks for your help.

I haven't done this yet because they are just basic duplication of the example circuits

just
How many times have we herd that here. Look, I can't make anything without a schematic and with the greatest respect I am about 1000 times better at this lark than you. What happens is that you miss something out and you are convinced that you have
just
duplicated some standard circuit.

They are 47k and 22k (sparkfun) for a factor of about .319.

You can get that same ratio with a 4K7 and a 2K2, the difference being that more current flows down the two smaller resistors. That means that any load you put across one of the resistors has a smaller effect on the real ratio. The A/D converter is optimised for a load impedance of 10K, and that coupled with your series resistor in the multiplexer increases the time it takes to charge the input capacitor on the sample and hold circuit on the input to the A/D. As a result the capacitor has not fully charged in the time between selecting that channel and starting the conversion. One simple way round this is to read the channel twice one after the other, and only use the second value. This gives the capacitor enough time to charge while the first reading is being made and then the second reading is more like the real voltage. You do not notice this on a multimeter because it takes only about three reading a second as opposed to the Arduino's 10,000 readings per second.

Clearly the capacitor was huge and I still can't find any of the examples with the mux that even mention this.

It is like a fish saying, I have never come across this concept of water before. It is such a fundamental of electronics that decoupling capacitors are often missed out of schematics because every one knows you have to have one on EVERY chip.

I wrote this to explain it to beginners.
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html