Hi I'm trying to program my Arduino using some digital signals to turn ON/OFF 3 different multiplexers which each have 24 channels. The channels selection signals are for the ADG732BRUZ and pins 10, 11, 12 are used to enable the multiplexers one at a time. However, I was only able to turn ON/OFF the channel selection bits but unable to get the enable pins to work at all.
int S0 = 0; // A0 connected to pin 0
int S1 = 1; // A1 connected to pin 1
int S2 = 2; // A2 connected to pin 2
int S3 = 3; // A3 connected to pin 3
int S4 = 4; // A4 connected to pin 4
int WR = 6; // WR* connected to pin 6
int EN = 7; // EN* connected to pin 7
int FLAG = 8; // FLAG connected to pin 8
int SELECT_ALL = 9; // SELECT_ALL connected to pin 9
int M1 = 10; // MUX1 connected to pin 10
int M2 = 11; // MUX2 connected to pin 11
int M3 = 12; // MUX3 connected to pin 12
void setup() {
// initialize digital pins:
pinMode(S0,OUTPUT); // set the pin A0 as output
pinMode(S1,OUTPUT); // set the pin A1 as output
pinMode(S2,OUTPUT); // set the pin A2 as output
pinMode(S3,OUTPUT); // set the pin A3 as output
pinMode(S4,OUTPUT); // set the pin A4 as output
pinMode(WR,OUTPUT); // set the pin WR* as output
pinMode(EN,OUTPUT); // set the pin EN* as output
pinMode(FLAG,INPUT); // set the pin FLAG as input
pinMode(SELECT_ALL,OUTPUT); // set the pin SELECT_ALL as output
pinMode(MUX1,OUTPUT); // set the pin MUX1 as output
pinMode(MUX2,OUTPUT); // set the pin MUX2 as output
pinMode(MUX3,OUTPUT); // set the pin MUX3 as output
digitalWrite(S0, LOW);
digitalWrite(S1, LOW);
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
digitalWrite(S4, LOW);
digitalWrite(WR, LOW);
digitalWrite(EN, LOW);
digitalWrite(SELECT_ALL, HIGH);
digitalWrite(MUX1, HIGH); // LOW means MUX1 selected
digitalWrite(MUX2, HIGH); // LOW means MUX2 selected
digitalWrite(MUX3, HIGH); // LOW means MUX3 selected
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
digitalWrite(MUX1, LOW);
Serial.print("MUX1 ON");
for(int i = 0; i < 24; i ++){
Serial.print("Value at channel ");
Serial.print(i);
Serial.print("is :");
Serial.print(readMux(i));
delay(1000);
//Serial.print(digitalRead(FLAG));
}
digitalWrite(MUX1, HIGH);
Serial.print("MUX1 OFF");
delay (1000);
digitalWrite(MUX2, LOW);
Serial.print("MUX2 ON");
for(int i = 0; i < 24; i ++){
Serial.print("Value at channel ");
Serial.print(i);
Serial.print("is :");
Serial.print(readMux(i));
delay(1000);
//Serial.print(digitalRead(FLAG));
}
digitalWrite(MUX2, HIGH);
Serial.print("MUX2 OFF");
delay (1000);
digitalWrite(MUX3, LOW);
Serial.print("MUX3 ON");
for(int i = 0; i < 24; i ++){
Serial.print("Value at channel ");
Serial.print(i);
Serial.print("is :");
Serial.print(readMux(i));
delay(1000);
//Serial.print(digitalRead(FLAG));
}
digitalWrite(MUX3, HIGH);
Serial.print("MUX3 OFF");
}
int readMux(int channel){
int controlPin[] = {S4, S3, S2, S1, S0};
int MuxChannel[24][5]={
{0,0,0,0,1}, //channel 0
{0,0,0,1,0}, //channel 1
{0,0,0,1,1}, //channel 2
{0,0,1,0,0}, //channel 3
{0,0,1,1,0}, //channel 4
{1,0,1,1,1}, //channel 5
{0,1,0,0,0}, //channel 6
{0,1,0,0,1}, //channel 7
{0,1,0,1,1}, //channel 8
{0,1,1,0,0}, //channel 9
{0,1,1,0,1}, //channel 10
{0,1,1,1,0}, //channel 11
{1,0,0,0,1}, //channel 12
{1,0,0,1,0}, //channel 13
{1,0,0,1,1}, //channel 14
{1,0,1,0,0}, //channel 15
{1,0,1,1,0}, //channel 16
{1,0,1,1,1}, //channel 17
{1,1,0,0,0}, //channel 18
{1,1,0,0,1}, //channel 19
{1,1,0,1,1}, //channel 20
{1,1,1,0,0}, //channel 21
{1,1,1,0,1}, //channel 22
{1,1,1,1,0} //channel 23
};
for(int i = 0; i < 5; i ++){
digitalWrite(controlPin[i], MuxChannel[channel][i]);
};
}
If you're using the Serial port, you can't use digital pins 0 and 1 as general purpose I/O.
You've declared M1, M2 and M3 - then you turn around in your code and use MUX1, MUX2 and MUX3. Which are not defined in your code. The compiler is picking up values for them from somewhere else.
For your own good, I advise you to learn from your program because it is a very good example of how NOT to program.
@shannonlee168
Please show a detailed connection diagram of your project.
Where this pins connected to multiplexers? The ADG732 has EN pin to enable the outputs, but it seems to me that you don't use EN pin.
Also your readMux() function is not looks correct - it read nothing from multiplexor. Moreover the function declared int, but doesn't have a return statement, therefore it's using inside the Serial.print() is perfectly useless.
Please show the full connection diagram, including the arduino, multiplexors, power lines etc... and show exact your connections and not a other's picture from the Net.
This say nothing
Addition
The pins 10,11,12 in your sketch are not working because your code not follow the ADG732 protocol. Did you read the ADG732 datasheet?
You can use a sourcecode of Arduino ADG732 library as an example of multiplexor control code.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
