-1
\$\begingroup\$

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;  
                                        defalut:
                                            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.

\$\endgroup\$
  • \$\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 Oct 22 '12 at 13:49
0
\$\begingroup\$

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.

\$\endgroup\$
  • \$\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 Oct 22 '12 at 14:08
  • \$\begingroup\$ @verendra so can you simply make a second variable or I may missing the whole point? \$\endgroup\$ – kenny Oct 22 '12 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 Oct 22 '12 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 Oct 22 '12 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.