Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 19 of 19

Thread: Will the 16 channel multiplexer CD74HC4067M96 work with Teensy 3.6?

  1. #1
    Junior Member
    Join Date
    Apr 2019
    Posts
    10

    Will the 16 channel multiplexer CD74HC4067M96 work with Teensy 3.6?

    Hej, I made a succesful first project and I am looking towards expanding the amount of hardware. Its a midi sequencer. I have been having a blast using the visual teensy to program the teensy from visual studio code.

    I want to have something like 16 switches, 16 leds and 16 knobs.

    Will this https://www.ti.com/store/ti/en/p/pro...=CD74HC4067M96 multiplexer work for both receiving the input of 16 digital switches and analog knobs and sending output to 16 digital leds? Ive read all about how to loop over the channels of the multiplexer and letting some time pass before reading the signals. I understand that 16 channels might be a lot to loop over with so I am wondering if this would work at all. I need to loop over all this components all the time.

    Will I need an extra capacitor somewhere in the multiplexer circuit or can I just do like in https://www.pjrc.com/teensy/td_midi.html many knobs example even though its a different multiplexer?

    Should I use 3.3v pin in Teensy 3.6 or should I use the Vin (3.6v to 6v) pin? Datasheet says "HC Types 2V to 6V Operation High Noise Immunity: NIL = 30%, NIH = 30% of VCC at VCC = 5V" So I guess the 3.3v should be fine?

    Thanks for the help

  2. #2
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,295
    As the midi page notes: don't add capacitance as it increases the time it takes to read a stable voltage. The same method shown on the midi page works with that mux by adding a forth select signal. You can chain the 16 chnl mux the same way as shown there.

    You might find this code useful
    https://forum.pjrc.com/threads/47074...l=1#post157268

    It's the closest I've done ... I think it's functional and should work well on fast Teensy without hobbling it with micro-seconds of delay on every read.

    It's a while ago and I don't normally use mux....

  3. #3
    Junior Member
    Join Date
    Apr 2019
    Posts
    10
    Thanks for reply!

    What about which power pin from teenay 3.6 to use?

    Im fairly strong coding so I think I will manage.

    Can i chain all three multiplexers even though 1 is digital inputs 1 is analog inputs and 1 is digital outputs?

  4. #4
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,295
    I think that mux works fine at 3.3v but you can have a mux at 5v as long as you source your voltage dividers and switches with 3.3v.

    An analog mux treats the signals the same. So reading the result as digital or analog is no problem as long as you read the signal pin from each mux appropriately.

    I really only faked signals thru the mux to help others and to know how in case I need to so I’m not really expert.

    That said, I did find everything worked just as in Paul’s examples; you just have an extra select signal on your mux control.

    Teensys are very fast compared with mux settling times so you should have lots to spare if you avoid delays. If you’re just scanning for a controller you can just use microsecond scale delay.

  5. #5
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,295
    The HC version works at 3.3v

    I used this breakout board https://www.sparkfun.com/products/9056

    I donít know if using the mux to control LEDs is the best solution... I think you could use an output pin to turn them on during the portion of the time the mux is on their channel but you might want to look itís into an led driver or shift register.

    If youíre planning to use USB power watch your overall current draw.

    FYI.. lower resistance pots allow faster settling time but draw more power.

  6. #6
    Junior Member
    Join Date
    Apr 2019
    Posts
    10
    Quote Originally Posted by oddson View Post
    The HC version works at 3.3v

    I used this breakout board https://www.sparkfun.com/products/9056

    I don’t know if using the mux to control LEDs is the best solution... I think you could use an output pin to turn them on during the portion of the time the mux is on their channel but you might want to look it’s into an led driver or shift register.

    If you’re planning to use USB power watch your overall current draw.

    FYI.. lower resistance pots allow faster settling time but draw more power.
    aha interesting! thanks for all the info!

    I didnt know mux was bad idea for LEDs, i will take a look at this led driver or shift register. i basically have the sequence steps represented in the leds all the time so i have to have independent control over the 16 steps.

    im using 10kohms linear pots, do you reckon thats a good value?

    i also use 220ohms resistors for the LEDs and 10k pull down resistors for the switches. does the multiplexer change anything regarding these resistors or is it correct that I still use them?

  7. #7
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,295
    I'm not sure it's a bad idea;. I'm not qualified to say either way.

    With a serial-register based IC I think you track the state of your leds with bit logic and write the full register at some refresh rate rather than writing directly whenever your code changes the state.

    Re values. Those are common values for these functions but it's really about your power budget.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,298
    10K is fine for the pots. If you use capacitors, put 1 cap on each pot. Never add a capacitor on the output of the mux.

    As explained on the USB MIDI page and mentioned here too, the main issue with this sort of mux chip for inputs is you need to delay between changing the mux control pins and actually reading the signal. Several microseconds may be required for the signal to become stable at Teensy's pin.

    74HCxxx parts should use 3.3V power. Their spec for minimum logic high is usually VDD * 70%. So if you run it at 5V, it's not guaranteed to recognize an input as logic high until it's 3.5V or more. Usually the threshold from low to high will be around 2 to 2.5V, so these chips normally work, but technically depending on that behavior is out of spec (much like overclocking usually works, but is never guaranteed).

    74HCTxxx parts should be used with 5V power (and most are rated for only 4.5 to 5.5V). The have special inputs which recognize anything over 2V as logic high. But the "HCT" parts are less common, partly because they aren't rated for use at other voltages, and partly because the special circuitry which makes the logic threshold under 2V also makes the circuit slightly slower (but still plenty fast enough for this sort of use).

    This sort of mux chip is a terrible idea for LEDs. Two big problems. First, you can only light 1 LED at a time that way, so the current needs to be 16X higher during that time if you want the same brightness. Some huge LED displays do work that way (using different chips), but it's very difficult to design and if your code ever freezes or stops, you'll burn out the LED if the current is sustained at 16X the normal amount.

    The second problem with using that type of mux chip for LEDs is the on resistance. While you can mostly just think of the mux like a mechanical rotary switch, the reality is when it's turned on the connection is basically a resistor, usually in the 100 to 1000 ohms range. For inputs to Teensy, that's fine, since the pin using input mode is a high impedance (essentially like not connected to anything). But if you're trying to drive LEDs, the mux actual as if you have an extra resistor in series between Teensy and the LED. That will limit the brightness, which is the last thing you want when you're turning the LED on for only 1/16th of the time and need to to be 16X brighter to make up for the short time driven.

    Best to use a shift register or I/O expader chip to drive LEDs. Pay attention to the chip's current specs. Some chips are rated for 24 mA or more, while others are designed for much less, often only 4 mA.

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,298
    Also understand this sort of mux circuit almost never gives inputs signals as good as direct connection. Even if your code waits plenty of time for the signal to settle, usually adding this sort of circuitry ultimately adds noise to the readings you will get.

    Here's a laundry list of things you can do to minimize (but never completely eliminate) those noise effects.

    Locate the mux chip close to Teensy.

    Keep the wires between Teensy and the mux chip short.

    Run the GND wire together with the signals, so you minimize the loop area between and signal and its returning GND current.. If using a ribbon cable, a common approach is to put GND on every other pin, so each signal has GND on both sides.

    Use a 0.1uF ceramic capacitor across the power pins of the mux chip. Locate it as close as possible to that chip and keep the leads short.

    Also run each signal wire with GND. Shielded cables are best, but overkill in many cases. Simply twisting the GND wire together with the signal wire usually works well.

    Avoid any other pins changing during the settling delay. Don't forget that PWM signals are changing the pin rapidly and automatically.

  10. #10
    Junior Member
    Join Date
    Apr 2019
    Posts
    10
    Thank you SO much for writing all of that Paul.

    Unfortunately it seems that 16 knobs + 16 leds + 16 switches kind of increases the complexity of the whole thing a lot. I am not sure if I have the skills to pull this one. I wonder if its not better to tone down the ambition and go for 8 steps, maybe that I can connect all directly to teensy without struggling with these lack of pins.

    If I go for the challenge and understand correctly:

    Tlc5940 to drive the LEDs.
    74HCxxx to read the knobs and the switches
    place the mux and driver close to the teensy
    use capacitors next to mux power with short leads

    Run the GND wire together with the signals
    what do you mean by that? I will be doing PCBs in KiCad.

    I havent used capacitors before so it will take some to figure out where to put them for each pot and where to put them across the power pins of the mux chips.

    I will make some kicad schematics and come back to see if I am on the right track.

    Thank you again for helping out. I think I know what I need to do now.

  11. #11
    Switches with enough poles can be wired in a 4 x 4 matrix. That'll save you 8 pins without having to use a mux. Just a thought.

  12. #12
    Junior Member
    Join Date
    Apr 2019
    Posts
    10
    Click image for larger version. 

