2

I am currently working on an Arduino Zero with a 74HC4067 multiplexer and I am experiencing inconsistencies when testing some of the channels.

My class is the following (it should be functional for 8 or 16 channels multiplexers).

Multiplexer.h :

#ifndef Multiplexer_h
#define Multiplexer_h

#include "Arduino.h"

class Mux { public: Mux(uint8_t numberOfChannels, byte sigPin, byte adress1, byte adress2, byte adress3, byte adress4 = 0);

uint8_t muxRead(byte pin);//Read specific mux pin
void selectMuxPin(byte pin);

private: uint8_t m_numberOfChannels; byte m_sigPin ; byte m_adress1 ; byte m_adress2 ; byte m_adress3 ; byte m_adress4 ; uint8_t m_numberOfAdressPins; };

#endif

Multiplexer.cpp :

#include "Multiplexer.h"

//**************************************************************

Mux::Mux(uint8_t numberOfChannels, byte sigPin, byte adress1, byte adress2, byte adress3, byte adress4)

: m_numberOfChannels(numberOfChannels), m_sigPin(sigPin), m_adress1(adress1), m_adress2(adress2), m_adress3(adress3), m_adress4(adress4) { if(m_numberOfChannels > 8) {m_numberOfAdressPins = 4;} else {m_numberOfAdressPins = 3;}

//Set adresses to OUTPUT pinMode(m_adress1, OUTPUT); pinMode(m_adress2, OUTPUT); pinMode(m_adress3, OUTPUT); if(m_numberOfChannels > 8){pinMode(m_adress4, OUTPUT);};

//Set adresses to LOW digitalWrite(m_adress1, LOW); digitalWrite(m_adress2, LOW); digitalWrite(m_adress3, LOW); if(m_numberOfChannels > 8){digitalWrite(m_adress4, LOW);};

pinMode(m_sigPin, INPUT_PULLUP); }

//**************************************************************

uint8_t Mux::muxRead(byte pin) { selectMuxPin(pin); bool value = digitalRead(m_sigPin); return(value) ; }

void Mux::selectMuxPin(byte pin) { const int selectPins[4] = {m_adress1, m_adress2, m_adress3, m_adress4}; if (pin > (m_numberOfChannels - 1)) return; // Exit if pin is out of scope

for (int i = 0; i < m_numberOfAdressPins; i++) { if (pin & (1<<i)) {digitalWrite(selectPins[i], HIGH);} else {digitalWrite(selectPins[i], LOW);} } }

To make my tests on the 74HC4067, I connect my multiplexer, I put the pin 8 of my Arduino to the "LOW" state and with the help of a jumper cable I test each of the pins via the following code:

#include "Multiplexer.h"

//**************************************************************

Mux Mux0(16, 6, 2, 3, 4, 5);

//**************************************************************

void setup() { Serial.begin(115200); }

//**************************************************************

void loop() {

//Set pin 8 to LOW for the test with a jumper analogWrite(8, LOW);

//For this test, we print the name of the multiplexer's channel if it's LOW

bool channel0 = Mux0.muxRead(0); if(!channel0) Serial.println("Channel 0");

bool channel1 = Mux0.muxRead(1); if(!channel1) Serial.println("Channel 1");

bool channel2 = Mux0.muxRead(2); if(!channel2) Serial.println("Channel 2");

bool channel3 = Mux0.muxRead(3); if(!channel3) Serial.println("Channel 3");

bool channel4 = Mux0.muxRead(4); if(!channel4) Serial.println("Channel 4");

bool channel5 = Mux0.muxRead(5); if(!channel5) Serial.println("Channel 5");

bool channel6 = Mux0.muxRead(6); if(!channel6) Serial.println("Channel 6");

bool channel7 = Mux0.muxRead(7); if(!channel7) Serial.println("Channel 7");

bool channel8 = Mux0.muxRead(8); if(!channel8) Serial.println("Channel 8");

bool channel9 = Mux0.muxRead(9); if(!channel9) Serial.println("Channel 9");

bool channel10 = Mux0.muxRead(10); if(!channel10) Serial.println("Channel 10");

bool channel11 = Mux0.muxRead(11); if(!channel11) Serial.println("Channel 11");

bool channel12 = Mux0.muxRead(12); if(!channel12) Serial.println("Channel 12");

bool channel13 = Mux0.muxRead(13); if(!channel13) Serial.println("Channel 13");

bool channel14 = Mux0.muxRead(14); if(!channel14) Serial.println("Channel 14");

bool channel15 = Mux0.muxRead(15); if(!channel15) Serial.println("Channel 15"); }

For most of the channels it works quite well. When I connect the jumper (pin 8) to a channel of the multiplexer, the name of the corresponding pin is displayed in the console.

However, two channels are problematic. Channel 0 and channel 8. No matter if I connect the jumper to one or the other, I see in the console "Channel 0" and "Channel 8" as if both were connected and the change of state of one would cause the change of state of the other.

Any idea why?

Thanks

Fanch
  • 23
  • 3

1 Answers1

2

I gather it is part of a learning experiment. Logically this does not compute however there are many reasons something like this could happen. A bad IC is the first thing that comes to mind but they are generally very rugged devices. If you have a scope probe the power supplies to be sure they are clean and stable, if so start by holding it in one of the bad states and take voltage measurements on VCC, Ground, several other pins and the related pins. Your voltage on each pin should be within 0.1V of the appropriate power supply pin. If not it would indicate a short especially if it goes somewhere mid supply voltage. If this is a breadboard flip the bad pins out and test again. If everything is in speck it is a short, if it still show you probably have a bad IC.

Gil
  • 1,863
  • 9
  • 17