# Calculating latency and resistance with Cascading multiplexers

I'm trying to work out how much latency to expect cascading 11 CD74HC4067 A/D multiplexers into a single master. The datasheet says each mux is rated at 6ns break-to-make time. If I am cascading 11 boards, that means I have 16 * 11 = 176 switches to cycle. Does that mean that if I wanted to cycle through every possible input it would only take 1.056 ms? If so that's great news, but I was expecting from my reading, something like 7 or 8 ms.

Also in a cascading configuration where all the selection pins are connected in parallel, except for the master, given the data sheet specifies a 70 ohm "on" resistance, can I reasonably calculate the total resistance as

70 + (70 || 70 || 70 || 70 || 70 || 70 || 70 || 70 || 70 || 70 || 70) = approx. 176 ohms?

16:1 devices, you have 10 of them feeding into 1 master to feed 1 analogInput on an Arduino?
If so, then each input will see resistance of 2 devices in series, so 140 ohms.

The Arduino will be driving 4 input pins in parallel, so about a 4uA load there.
Plus an Enable line to each device.
To read them all, 160 inputs, will take ~1.6mS in analog reads, plus the switching time.
With a loop within a loop, and using the lower 4 bits of 2 ports for addressing, you can go pretty quick.

``````void loop(){
for (master = 0; master < 10; master = master +1){
PORTC = master; // D19 to D14 (check that)
for ( slave = 0; slave <16; slave = slave +1){
PORTB = slave; // D11 to D8 (check that)
analogArray = (master * 16) + slave;
}
}
}
``````

The schematic looks like this, the schematic is a little hard to follow, so I'll explain it here. Each of the S0 - S3 pins are connected in parallel. These are then connected to the Arduino. Each of their outputs are connected to a single master whose S0 - S3 pins are also connected to the Arduino. That way I can switch between boards with the master, and switch between any of the 16 inputs on them.

Perfectly normal.
So the incoming signal goes thru 2 devices to end up at the Arduino.
Control lines go from Arduino to 11 devices.
No reason to Disable the output from any device, as the output is only connected to other pin on the master 4067.
You'll need a 0.1uF on the VCC pin of each device for reliable operation.
The Arduino has "high current" outputs (compared to lot of other devices) so it will have no problem driving 11 address lines especially if you keep the wiring neat and short.
You can use my code example to cycle thru one chip's outputs at a time, or revise it to cycle thru the master channels in the inner loop and have the outer loop cycle thru the 1 of inputs. Total time required will be the same.

I can't zoom in enough to see where the groups of address lines are connected PORT-wise, hopefully you can use 4 bits on a port and not have to a bunch of fooling around to cycle 4 bits from 0000 to 1111.

The datasheet says each mux is rated at 6ns break-to-make time. If I am cascading 11 boards, that means I have 16 * 11 = 176 switches to cycle. Does that mean that if I wanted to cycle through every possible input it would only take 1.056 ms?

No.
While the chips can operate at 6nS the Arduino will take much longer to set the address pins, and then take 100uS to read the analogue input and some more time to store the data somewhere.

You can measure how long it takes to do this by lighting the internal LED at the start and turning it off at the end. And then measure how long it is on with an oscilloscope.

Calculating it is a bit more tricky. Write the code, compile it and then look at the resulting machine code and count the number of cycles it takes to compleat one cycle of setting the address, reading the analogue to digital converter and storing the result. Not a job for a beginner.

I’m seeing
28680
28676
28676
28676
28684
28676
28672
microseconds to read 256 channels into an 256 word array.

``````byte master;
byte slave;
int analogArray[256]; // 512 bytes
unsigned long timeStart;
unsigned long timeEnd;
unsigned long timeElapsed;

void setup(){
Serial.begin(115200);
pinMode (8, OUTPUT);
pinMode (9, OUTPUT);
pinMode (10, OUTPUT);
pinMode (11, OUTPUT);
pinMode (14, OUTPUT);
pinMode (15, OUTPUT);
pinMode (16, OUTPUT);
pinMode (17, OUTPUT);

}
void loop(){
timeStart = micros();
for (master = 0; master < 16; master = master +1){  // 16 channels of master
PORTC = master; // D19 to D14 (check that)
for ( slave = 0; slave <16; slave = slave +1){ // 16 channels each slave
PORTB = slave; // D11 to D8 (check that)
analogArray [(master * 16) + slave] = analogRead(A0);
}
}
timeEnd = micros();
timeElapsed = timeEnd - timeStart;
Serial.println (timeElapsed);
delay(1000);
}
``````

And 19712
19716
19716
19716
19720
19716
19716
19724