Name:	Screenshot 2020-01-20 at 16.03.10.jpg 
Views:	9 
Size:	99.3 KB 
ID:	18791

    Hey Paul and Oddson, I created a schematic implementing the circuits needed for two 16 channel multiplexers of the 74HC type and one 16 channel led driver of the TLC5940 type.

    I used https://www.pjrc.com/teensy/td_libs_Tlc5940.html#bottom for the LED driver schematic and https://www.pjrc.com/teensy/td_midi.html for the multiplexers schematic.

    You can see 1 example pot and switch with led symbols in my schematic. I expect to add 15 more of each if this base diagram is correct.

    I am still using a 220ohm resistor in between the LED driver and the LED itself, is this needed as with typical LED wiring or can I skip it if power comes from the output of the TLC5940?
    I am using different pins than those in the 3.6 column of the https://www.pjrc.com/teensy/td_libs_Tlc5940.html#bottom table, because I wont to keep the first 14 pins for adding the Audio Shield in the future.

    Note that I dont have any capacitors anywhere, would they help with noisy readings if I had 1 between each pot and the multiplexer input channel?


    Bare in mind I already have a 4 step version of this schematic already implemented, I am trying to take the next step by adding multiplexers and LED driver and having the board open for extension in case i want to also add audio generation.

  13. #13
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,295
    ...non-qualified personnel answer:

    The data sheet shows LEDs without current limiting resistors in the 'typical application' schematic.

    The pot setup is OK but you might want to consider a cap between wiper and ground (near the MUX rather than on the pot itself) -- I've read it not only helps filters out power spikes but also 'charges' up the far-side of the MUX faster once it switches (the charge in the cap maintains the output voltage once the stay capacitance is encountered after switching). While it does not appear to be essential; it may allow for less time waiting for the voltage to stabilize after switching the mux... but if you have to do other processing anyway this may not be required or even beneficial if you can switch the controls of the mux before you're ready to read them.

    Never add capacitance to the Teensy side of the mux as that will make switching MUCH slower.

    I can't say if your IC connections are correct. I don't see anything wrong but that's not saying much

  14. #14
    Junior Member
    Join Date
    Apr 2019
    Posts
    10
    Hej Oddson,

    I now see that in Paul's schematic the switches are connected to the mux on one side and to the ground on the other side. There is no pulldown resistor. Do I need the pulldown resistor in my schematic or can I spare it?

  15. #15
    Junior Member
    Join Date
    Oct 2014
    Posts
    10
    I put a 1us delay after the mux pin switch before I read the same. I still get some noise, but then I apply temporal/weighted filtering (something like, last read value for this pot counts for 70%, and new value counts for 30%), as well as freezing values completely if the user isn't actually turning the pot.

    haven't tried capacitors, different delays or kinds of filtering. I'm relatively new to multiplexers as well.

  16. #16
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,295
    There is no pulldown resistor. Do I need the pulldown resistor in my schematic or can I spare it?
    No… I guess you don't if you enable the pin that's reading the mux with an internal pullup.

    (Note you need to connect the switch to pull to ground instead of to 3.3v if you want to skip a resistor as the internal option is for a pullup for active-low switching. The logic of the code has to reflect which version of this you are using.)

    It's possible you'd need less settling time with lower value resistors stabilizing the mux side before it switches but if you're reading pot at the same rate you'd have to wait longer for them anyway.

    I'm not expert at any of this stuff... I try to field beginner questions on MIDI and in particular try to warn noobs from trying to build a monster controller as their first project.
    Last edited by oddson; 01-22-2020 at 04:40 PM.

  17. #17
    Junior Member
    Join Date
    Apr 2019
    Posts
    10
    You are a godsend oddson! And just for your tranquility, im merely jumping from 4 steps to 16 steps, i already have a fully featured version with 4 steps.

    it so happens that each step is a switch a pot and an led so the complexity of expanding i/o to 16 of each add a looot of overheard

    im drawing the pcb now and im quite sure it wont work on the first go, but im fine with doing a few revisions until it works, i cant be fucked to go step by step with each IC and breadboarding

  18. #18
    Junior Member
    Join Date
    Apr 2019
    Posts
    10
    Hej everyone,

    I still havent surrendered, here is a part of the PCB I am working on with two multiplexers and a led driver to control sixteen cherry switches/led/pots

    I know this is not a forums for reviewing PCBs but if you see anything glaringly wrong please let me know, I am going to send the PCBs for prototyping soon.

    Click image for larger version. 

Name:	Screenshot 2020-01-26 at 18.16.03.png 
Views:	5 
Size:	84.1 KB 
ID:	18878

  19. #19
    Junior Member
    Join Date
    Feb 2020
    Posts
    6
    Hey, Funny enough I also start working on a MidiSequencer project. However I want to use rotary encoders, which make this even more difficult. I believe. I will ask how to multiplex rotary encoders in another place.

    However for your LED problem I have another solution that I have found. Use WS2812B diodes aka NeoPixels. These exist in various form factors and they are addressable. In short, you just put them into a chain and each diode gets an address automatically 1, 2, 3 4, which can then be accessed from software directly. You only need one pin from your teensy and you get full RGB on as many LEDs as you want and there are libraries for them. It's easy to root too.

    As for the button. Just go for a 4x4 matrix with diodes in case you want simultaneous button presses. But I think that you are already doing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •