Offline
Jr. Member
Karma: 0
Posts: 86
|
 |
« on: August 03, 2012, 04:56:40 pm » |
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/74HC4051but 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
Brattain Member
Karma: 298
Posts: 26024
Solder is electric glue
|
 |
« Reply #1 on: August 03, 2012, 05:01:54 pm » |
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.htmlThis is a project where I used a multiplexer, the code is included. http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps.html
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 86
|
 |
« Reply #2 on: August 03, 2012, 05:24:26 pm » |
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
Jr. Member
Karma: 0
Posts: 86
|
 |
« Reply #3 on: August 03, 2012, 05:40:07 pm » |
No, wait... you can write on it. On the datasheet ( http://www.datasheetcatalog.org/datasheet2/8/0uo046lw3xgikpf1d0zg15wpefpy.pdf) it says: 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
Edison Member
Karma: 91
Posts: 2232
|
 |
« Reply #4 on: August 03, 2012, 06:17:56 pm » |
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
|
Something different - Kitchen-Sink Arduino-compatible boards
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 86
|
 |
« Reply #5 on: August 03, 2012, 06:32:46 pm » |
oooohhhhhhh... I see. So a shift register it is.
Thanks for the clarification.
|
|
|
|
|
Logged
|
|
|
|
|
the land of sun+snow
Offline
Edison Member
Karma: 91
Posts: 2232
|
 |
« Reply #6 on: August 03, 2012, 06:49:31 pm » |
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
|
Something different - Kitchen-Sink Arduino-compatible boards
|
|
|
|
0
Online
Tesla Member
Karma: 58
Posts: 6768
Arduino rocks
|
 |
« Reply #7 on: August 03, 2012, 11:24:13 pm » |
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
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 298
Posts: 26024
Solder is electric glue
|
 |
« Reply #8 on: August 04, 2012, 02:42:15 am » |
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
God Member
Karma: 6
Posts: 640
Arduino happiness
|
 |
« Reply #9 on: August 04, 2012, 07:39:07 am » |
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
Jr. Member
Karma: 0
Posts: 86
|
 |
« Reply #10 on: August 04, 2012, 11:13:50 am » |
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: 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
Online
Tesla Member
Karma: 58
Posts: 6768
Arduino rocks
|
 |
« Reply #11 on: August 04, 2012, 11:21:34 am » |
Why the sudden drop on the reading? Do your 4051 control pins float when not actuated?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 86
|
 |
« Reply #12 on: August 04, 2012, 11:38:49 am » |
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: 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: 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
God Member
Karma: 6
Posts: 640
Arduino happiness
|
 |
« Reply #13 on: August 04, 2012, 11:42:41 am » |
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
Jr. Member
Karma: 0
Posts: 86
|
 |
« Reply #14 on: August 04, 2012, 11:45:29 am » |
yes, I am using a pot like that. It's working fine if it's connected directly to an Arduino pin
|
|
|
|
|
Logged
|
|
|
|
|
|