I am new to programming. I have one input signal from waveform generator. I am giving this signal to one sensor and as well as channel 1 of multiplexer. The sensor output is giving to channel 2 of multiplexer. If sensor output is low then I am using some amplification, the signal after amplification is giving to channel 3 of multiplexer. I am using switch case to select one of the input as output of the multiplexer. The multiplexer output is giving to external ADC and I am able to read ADC value.
My problem is I need both sensor input voltage and sensor output voltage for calculating impedance but I have written one function to read ADC values. Is there any possibility to get input and output voltage using same read ADC function and I have to use both voltage values later on. Or I have to write two different read ADC functions to read input and output voltage values. Any advice please.
I am using C language.
Edited: Hi, I am able to read different MUX channels. I am able to select first channel and reading ADC value and stored in a variable. If i change MUX channel to channel 2 and tried to read ADC and stored in another variable. But the problem is when i tried to read second channel, first time it is giving previous channel value and then if i read second time then it is giving second channel actual value. Can any one suggest me how to overcome this. I want to get the original value of that channel first time itself?
I have tried like this.
switch(c) {
case '1':
PORTB = 0x00;
SetWGFreq(arg);
Delay(1000);
mux1 = readADC();
printf("muxchanel 1 adc RawData:%d\r\n", mux1);
Command = 0;
break;
case '2':
PORTB = 0x04;
SetWGFreq(arg);
Delay(1000);
mux2 = readADC();
printf("muxchanel 2 ADC RawData:%d\r\n", mux2);
Command = 0;
break;
default:
Command = 0;
break;
}
But I have tried to print the ADC value out side the switch case. There it is changing at first time but when i tried to print within switch case I have to enter that case twice.
-
\$\begingroup\$ What do you mean by "input voltage" or "output voltage" ? It seams that "input voltage" is from the channel 1 of the MUX and "output voltage" from channel 2 or 3. \$\endgroup\$Blup1980– Blup19802012年10月22日 13:49:04 +00:00Commented Oct 22, 2012 at 13:49
-
\$\begingroup\$ I'm currently working with a multiplexer and a microcontroller, where i need to read the values of mux channel and i'm facing the same problem. So i wanted to ask if you were able to solve this issue, if so, how did you? with best regards Jeff \$\endgroup\$Jeff Spencer– Jeff Spencer2022年04月04日 08:26:06 +00:00Commented Apr 4, 2022 at 8:26
-
\$\begingroup\$ @JeffSpencer Do you see the answer below? It is marked green, so the OP thinks the issue is solved. -- You should take the tour to learn how this site works. It is not a forum. \$\endgroup\$the busybee– the busybee2022年04月06日 10:31:40 +00:00Commented Apr 6, 2022 at 10:31
1 Answer 1
You should select channel 1 of you MUX. read one value using the read function. Store it in a variable. Then switch your MUX to channel 2. Read the value using the same ADC read function and store it in another variable. Then you can do the computation using the value stored into the first and second variable. That's it.
-
\$\begingroup\$ I have tried as you said but, I have read adc function like this "adc=AD7798_16(0x58, 0xFFFF);" then I am storing the adc value in variable "In_voltage" then when I change channel and read ADC and storing in "out_voltage". But my problem is both variables updating with same value. \$\endgroup\$verendra– verendra2012年10月22日 14:08:14 +00:00Commented Oct 22, 2012 at 14:08
-
\$\begingroup\$ @verendra so can you simply make a second variable or I may missing the whole point? \$\endgroup\$kenny– kenny2012年10月22日 14:13:11 +00:00Commented Oct 22, 2012 at 14:13
-
\$\begingroup\$ How quickly in time after you switch the MUX channel are you invoking the ADC read routine. The MUX to ADC input will have some settling time based upon the capacitance in the circuit modes. You may have to delay between MUX change and the ADC reading. \$\endgroup\$Michael Karas– Michael Karas2012年10月22日 15:21:07 +00:00Commented Oct 22, 2012 at 15:21
-
\$\begingroup\$ @verendra - Have you validated and gained confidence in your A/D reading routine? Call it repeatedly on one MUX channel with a varying voltage and see the output of your routine change? You should do this before going off to work with two MUX channels because there could be a bug in your routine. \$\endgroup\$Michael Karas– Michael Karas2012年10月22日 15:24:34 +00:00Commented Oct 22, 2012 at 15:24