Hall sensors and multiplexing erratic readings

Status
Not open for further replies.

Benjy

New member
Dear all,
I am currently working on the midification of an organ pedalboard. I am using a Teensy 4.1 to control three 16x multiplexers (CD74HC4067) to read (among other things to be implemented) the state of 30 hall sensors (A3144EUA).
The Teensy is connected via USB cable to the computer and the circuit is powerd by the 5v pin (which should be fine as the current is drawn directly from the usb port). I measured the current consumption of the sensors and multiplexers to be ~130 mA. See drawing and code below (I did not draw the multiplexer control lines for clarity). The multiplexers control pins are driven simultaneously as all the identical control pins are connected to the same teensy port. The signal out pins of the multiplexers are connected to 3 different pins (37, 35, 33) with the internal pullup resitors switched on. I have a strange effect: some sensors would trigger a signal on the whole multiplexer (I get a signal on all the 16 entries). Even if I switch the multiplexer to off by putting its enble pin to HIGH, triggering some sensors with a magnet will still trigger the whole multiplexer and I get a readig as if all the 16 sensors of this multiplexer are being triggered. I have done some troubleshooting (That did not Change anything):
-I checked for shorts whitout finding any.
-Adding a big delay (up to a second) between the readings of the signal pins. The 16 pins seem still to be trigered instantaneously.
-Connecting the enable pins of the multiplexers to the teensy to enable them only during a read, also did not change a thing.
-The sensors who are fine would draw between 40 and 60 micro Amps. The ones that cause the problem between 80 and 100 micro Amps. Replaced them, no improvement.
-Triggering 2 sensors at once also causes erratic readings.
-Instead of supplying the Multiplexers via the 5V pin, I changed it to the 3V pin. No sucess.
-Shorting the multiplexer input pins by hand using a cable connected to the ground pin of the teensy works perfectly. I tried to play a little tune with 2 cables on the midi interface, it worked flawlessly.
-Shorting by hand also only draws about 40 to 60 micro amps.
-I decided to pull up the sensors before the multiplexer by connecting a 10k resitor beween the floating out and 3.3V. (does not change anything)
-Connecting a 10k resitor in series to the out pin of the sensors seems to resolve the problem for that sensor, but then other pins behave eratically.
-It seem that triggering one sensor affects the others. As have only a multimeter and not an oszilloscope I could not search for any spikes or drops in the voltages.
-So I came to the conclusion: The design is flawd by default :D. Does someone see what could be the problem?
-I think that putting some decoupling capacitors might be necessary (I ordered some) but I think the problem is more involved.
Any Ideas are welcome !

Here is the Code:

Code:
//defining pin names for the multiplexer control
const uint8_t s0 = 26;
const uint8_t s1 = 28;
const uint8_t s2 = 30;
const uint8_t s3 = 32;

//Eneable pins for switching on the multiplexers 
const uint8_t en0 = 16; 
const uint8_t en1 = 15;
const uint8_t en2 = 14;

//port for digital read of the sensors signals
uint8_t d_in_1 = 33;
uint8_t d_in_2 = 35;
uint8_t d_in_3 = 37;

const uint8_t b1 = 1;
const uint8_t b2 = 2;
const uint8_t b4 = 4;
const uint8_t b8 = 8;

const int base_note = 36; // 36 -> C2 Lowest note on organ pedalboard
uint8_t note_offset = 0;

const uint8_t midiChannel = 1;

int *note_states =  new int [48];
int last_state, this_state;

void setup() {
  //Debug serial monitor
  Serial.begin(384000);

  //Setting the output pins
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);

  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);

  //setting the enables pins
  pinMode(en0, OUTPUT);
  pinMode(en1, OUTPUT);
  pinMode(en2, OUTPUT);

  digitalWrite(en0, HIGH);
  digitalWrite(en1, HIGH);
  digitalWrite(en2, HIGH);

  //Setting pins 14, 15, 16 to digital input with pullup resistor
  pinMode(d_in_1, INPUT_PULLUP);
  pinMode(d_in_2, INPUT_PULLUP);
  pinMode(d_in_3, INPUT_PULLUP);

  //Initialisation of the notes states to off
  for (uint i = 0; i < 48; i++)
  {
    note_states[i] = HIGH;
  }
  delay(1000);
}

