I’ve been working on some driver code for a LTC1390CN 8:1 analog multiplexer, so here it is.
The point of this multiplexer is to limit the number of voltage dividers for a bunch on 12V sensors for a car project I am working on. By using this multiplexer I only need a single AnalogIn on the FEZ, but I need 3 DigitalOut ports to drive the multiplexer.
The multiplexer has a nice trick; you can put up to 15v into the analog inputs while the logic only needs a TTL/CMOS signal to select the proper input.
http://www2.conrad.nl/goto.php?artikel=152226
public class LTC1390CN
{
OutputPort _clock;
OutputPort _cs;
OutputPort _data;
AnalogIn _value;
public LTC1390CN(FEZ_Pin.Digital clk, FEZ_Pin.Digital cs, FEZ_Pin.Digital data, AnalogIn.Pin value)
{
_clock = new OutputPort((Cpu.Pin)clk, false);
_cs = new OutputPort((Cpu.Pin)cs, false);
_data = new OutputPort((Cpu.Pin)data, false);
_value = new AnalogIn(value);
_value.SetLinearScale(0, 3300);
}
public int Read(byte port)
{
// when !CS is high, the input data on the data1 pin is latched into the 4 bit shift register on each rising clock.
_clock.Write(false);
_cs.Write(true);
_data.Write(true);
_clock.Write(true);
_clock.Write(false);
_data.Write((port & 0x04) != 0);
_clock.Write(true);
_clock.Write(false);
_data.Write((port & 0x02) != 0);
_clock.Write(true);
_clock.Write(false);
_data.Write((port & 0x01) != 0);
_clock.Write(true);
_cs.Write(false);
_clock.Write(false);
int val = _value.Read();
return val;
}
}