/* model for an n-channel multiplexer each channel is simple modelled by a resistor between input and output in[0]----R------| in[1]----R------|---- out .... the value of the channel resistance is controlled by the bit pattern at the input, the selected channel is ron, all other are roff if a new channel is selected, the old on get switched of in ttransit_off, the new one is switched on in ttransit_on */ module multiplexer(in,ctrl,out); input [0:pow(2,size)-1] in; input [0:size-1] ctrl; // LSB : MSB output out; electrical in,ctrl,out; parameter integer size=2 from [1:inf); parameter real vth = 1.4, // threshold for 0/1 on ctrl bi ts ron = 1 from (0:inf), // channel on resistance roff = 1M from (ron:inf), // channel off resistance ttransit_off = 5n from [0:inf), // transit time from ron -> rof f ttransit_on = ttransit_off from [ttransit_off:inf); // transit time form roff -> ro n integer rch [0:pow(2,size)-1]; integer pow2 [0:size]; integer channel; real iout; analog begin @(initial_step) begin channel = 0; // initial value for ch annel for (i=0;i vth) channel = channel + pow2[i]; rch[channel] = ron; // switch on the new ch annel end iout = 0; for (i=0;i