Analog multiplexing (4051) with sticky state?

Hi everyone

My project is still at the conceptual stage but if I understand it correctly I could use several 4051 8 channel analog mulitplexers to get a large number of inputs to Arduino. I think I understand the concept of chaining them together from what I've read on this site.

Having thought about this though if I were to loop round all the inputs one at a time, although it would be really quick, there is a possibility that I could miss one going from LOW to HIGH if it happened very quickly. Ideally I would like the input to be sticky until I clear it or have something record the count that I can pickup during the next loop iteration. I'm no expert but could I use a binary counter or something attached to each input to record the state change or is there another way to achieve this. Basically I don't want to miss a single change in state once it has changed (LOW->HIGH).

Many thanks

A 4051 is a bad chip to use for digital input multiplexing as it is an analogue multiplexer.

there is a possibility that I could miss one going from LOW to HIGH if it happened very quickly.

It would have to go LOW, HIGH, LOW in less than the time for a scan.

If you don't want to miss them then the answer is to use a flip flop latch to catch the transition. This is quite messy and involves a lot of logic chips. However if you use a port expander like the MCP23S17 there is a latch built in called the interrupt register. This will capture you rapid transitions. It also has the advantage of having an interrupt output pin which you can connect to an input pin. Then if any of the 16 inputs changes this pin changes. That means you only have to monitor one pin from the code and only bother to read all 16 pins when you know something has changed.

Thanks for that Mike.

Can you chain together MCP23S17s and still use the interrupts and be sure you wouldn't miss anything? What would the theoretical number of inputs be do you think with an Uno?

Thanks

A 4051 is a bad chip to use for digital input multiplexing as it is an analogue multiplexer.

Any technical basis for that position? I don't see why the 4051 can't be used.

Can you chain together MCP23S17s and still use the interrupts and be sure you wouldn't miss anything?

The MCP23S17 is an addressable SPI chip. That means that without taking any further measures you can have 8 of these together on one SPI bus, so that gives you 16 * 8 = 128 inputs. If you use another pin as a chip enable then you can add another 8 chips, and so on for each chip enable pin.
The interrupt pins are for every 8 inputs but these are open collector and so can be wired ORed together to give you just one pin to monitor if you want. Of course that means when you see a change you have to read all the pins so it is a compromise between the number of pins you have to monitor and the number of pins you have to read when you do see a change.

I don't see why the 4051 can't be used.

I am not saying they can't be used I am saying it would be a bad choice to use them. Essentially they are an analogue multiplexing chip being used for a digital signal. You are much better off for things like speed, noise rejection, signal integrate using a digital chip for a digital signal, especially for a multi-level depth of multiplexing. That is, when passing through several analogue chips the signal is degraded by each chip and the degradation is cumulative. Using a digital chip like a 74LS151 (8 inputs to 1 line) or a 74LS150 (16 inputs to 1 line) the signal is regenerated at each level of multiplexing.