//incr variable
int i = 0;
void loop() {
  
  digitalWriteFast(en0, HIGH);
  digitalWriteFast(en1, HIGH);
  digitalWriteFast(en2, HIGH);
  
  delayMicroseconds(10);
  
  digitalWriteFast(s0, HIGH & bitRead(i, 0));
  digitalWriteFast(s1, HIGH & bitRead(i, 1));
  digitalWriteFast(s2, HIGH & bitRead(i, 2));
  digitalWriteFast(s3, HIGH & bitRead(i, 3));
  
  delayMicroseconds(15);

  digitalWriteFast(en0, LOW);
  digitalWriteFast(en1, LOW);
  digitalWriteFast(en2, LOW);

  delayMicroseconds(10);
  
  for (int k = 0; k < 3 ; ++k) {
    note_offset = i + 16 * k;
    last_state = note_states[note_offset];
    this_state = digitalRead(d_in_3 - 2 * k);
    
    if (last_state == this_state)
    {
      continue;
    }
    else
    {
      if (this_state == LOW) //on
      {
        usbMIDI.sendNoteOn(base_note + note_offset, 100, midiChannel);
      }
      else // off
      {
        usbMIDI.sendNoteOff(base_note + note_offset, 100, midiChannel);
      }
    }
    note_states[note_offset] = this_state;
  }

  ++i;
  if (i > 15) {
    i = 0;
  }
}
 

Attachments

  • IMG_20211122_002807.jpg
    IMG_20211122_002807.jpg
    149 KB · Views: 49
No decoupling capacitors? If so fix that first - 100nF for each IC (each Hall switch is an IC), and something
like 10--100uF bulk decoupling perhaps. Lack of decoupling can lead to all sorts of confusing behaviours
so its wise to rule that out before anything else.

I'd put the physical pull-ups _after_ each analog multiplexer, perhaps 4k7 or 2k2 (you need much stiffer
pullups when the signals travel over long wires, otherwise you risk noise pickup and capacitive cross-talk).

How are you running the cabling - ideally each signal has its own ground-return wire, but at a pinch you
can share a ground return with several signals. Again getting this into good shape reduces risks of
cross-talk and EMI.
 
Thanks

No decoupling capacitors? If so fix that first - 100nF for each IC (each Hall switch is an IC), and something
like 10--100uF bulk decoupling perhaps. Lack of decoupling can lead to all sorts of confusing behaviours
so its wise to rule that out before anything else.

I'd put the physical pull-ups _after_ each analog multiplexer, perhaps 4k7 or 2k2 (you need much stiffer
pullups when the signals travel over long wires, otherwise you risk noise pickup and capacitive cross-talk).

How are you running the cabling - ideally each signal has its own ground-return wire, but at a pinch you
can share a ground return with several signals. Again getting this into good shape reduces risks of
cross-talk and EMI.
Thank you very much for your advice. I will redo the cabling as I have one ground cable for all sensors :-o so I might try to group them into smaller groups, I will also put the decoupling capacitors. It might take me some days. But I will post an update !
King regards.
 
So I did some rewirering and added the decoupling capacitors: I seriously underestimated interferences: Just using different ground return wires for the sensors and the multiplexers improved the situation dramatically. But I still got some interferences especially when pressing multiple pedals at once. So I added the 100nF to each IC, and splitted the ground return wires in groups of 5. This solved the problem!
You also mentioned bulk decoupling. I am not sure if I should add more than 10uF as bulk decoupling to not draw to much current from the USB port on plugin.

Thanks!
 
I note one of my old Arduino boards has two 47µF caps, but the current USB2 specifications say 10uF max...
 
Status
Not open for further replies.
Back
Top