I added a new feature to micro-OSC that enables digital output pins to "toggle" between states automatically on a repeating schedule. In this mode, the pin oscillates between an output state (of value high or low) and the *input state* (also called the tristate). The output state is active when the clock tick counter + X is equal to zero, mod N, otherwise the pin is an input. For example, to make pin /a/4 go high on every other tick we send this message:

/a/4/v 1 2 0

To make pin /b/6 go low at the same time:

/b/6/v 0 2 0

Now lets make pins /b/7 and /c/0 go high/low on the same rotation period (mod 2) but with an offset of 1:

/b/7/v 1 2 1
/c/0/v 0 2 1

Now, suppose we use /a/4 and /b/6 to form the V+ and Ground for a sensor attached to analog input AN0. And, suppose we use /b/7 and /c/0 to be the V+ and Gnd of another sensor also attached to AN0. Because /a/4 and /b/6 go to the tristate when /b/7 and /c/0 go to outputs (and vise-versa), one sensor is effectively "removed" from the circuit while the other is active. We have just accomplished analog multiplexing without needing an external multiplexing chip! And, there are no bias resistors or other tricks needed in the circuit. Additionally, the timing of the toggling is such that the next mode switch happens right after the last analog measurement. This gives the sensor the longest possible time a relatively to "settle" before the next measurement (e.g., 2msec settling time at 500 Hz).

How far can we take this? For each order of multiplexing, two pins are needed, and the entire analog bank can be multiplexed. So, on a CUI having 16 digital output pins and 13 analog inputs, we can do 8:1 multiplexing--at a sample rate of 500 Hz, we can read 13 * 8 = 104 analog inputs at about 60 Hz. If the multiplexed sensors share the same pullup resistor (which is not the case in the example below), then the ground pin does not also need to be toggled, so we could achieve 16:1 multiplexing with 208 total inputs sampled at 30 Hz.

In this example I have two sliders multiplexed to pin AN0.

[inline-center:1]

In MaxMSP we use the state of the multiplexing-control pin to route the floating point number to the appropriate direction:

[inline-center:2]

Caveat: there appears to be some cross-talk between the multiplexed elements on the order of 10^-3 (about 1-2 bits worth). Possible reasons: stray capacitance of the disconnected sensor? Capacitance of the digital input pins which are inactive? May consider discharging those pins just before setting them to input.

Attachments