Multiplexer channel selection
It's more of a conceptual question then a programming issue. I use a pic to control the inputs of a 16 channel multiplexer, thus allowing me to select a certain channel and read voltages from a multi cell battery pack. How do I inteligently cycle through the mux control inputs other then aliasing ports and attributing values ?
Code:
a_mux var porta.1
b_mux var porta.2
c_mux var porta.3
d_mux var porta.4
inh var porta.5
'select MUX channel X0
a_mux = 0:b_mux = 0:c_mux = 0:d_mux = 0:inh = 0
'select MUX channel X1
a_mux = 1:b_mux = 0:c_mux = 0:d_mux = 0:inh = 0
'select MUX channel X2
a_mux = 0:b_mux = 1:c_mux = 0:d_mux = 0:inh = 0
'select MUX channel X3
a_mux = 1:b_mux = 1:c_mux = 0:d_mux = 0:inh = 0
'and do this up to channel 15
It would be really useful to cycle using a for.. next loop and I belive it's quite possible because the multiplexer's truth table consists of consecutive binary numbers for the selection inputs. I'm thinking something like:
Code:
i var byte
a_mux var porta.1
b_mux var porta.2
c_mux var porta.3
d_mux var porta.4
i.7 var a_mux
i.6 var b_mux
i.5 var c_mux
i.4 var d_mux
for i= 0 to 15 ' meaning i=00000000
00000001
00000010
' do stuff
next i
But it doesn't compile well because quote "Variable already an alias". How do I get around this ? All the code above is just for demo purposes, I know TRIS is not set and the other stuff that goes into an actual program is missing