Multiplexing 8 analog inputs using a CD4051B

Home :: MIDIfighter Resources and Discussion :: Multiplexing 8 analog inputs using a CD4051BReply
Multiplexing 8 analog inputs using a CD4051B
Posted on: 20.01.2011 by robert chanda
Here's a setup that allows 8 analog inputs to be read by a single analog expansion pin (plus three digital outputs). You'll need to make a few firmware changes to make it function however so it won't work out of the box, but it's not that big a change. I can make a .hex file or a new source drop available if there's enough interest.



http://goo.gl/pIX5P



http://goo.gl/0sIGD
Hunter Renslow
16.02.2011
Originally Posted by MiL0
what's the theoretical maximum number of analogues using a multiplexer?
8 per multiplexer,1 multiplexer per analogue input so 32 in total.as far as I can figure that's it for the simple solution.as for encoders I have no idea

I'm still waiting on a few parts and need to re-order my multiplexers(accidentally got the wrong ones and they're so small its hard to see them LOL) and then we'll see what mad controller the midifighter can morph into!
Arcelia Siebeneck
16.02.2011
what's the theoretical maximum number of analogues using a multiplexer?

also, is encoder support possible? this teensyduino-based controller looks like it uses one: http://www.noisybox.net/electronics/dickhole_keypiss/
robert chanda
10.02.2011
We have four techniques:

1. add another LED controller to the chain. Some tricky resoldering in there.

2. Use the digital inputs also as outputs. For most of the time you output the LED state through the pin, remembering to set the PORTD and DDRD registers to enable the internal pull-up resistor. When it comes time to poll the switch, the output is turned into an input, the switch is read then the port is switched back to output. Do this quick enough and the LED will appear constantly on.

3. Add another small microcontroller that will read the button states and set the LED itself, independent of what the main CPU is doing. The main CPU never sees or knows anything about these LEDs, and their state is updated by the second micro. Cheaper than you might imagine.

4. Do option 3, but but the micro on an SPI or I2C bus as a slave, so that it reads instructions sent by the main controller. This way the main machine controls the lights indirectly by sending instructions to a slave processor. The protocol need not be complex, just send bytes with a bit set for each LED.
Hunter Renslow
10.02.2011
Fatlimey i was wondering whats the easiest way to add more leds to the midifighter?With the extra buttons im adding i could really use a few more leds? Any suggestions?
Hunter Renslow
01.02.2011
Thanks a million!! Im getting excited and cant wait for my parts to arrive
robert chanda
01.02.2011
Originally Posted by sidetrakd
Fatlimey how well is this working in your tests?I should have parts next week for my own expansion project and was wondering if i could get some more info on the firmware changes.My brother whos a software engineer said it wont be any problem but any info you may have would be appreciated
Thanks
The instructions for building the firmware are on a Sticky thread in this community .

The changes you need are (I'm remembering the function and variable names off the top of me head here, so check the source):

  1. Change three of the digital input ports to be outputs. You do this using the DDRD register (Data Direction Register for Port D)
  2. You add 8 analog inputs to the g_exp_analog_prev[] array (global, expansion, analog previous value), giving you a total of 11. This array hold the previous analog value so we can see if the knob has moved since we last checked.
  3. To fill the g_exp_analog_prev[] array you need to replace one of the "read_analog(0)" calls with a short loop that sets the PORTD bits to tell the 4051 which input to connect to the output, then executes a read_analog(0).
  4. Finish filling the analog reads using the normal "read_analog(1); read_analog(2); read_analog(3);"
  5. Make the same changes in the main loop where it fills the array "analog_value[]";
  6. In the main loop where it outputs CC values for analog changes, alter any loop from 0..4 to a loop over 0..NUM_ANALOG, where you define a global NUM_ANALOG to be 11.
  7. erm, that's it.


That's pretty much it. You'll be generating CCs in groups of two per knob starting from CC16. Oh, and you have to make sure the MIDI NoteOn numbers for your smart faders don't clash with any notes used by the keypad.
Hunter Renslow
01.02.2011
Fatlimey how well is this working in your tests?I should have parts next week for my own expansion project and was wondering if i could get some more info on the firmware changes.My brother whos a software engineer said it wont be any problem but any info you may have would be appreciated
Thanks
Hunter Renslow
01.02.2011
Very interested in this! It changes my whole design.
Lisa Lochotzki
31.01.2011
Originally Posted by kilobytekaushik
Is there any way for multiplexing leds?
There's quite different ways to do that depending if you want to have only 1 led at the time or a combination of ... even all ON.
Lisa Lochotzki
31.01.2011
Fatlimey,
I'm not sure how bad the 4051 could be in this specific DC signal use, but I would suggest you to have a look at something.

Some 4051 series have some "huge" crosstalk issues (CD4051 probably being the worst) 'Course you could trick it a bit in software, but it add some extra latency.

74HC4051 are better, but still not perfect. If my memory serves me well, Maxim MAX4617 is a 4051 drop in replacement, sure more expensive but has better features (smaller Rdon and less crosstalk). On the long run they worth it.

my 2 cents.
Karry Sappington
31.01.2011
Is there any way for multiplexing leds?
Shirlee Depiazza
28.01.2011
Originally Posted by Fatlimey
Seriously, this stuff is not that difficult! Give it a try.
Hehe, Fatlimey you crack me up.
Really not meaning to sound rude or anything here but most people here (myself included don't know much about electronics).
In fact I probably shouldn't be allowed to play with a multi-meter and soldering iron.

Now a technical question...
When you do this multiplexing stuff I'm guessing inputs basically share pins with the midifighter working out which input is sending based on magic (it's the resistance or pulse isn't it?).
Excuse my poor understanding I do have a point.
Is it possible to trigger the wrong midi message by feeding in multiple inputs through the same pin at the same time?

The reason I ask is I had a Reloop Digital Jockey 2 Interface Edition, and discovered that if you pressed three buttons at the same time it would trigger an extra unrelated midi message (the worst being pressing all 3 FX buttons would kill the bass on the deck).
Was this issue related to multiplexing or just bad coding on Reloop's part?
Vernie Beharry
28.01.2011
:eek:
Fatlimey. . .You're my hero!!!
robert chanda
28.01.2011
You have 4 pins of analog and 4 pins of digital.

Each multiplexer takes three digital pins, but all the 4051s can share the same three digital pins. That would give you 4x8 = 32 analog POTs with one digital pin spare.

Alternatively, you can use a pair of CD4052 which takes two digital pins and swaps four analog ins into two analog outs. That would give you 16 analog devices and two spare digital pins.

If you can find a system that borrows or reuses pins, enough to get you three spare digital pins you can hook them up to a Latch-and-shift chip like the 74165 which can be daisy-chained together to give you multiples of 16 inputs, all read using three digital pins.

Seriously, this stuff is not that difficult! Give it a try.
Leeanna Ayla
28.01.2011
So does that mean you could get 32 analog inputs and 12 digital outs on one MF board?
Karry Sappington
28.01.2011
that means more 8 knobs/faders/buttons on the remaining three expansion pins. if its possible i'l surely get one midi fighter righy away, no problem with soldering n coding a bit.
Iona Mertens
27.01.2011
sounds like exactly what I'm wanting to know about

~ct

http://www.soundcloud.com/copperthumb
Candie Kletter
20.01.2011
i

<< Back to MIDIfighter Resources and DiscussionReply

Copyright 2012-2023
DJRANKINGS.ORG n.g.o.
Chuo-ku, Osaka, Japan

Created by Ajaxel CMS

Terms & Privacy