Pages: [1] 2   Go Down
Author Topic: Help with multiplexer (74HC4051)  (Read 2604 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using an IC that has a data input of 8 bit. Instead of using 8 pins on my Arduino I want to use a multiplexer.
So I connected it in the same way it's here: http://www.arduino.cc/es_old/Tutoriales/74HC4051
but instead of doing a analogRead at the end, I do a digitalWrite to the "COM OUT/IN" pin on the multiplexer. And when trying to write a certain 8 bit value it doesn't work.

I did a test reading a control pin on the multiplexer outputs but it's not even stable, it's erratic.

Is it possible to use this multiplexer in the way I want? What's wrong????

Thanks!
Logged

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

Quote
And when trying to write a certain 8 bit value it doesn't work.
I don't understand, you can't write an 8 bit value with a multiplexer. You can read 8 bits one bit at a time.
The code in that link is appalling.
Here is how to use and array:-
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html
This is a project where I used a multiplexer, the code is included.
http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps.html
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

oh... ok, so a multiplexer cannot be used to write?
There is the problem then, hehe. I thought it could be used for reading as well as writing.
I would need to use a shift register then, right?

Cool project by the way!
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, wait... you can write on it.

On the datasheet (http://www.datasheetcatalog.org/datasheet2/8/0uo046lw3xgikpf1d0zg15wpefpy.pdf) it says:
Code:
The 74HC/HCT4051 are 8-channel analog
multiplexers/demultiplexers with three digital select inputs
(S0to S2), an active LOW enable input (E), eight
independent inputs/outputs (Y0to Y7) and a common
input/output (Z).

What I want to do is write on 8 different pins by using the multiplexer, one at a time by writing each time the selector value and then the pin value. Am I that wrong?
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It's an "8-channel" multiplexer, not an "8-bit" multiplexer, which implies something
different [although I'm not sure what that would even be].

You can connect only 1 channel at a time, and it doesn't latch, so as soon as you
switch to another channel, the signal to the previous channel will no longer
be valid [ie, floats]. You can use it to read input lines.

If you want to write to 8 pins you will want to use an 8-bit latch, which will have
3 pins for channel select, plus a Din pin [hi/low].

It is not simple to both read and write to 8 pins, to do that you will need a latch
with ability to set the output channels to hi-Z, as well as a another chip to
do the reads. Even worse, most latches will not allow you set individual pins
to hi-Z, but do all pins at the same time.

If you look at the info on the I/O pins in the mega328 d/s, you'll see they have a
lot of circuitry for individual pin control. You would have to emulate something
like that in order to allow individual pins to be either input or output at the
time.
« Last Edit: August 03, 2012, 06:20:33 pm by oric_dan(333) » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

oooohhhhhhh... I see.
So a shift register it is.

Thanks for the clarification.
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A shift register will work, although you want to be careful that
you're not sending flukey signals to the output pins as you're shifting
the 8-bits through the device.
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8919
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've tinkered a little with 4051 chips and had to put a high value resistor on the control pins to ground to prevent them from floating, causing some erratic behavior. Below is a 16 channel version.

https://www.sparkfun.com/products/9056
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

Only a total idiot would use a 4051 to write data to each of its outputs. There are a lot of idiots on the web.
The example you showed was reading LDRs.

Normally the shift registers are latched so you don't have to worry about values changing as you shift them along.
Logged

Peoples Republic of Cantabrigia
Offline Offline
God Member
*****
Karma: 6
Posts: 691
Arduino happiness
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have used the 16-channel 4067 with good success to allow a high-accuracy, single channel ADC make its readings. Another option would have been using multiple ADCs but there were board space considerations. Plus, with 16 input channels and only a need for 11 inputs, I could set aside 5 channels for reference resistors - thus allowing calibration and verification.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks all for the help!
But now I need more :-)

I am using the 74HC4051 multiplexor and I connected 3 buttons and 2 pots to it.
I am getting very erratic readings on the pots, it might be accurate enough to use it for buttons, but not for the pot.
For example, I select channel 0 (0,0,0) for reading A0 wich is connected to the pot, I spin the pot to the maximum value and the output is this:
Code:
pitchRead: 1014.00
pitchRead: 1013.00
pitchRead: 1014.00
pitchRead: 1013.00
pitchRead: 1013.00
pitchRead: 1014.00
pitchRead: 1013.00
pitchRead: 1014.00
pitchRead: 1023.00
pitchRead: 26.00
pitchRead: 24.00
pitchRead: 25.00
pitchRead: 26.00
pitchRead: 40.00
pitchRead: 1013.00

Also, if I press one of the buttons the reading is higher, if I press the 3 buttons at the same time more.
Maybe I need to use one multiplexor for the pots and another for the buttons???

Why the sudden drop on the reading?
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8919
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Why the sudden drop on the reading?

Do your 4051 control pins float when not actuated?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Jr. Member
**
Karma: 0
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm sorry but what do you mean when not actuated?

As a test I connected every input from the multiplexor to the ground except a potentiometer.

*When I select one of the ground channels (A1-A7) it gives a reading of 47-49 when the pot is at maximum or at minimum, it's affecting it very little to nothing.
*When I select the pot channel (A0) and set the pot to minimum it gives me this:
Code:
pitchRead: 47.00
pitchRead: 48.00
pitchRead: 48.00
pitchRead: 48.00
pitchRead: 49.00
pitchRead: 70.00
pitchRead: 73.00
pitchRead: 46.00
pitchRead: 46.00
pitchRead: 47.00
pitchRead: 53.00
pitchRead: 56.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 49.00
pitchRead: 71.00
pitchRead: 76.00
pitchRead: 50.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 80.00
pitchRead: 62.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 48.00
pitchRead: 48.00

And when I spin the pot at maximum it gives me this:
Code:
pitchRead: 973.00
pitchRead: 974.00
pitchRead: 973.00
pitchRead: 974.00
pitchRead: 971.00
pitchRead: 965.00
pitchRead: 962.00
pitchRead: 46.00
pitchRead: 69.00
pitchRead: 54.00
pitchRead: 46.00
pitchRead: 46.00
pitchRead: 47.00
pitchRead: 47.00
pitchRead: 62.00
pitchRead: 969.00
pitchRead: 973.00
pitchRead: 974.00
pitchRead: 975.00
pitchRead: 975.00
pitchRead: 974.00
pitchRead: 975.00
pitchRead: 976.00
pitchRead: 964.00
pitchRead: 975.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 973.00
pitchRead: 973.00
pitchRead: 974.00
pitchRead: 973.00
pitchRead: 973.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 973.00
pitchRead: 974.00
pitchRead: 47.00
pitchRead: 975.00
pitchRead: 974.00
pitchRead: 975.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 974.00
pitchRead: 974.00

I am constantly selecting the cannel in the loop.
Logged

Peoples Republic of Cantabrigia
Offline Offline
God Member
*****
Karma: 6
Posts: 691
Arduino happiness
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you using a three-legged potentiometer as described here? If not, that could be your problem. A pot that doesn't feature a wiper + two other terminals will require a drop-down resistor of the right value to work as expected.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes, I am using a pot like that.
It's working fine if it's connected directly to an Arduino pin
Logged

Pages: [1] 2   Go Up
Jump to: