problems in data measurement

Hi,

Just a brief of the project I am working on. I am trying to connect inductors in circular array which are connected to two MUX acting as a transmitter and receiver which is controlled by arduino UNO. The MUX i am using is ADG508A (data sheet attached, schematics attached). I have written the coding, but i feel it is not working well with the MUX. I will explain the algorithm and put the code in after it.

The example of how my mux's should work is

Transmitter MUX Selection pin 1(selected): the signal goes to the inductor of value 220uH, The other inductors get induced by the signal, and the receiver mux from selection pin 2 should be selected and the value to written on the serial monitor. then the receiver should go for the selection pin 3 and write it down, like wise till the Selection pin 8.

So, it's like this

Output should be like below, only receiver voltage is measured.

transmitter 1 - Receiver 2 3 4 5 6 7 8
transmitter 2 - receiver 3 4 5 6 7 8
TX 3 - RX 4 5 6 7 8
TX 4 - RX 5 6 7 8
TX 5 - RX 6 7 8
TX 6 - RX 7 8
TX 7 - RX 8
TX 8 - none

Should follow n(n-1)/2

        for(count=0;count<=7;count++)
   {
      i = pin[count];
      a0 = bitRead(i,0);
      a1 = bitRead(i,1);
      a2 = bitRead(i,2);
    
      digitalWrite( 3,a0);
      digitalWrite( 5,a1);
      digitalWrite( 6,a2);
      delay(3000);
      
     }

        while(i==pin[count])
        {
  
         for(count1=count+1;count1<=7;count1++)
          {
          i = pin[count1];
          a00 = bitRead(i,0);
          a11 = bitRead(i,1);
          a22 = bitRead(i,2);
    
          digitalWrite( 6,a00);
          digitalWrite( 7,a11);
          digitalWrite( 8,a22);
          delay(2);
         
    
          }
    
        }
    
    }

Since this code didn't work with the MUX i went for the analogWrite command which has a similar programming

  int a0_LH[] = {0, 255, 0, 255, 0, 255, 0, 255};
  int a1_LH[] = {0, 0, 0, 0, 255, 255, 255, 255};
  int a2_LH[] = {0, 0, 0, 0, 255, 255, 255, 255};
  for(i=0;i<=7;i++) 
  {

  a0 = a0_LH[i];
  a1 = a1_LH[i];
  a2 = a2_LH[i];
  
 analogWrite(3, a0);
 analogWrite(5 ,a1);
 analogWrite(6 ,a2);
 delay(80);
 
 if (i==i)
   for(i1=i+1;i1<=7;i1++)
     {
       int a3_LH[] = {0, 255, 0, 255, 0, 255, 0, 255};
       int a4_LH[] = {0, 0, 0, 0, 255, 255, 255, 255};
       int a5_LH[] = {0, 0, 0, 0, 255, 255, 255, 255};
       a3 = a3_LH[i1];
       a4 = a4_LH[i1];
       a5 = a5_LH[i1];
       
       analogWrite(9,a3);
       analogWrite(10,a4);
       analogWrite(11,a5);
          //analogReference(INTERNAL);
        
        Val = analogRead(analogPin); 
        Serial.println( Val);   // prints the values in volts
        delay(10);
     
  }
  
   
  }

This program makes 4 of the selection pins work [s1,s2,s7,s8] and the remaining 4 doesn't work [s3- s8].

Please kindly help to figure out where I have done the mistake. Is it my logic is wrong or my understanding of the MUX and arduino?

TXRXMUXREVA.pdf (18.3 KB)

ADG508A_509A.pdf (381 KB)

What signal are you feeding to the coils? Arduino may have problems reading the voltage levels from the coils without rectification and filtration if it is AC as I guess.
From your code the statement if(i==i) is always true
There are probably better ways to do it; but in the mean time this may help you. At least it compiles. This is from what I interpret from your question on how to drive the multiplexers.

Good luck,

//pins 10,11,12 for TX
//pins 7,8,9 for RX
int MaxCoils=8;
int YourReadPin=0;
int YourDelay=10;
int YourOtherDelayIfYouNeed=20;

void setup()
{
 for (int k=7;k<13;k++)
{
  pinMode(k,OUTPUT);
} 
 Serial.begin(9600); 
}

void loop()
{
for (int i=0;i<MaxCoils;i++)
{
WriteTXActivationCode(i);
for(int j=i+1;j<MaxCoils;j++)
{
 WriteRXActivationCode(j);
 int Val=analogRead(YourReadPin);
 Serial.println(Val);
}
delay(YourDelay);
}
delay(YourOtherDelayIfYouNeed);
}

void WriteTXActivationCode(int i)
{
  if(i<4)
  {
  digitalWrite(10,LOW);
  }
  else
  {
  digitalWrite(10,HIGH);
  }
  
  if(i==0|i==1|i==4|i==5)
  {
  digitalWrite(11,LOW); 
  }
  else
  {
  digitalWrite(11,HIGH);   
  }
 
  if(i=0|i==2|i==4|i==6)
  {
  digitalWrite(12,LOW);
  }
  else
  {
  digitalWrite(12,HIGH);
  }   
}

void WriteRXActivationCode(int j)
{
   if(j<4)
  {
  digitalWrite(7,LOW);
  }
  else
  {
  digitalWrite(7,HIGH);
  }
  
  if(j==1|j==4|j==5)
  {
  digitalWrite(8,LOW); 
  }
  else
  {
  digitalWrite(8,HIGH);   
  }
 
  if(j==2|j==4|j==6)
  {
  digitalWrite(9,LOW);
  }
  else
  {
  digitalWrite(9,HIGH);
  }   
}

By the way, you should have continued with your previous posting
AC Signal data acquisition using Arduino - Science and Measurement - Arduino Forum which I have not seen till now and not starting a new one.

hi arduinoadrian,

Thanks for your help.

Let me give you more explanation on the topic, I am sending AC signals generated by DDS chip and amplify it by 5 times and send a AC voltage of 2.4V at the frequency of 20KHz to the inductors of value 220uH via MUX and the induced voltage at the other inductors are received via mux and transmitted to an Instrumentation amplifier and then a rectifier circuit and the output is read by the arduino.

I tried to use your coding, and I got the same errors when I was doing with my own coding as well.

The error is when transmitter 1 transmitting signal for all of - Receiver 2 3 4 5 6 7 8, to be read and printed. But the transmitter is not transmitting for the entire period and the receiver reads transmitter 1 signal and send them out as well. Using for loop, causes this. So I tried an experiment where no for loop is there but the variable 'i' is used to write control signals to MUX.

like this doing below:

int i=0; // TX 1 
{
WriteTXActivationCode(i);

for(int j=i+1;j<8;j++)
{
 WriteRXActivationCode(j);
 int Val=analogRead(analogPin);
 Serial.println(Val);
 
}
delay(2000);

}

using this I was able to keep the transmitting signal to be transmitting for the entire loop of the receivers.

but if I use this coding below

for (int i=0;i<MaxCoils;i++)
{
WriteTXActivationCode(i);
for(int j=i+1;j<MaxCoils;j++)
{
 WriteRXActivationCode(j);
 int Val=analogRead(YourReadPin);
 Serial.println(Val);
}
delay(2000);
}
delay(3000);
}

the transmitting signal does not stay for the entire period for the receiving signals. which is why I tried to use a conditional statement in between to keep the transmitting signal to be ON for the entire period which did not work well as i thought.

here's another code I tried, but the same error results.

   for(count=0;count<=7;count++)
   {
      i = pin[count];

      a0 = bitRead(i,0);
      a1 = bitRead(i,1);
      a2 = bitRead(i,2);
    
      digitalWrite( 3,a0);
      digitalWrite( 5,a1);
      digitalWrite( 6,a2);
      delay(3000);
      
     }

        while(i==pin[count])
        {
  
         for(count1=count+1;count1<=7;count1++)
          {
          i = pin[count1];
          a00 = bitRead(i,0);
          a11 = bitRead(i,1);
          a22 = bitRead(i,2);
    
          digitalWrite( 6,a00);
          digitalWrite( 7,a11);
          digitalWrite( 8,a22);
          delay(2);
         
    
          }
    
        }
    
    }

i wrote the above coding thinking that the transmitting sensor will be transmitting for the entire receiving period, using the while statement. It also produces the same error.

Can you please help me to find where I am going wrong?

thanks

Hi:
Please double check your connections correspond to the pins you are driving from the code. The instance i==0 corresponds to (LOW, LOW, LOW) for your mux which means none of the TX outputs is active and maybe that's why it works there and not with other instances of i++. Remember I set my own pins for TX which may not have been the same you were using. Another reason for the problem could be the definition of the TX pins Mode in the setup. If I get any other ideas I'll let you know. Please post your results.

Since you have enough memory left (or I guess so) you can try to run the code step by step as we use to do with the Z80 and others back in the day and check the results.

Simply repeat the same thing for several instances of i.

int i=0; // TX 1 
{
WriteTXActivationCode(i);
for(int j=i+1;j<8;j++)
{
 WriteRXActivationCode(j);
 int Val=analogRead(analogPin);
 Serial.println(Val); 
}
delay(2000);

int i=1; // TX 2 
{
WriteTXActivationCode(i);
for(int j=i+1;j<8;j++)
{
 WriteRXActivationCode(j);
 int Val=analogRead(analogPin);
 Serial.println(Val);
}
delay(2000);
// and so on...

HI,

Really , Thank you.

I managed to solve the issue on my own. But you were right on the mark, the signal was i=0 instead of i==0; and also I found that the rest of my coding were working properly too.

Managed to get 28 outputs for the 8 sensors the lowest being 0.02mV and the highest 0.5mV -> this value must be an error. this is too big compared to the other max signals.

Now, I need to use a large gain to amplify the signals and rectify it and feed it to the Arduino. But, i want to go step by step from amplification then rectification and then reading the output.

Since I know arduino adc only reads 0 - 5 V and using 100,000 gain [ not sure if i can do this] to multiply the signals, if i do, the highest output from the sensor goes to 50V and that will harm the arduino.

I am using Instrumentation amplifier[AD8226] for high gain of 1000 which means i will get the lowest value as 0.02V and the Highest 0.5V .These values are really low to be rectified using 1n4007 as it requires 0.7 Volts for forward biased conduction.

I think that a second stage amplification is needed for rectification. Will try to experiment it.

If you think or feel I might be doing something wrong, kindly correct me.

I wish I can think first and do it rather than do it and think later.....

Glad you solved the problem and the code worked.
Check these subjects:
-Precision rectifier
-Input protection diodes.

Since I know arduino adc only reads 0 - 5 V and using 100,000 gain [ not sure if i can do this] to multiply the signals, if i do, the highest output from the sensor goes to 50V and that will harm the arduino.

Then you don't need 100000 you need only 10000 to get the 5V you want and not 50.
Check the datasheet of your instrumentation amp to see if the gain can be set to 10000. I'm using right now an AD620 with a gain of 2000 with no problems. On it, the gain can be set to 10000 according to the manufacturer.
For the precision rectifier if you are concern about temp dependency of your whole system transfer function select a low offset temp drift opamp and low temp coefficient resistors. Correcting temp drifts later on will be time consuming and can get pretty ugly.
I still don't understand why you are getting such low voltages with a gain of 1000 already and how could you read them without a precision rectifier??? But I'm not there.
-Are your TX and RX too apart from each other?
-Do the RX coils have enough turns?
-Are you feeding the right power to the TX coils?
-Are the frequencies correct?
With such low voltages and coils as pick ups, if you are anywhere near public broadcasting stations frequencies and/or distances you will have problems isolating your signal from the interference from theirs. Its always better to have a strong clean transducer signal than having to amplify it too much to keep the S/N ratio under control. Maybe you can improve your transducer performance somehow and get a stronger signal so you don't need to amplify that much.

I wish I can think first and do it rather than do it and think later.....

That's common occurrence for many of us, including myself. The reason being lack of patience... That condition improves a bit as you get older though.

I will check on those topics.

I measure the voltages using the oscilloscope for the time being. The values that I wrote was with a gain of 8.15. After posting this
I increased the gain to 1052 and now getting the values as 0.15 V the lowest [0.02mV previous] and 1.5 V [0.24mV] the highest but there is an error which reads one of the peaks to be 5.8V. The reason I am saying this induced voltage as an error because all 8 inductors are of the same value 220uH inductance. So when a near by transmitter is sending a high signal, the voltage received by all others are of 1.5 V except this one.

The inductors are arrange in a circular formation of diameter 32mm and at a distance of 0.5cm from each other. Well, the closest position to each other. I will upload a picture after this post.

After comparing the outputs for both gains, i feel something is wrong. from the gain of 8.15, the lowest value is 0.02mV or 20 micro volts but after a gain of 1052 it just went upto 0.15 volts or 150 milli volts. Is this right?

In theoretical calculations it should be in milli volts. But the practical value I am reading from oscilloscope is in volts much higher than my calculated theoretical values.

So let me answer your questions,

  • TX and RX are of same number of turns and has same inductance of 220uH placed between 4mm or lesser in a circle of 32mm.
  • I am feeding the coils AC voltage of 2.4 volts at frequency 20KHz, but the coils are producing the output of 0.8Volts at 20KHz.
    to be honest, I need to understand this part as well. I can see this reduction in the voltage is due to the impedance of the inductor, but not sure how to calculate it.
  • The frequencies seem to be right between the input and the output.

yeah, I really need to understand my circuits first.

Thanks again.

From the AD8226 you are using datasheet page 12: http://www.analog.com/static/imported-files/data_sheets/AD8226.pdf

With a gain of 1052 ( aprox. 60 dB), If you look at the Graphs (Fig. 25, Fig.26), no matter what Power Supply Voltages are you using, the cutoff freq is way lower than your operating freq of 20KHz. Probably, the reason why you are not getting a linear increase in the output voltage when you increase the Gain to 1052 as you were expecting (It falls in the slope of the Graph).

Possible solution:
-Divide the Gain into multiple stages.

Additionally, check the subject Slew Rate.
You may also be out of range of the device max slew rate (I don't know) and getting a triangular wave at the output not linearly following the input. This is common occurrence when the gain is taken too high and the freq is too high to do that. I haven't checked that in your case; but you need to check it as well and confirm the slew rate is right in your case.

I think you are taking the device off limits in this application.

To avoid some head aches, I would try to do this:
-Try to find a different approach and a different sensor, if possible. Its difficult to believe there is only one possible method to measure what you are trying to accomplish; but I don't know what it is.
-If the coils method is the best option:
Decrease the freq to about 10-15KHz and use a HiFi audio amp (in case the oscillator-driver you are using can't do it) to put more power on the TX coils, 10V for example, That will give a higher induced voltage at the receivers, needing less amplification and making it more immune to noise.That's if the coils can take it without burning, overheating or core saturation. Take the voltage as high as possible without undesirable effects. Careful though as that my produce unacceptable EMI radiation.
-Use caps to tune the thing and make an LC tank (f=1/2PI
sqrt(LC)). That will help filter out undesirable harmonics and reduce distortions and EMI radiation. Same goes for the RX coils to help filtering RF interference.
*Define the temp range you expect for the device to operate without significant change in the readings at the output. Once you have that, make sure to select the gain resistor with a temp coefficient capable of that, so it will not change the gain with temp inside that range. The same applies to the offset voltage temp drift of any other amps you may need and any other resistors affecting the total gain.
Keep the gain of any amp stage under 10 or whatever the product GainBandwith limit for the particular device dictates for the operating freq selected. Check the device datasheet for that similar to the previous post. Spread the overall gain into several stages. Too much gain increases the chances of building an oscillator instead.
*Use the manufacturer's recommended filtration caps on power supplies rails next to the actual opamps or any other places you may need including the input. *Use ferrite cores and make a couple of turns trough them with the power supplies wires feeding the amps at least in the prototyping phase. If not enough and noise persists, place ferrite core coils in series with the power supply wires feeding the amps.
*Use shielded wires to send the coils signal to the amp. Place the amp as close as possible to the coils.
*Make sure the multiplexers can handle the freq in use ( I don't know, never used them).
*Follow ground distribution recommendations from the manufacturer of the Instrumentation Amp.
*If noise is persistent, enclose the amps board in a grounded metal box.
*Use a precision rectifier at the output (if required as there maybe enough voltage already to use simple diodes) and build the right low pass filter to average the envelope of the rectified signal with the right time constant for the application. Check AM Demodulation subject, as I think AM modulation of your 20KHz carrier from the measured variable, is what you get at the end of the day with your sensor approach. The low pass filter must be designed to filter out the carrier freq and keep the envelope which is your original signal.
-Consider using a high quality Audio preamplifier as your first stage, instead of the instrumentation Amp. Similar to the ones used as Needle Preamps in old vinyl record players or a simple Mic Preamp. You will need to reduce the band width though to reduce noise and most likely correct the freq response. If I recall well, their band pass wasn't flat to compensate for freq response problems in the needles or mics. You can build your own using LM382 or similar. Beware when setting the band pass it can not be a super High Quality (Q) filter that excludes useful freq components of your original variable signal (the one you are sensing). The bandwidth if its AM modulation (as I suspect) has to be at least twice your original variable signal max freq and centered to the carrier you use.

I don't know what else could help you. If any thing else comes to my mind I'll let you know.

HI,

Multiple amplifier stages worked really great. :slight_smile:

Precision rectifier :
The next one I tried is the precision rectifier cirucit, which does not seem to be working at all. The output I am receiveing is AC signal which are amplitude reduced. I am using a 1N4007 diode and from my observation from the outputs, their amplitudes are reduced 0.7Volts on both positive and negative cycles of the AC signal. I used the circuits in the following link

Rectifier on its own:
So, since the amplifier stage didn't work I tried with the DDS chip[AD9833] I am using, The result was still the same, got an AC signal. Since the output from the DDS is always 0.63 volt with 20KHz frequency, probably diode didn't receive enough voltage for forward biasing.
So, I connected the diode to the op-amp amplifying the DDS voltage with gain 4. and the result was an ac signal amplitude reduced by 0.7 volts on both sides of the wave.

I don't understand why there is an AC signal after a diode. It should be either a half wave rectified signal or the same input signal.

Next, I am planning to connect the precision rectifier to the above stage. So to see if there is any change in the output at all.

If you understand why there is an AC signal at the rectifier output, kindly explain it to me.

Thank you.

The next one I tried is the precision rectifier cirucit, which does not seem to be working at all. The output I am receiveing is AC signal which are amplitude reduced. I am using a 1N4007 diode and from my observation from the outputs, their amplitudes are reduced 0.7Volts on both positive and negative cycles of the AC signal. I used the circuits in the following link

In order to attempt finding the reason for that, could you please post the schematic of the actual circuit you have built, including the part number for the OpAmp you have used?.
Normally, for such low current applications the 1N4148 diode is more frequently used.

hi,

I have attached the precision rectifier schematics and also the last stage buffer amplifier schematics.

I also thought that the diode might be the case for the precision rectifier not working, So i changed the diodes to 1n914. This did work yesterday,well almost, a few of the AC signals were not rectified and the output was in millivolts.

Since the arduino can't read millivolts I used a buffer amplifier with gain 4 and made it to read the voltages, a few signals were not read and some were zero and there was a huge difference between the output read at the oscilloscope and the serial monitor, it might be due to the addition of amplifier at the last stage or it might be due to the delays given in the coding. Not sure which is the reason, I might need to use another diode to check if there is a different out come.

I will post if there has been any improvements.

Thank you very much again.

precision rectifier.sch (123 KB)

laststagebufferamplifier..sch (41 KB)

I can't open the files format you used. I'm an antiquated computer user, so please just use a different file type like a simple picture file jpg or png if possible. PDF format is also OK.

Sorry about that.

Should have attached the PDF files the first time.

The files are attached. After this amplifier stage I tried to connect the output from the amplifier to the Arduino adc and opened the serial monitor, compared the observing values in oscilloscope and serial monitor in the arduino, some of the values are not matching. This led me to think may be the rectifier is not working properly or might be something wrong with the capacitor attached to the filter circuit.

When the values are observed in the oscilloscope, they are coming in the U shaped, means for every signal transmitted the result will be in U shaped. I will provide an data of those after i take few more readings this afternoon.

I also tried using analog reference voltage from 1 -3 volts using a voltage divider circuit, but that was not useful. It ended up producing more abnormal values.

I think I need to learn more on this data acquisition circuits.

I thank you again for your guidance.

precision rectifier.pdf (16.2 KB)

laststagebufferamplifier..pdf (13.9 KB)

-The OP37E is an excellent choice. BTW, check pages 13 and 14 of its datasheet http://www.analog.com/static/imported-files/data_sheets/OP37.pdf for the Phono and Mic preamps configurations mentioned before. I still think that's a better choice than the Instrumentation Amp config you are using in this particular case. The reasons for that are the high freq and gain levels you are using.
-Consider using another OP37E instead of the LM741P. Although I can't find the datasheet for the P version you are using, I suspect, it might introduce more noise and its temp offset drift is probably higher and that will cause problems as explained before. What you are trying to build is uncommonly difficult and requires extreme care and attention to details. If you don't follow already known procedures and techniques you won't get acceptable results.
-I think there is no need for a buffer last stage unless the voltage level is too low; but having so many stages already that's difficult to accept if everything was done right. The low pass filter stage to recover the signal envelope acts as a buffer already. Adding another stage introduces more noise and problems. If there is not enough voltage try to increase the gain of that and previous stages with care not to surpass the Gain Bandwith product and slew rate as advised before. The more active components the more noise is introduced and the more problems are added. Plus added cost
-The 10pF cap used apparently is not right . According to f=1/2PIxRxC, with R=47K and c=10pF the cutoff freq should be 1/(2xPIx47x10^(3)x10^(-11))=1/(2xPIx47x10^(-8))~344KHz that's way above the 20KHz carrier and the cutoff freq. must be way below it for correctly detecting the envelope by averaging and properly measure the voltage. The filter is simply not filtering and the 20KHz half wave carrier is passing through. Arduino is sampling the non averaged signal and since there is no sync between it and the Arduino sampling rate, it gets the reading at any point of the "rectified signal" and therefore the readings are erratic. There could be other problems though, like the amplitude actually getting to Arduino, noise, bad rectification, etc. But lets begin by fixing that. Double check my calculations for accuracy please. I did it quickly and they may be wrong.
-Please post a picture of the "U shaped waveform" you are getting? Sounds like a clear indication of distortion taking place along the signal path. Troubleshoot with the scope by measuring the signal at different points in its path, that is, at all amplifier stages inputs and outputs and check where that distortion begins to appear. That's the stage introducing it. Must be revised then.
-Please post scope screen pics of the signal waveforms at inputs and outputs where you think there is a problem.

Hi,

Thanks for the guidances,

The precision rectifier has stopped working, I need to get some diodes for it to work. Played with it in the morning and now it stopped. [Me and my hands]

The U shaped curve is obtained by the plotting of the observed values on a graph, sorry if I made you misunderstand that it is appearing on the scope. Its the values of the receiver for each transmitter inductor.

I need to understand a lot about my design and circuit. As you said, Its really difficult, and even a minor mistakes in the circuit stops it from working.

The output voltage coming from the filter circuit is really less and when fed into arduino nothing other than 0 appears on the screen. So, I had to amplify it at the end.

will update on this tomorrow.

Thank you.

I suggest this:
-Take a couple of days of break from the build up and go to the library with your circuits on hand, carefully read the postings and deeply study the subjects recommended. Compare what you learn with what you have actually built. When you have a better picture of the possible mistakes and only then return to the lab to continue with the build up. I honestly have told you everything I consider necessary for your approach to succeed to the best of my knowledge and experience.
-Talk to your project tutor and request some onsite help also. Its hard to figure out the details from reading posts. From short distance, he will have better clues than me.

Hi,

Thanks for all your help. I made it work. But most the times the arduino adc is not working well. Most of the times it gets burned.

Now i am trying to improve the current being sent to the inductor, I am not sure how i can send more current to it. There is a multiplexer stage in-between the sensor and the frequency generator and if i send more than 20 mA current to the multiplexer it will definitely get burned. So clearly I need to send it afterwards.

Currently I am sending ac 10V at 20KHz frequency to my inductor but i want to send 1 Amp current or more to it. how can i Possibly send more ?

Also one more thing i need to ask. I have a inductor of value 220microHenry. I am supplying 10V at 20KHz frequency. The voltage drop across the inductor to 4V. I calculated using different formulas but none of them seems to be correct.
Voltage drop across the inductor = AC voltage / Inductor. => VL = Vac / L
And not sure how to calculate the change in current.

want to seriously improve my knowledge, please help me out.

Thanks