Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Arduino based inductance meter - explanation?

Status
Not open for further replies.

boylesg

Advanced Member level 4
Joined
Jul 15, 2012
Messages
1,023
Helped
5
Reputation
10
Reaction score
6
Trophy points
1,318
Location
Epping, Victoria, Australia
Activity points
11,697
I am following this: https://electronoobs.com/eng_arduino_tut10_3.php

Using this code based on the authors code:
Code:
#include <Wire.h>

//13 is the input to the circuit (connects to 150ohm resistor), 11 is the comparator/op-amp output.
double frequency, capacitance, inductance;
uint32_t nPulse = 0;
void setup()
{
  Serial.begin(115200);
  pinMode(11, INPUT);
  pinMode(12, OUTPUT);
  delay(200);
}
void loop()
{
  digitalWrite(12, HIGH);
  delay(100);//give some time to charge inductor.
  digitalWrite(12,LOW);
  //delayMicroseconds(100); //make sure resination is measured
  nPulse = pulseIn(11,HIGH,5000);//returns 0 if timeout
  if(nPulse > 0){ //if a timeout did not occur and it took a reading:
    
    
  // #error insert your used capacitance value here. Currently using 2uF. Delete this line after that
  capacitance = 10.0; // - insert value here
  
  
  frequency = 1/(2*(float)nPulse);
  inductance = 1/(capacitance*frequency*frequency*4*3.14159*3.14159);//one of my profs told me just do squares like this

  //Serial print
  Serial.print("High for uS:");
  Serial.print( nPulse );
  Serial.print("\tfrequency kHz:");
  Serial.print( frequency * 1000);
  Serial.print("\tinductance uH:");
  Serial.println( inductance );
  delay(500);
        
  }
}

The circuit that the author specifies absolutely does not work - there is no response to the call to pulseIn(....)

However if a remove the connection from the bottom of the tank circuit to GND then there is a response to the call to pulseIn(....)

If I connect a 150R resistor between the tank circuit and GND then there is intermittent responses to pulseIn(....).

If I connect a 10k resistor between the tank circuit and GND then there is always a response to to pulseIn(....) but the pulse period, and therefore the calculated capacitance value, is unstable and varies widely between 0.01uH to 3uH (roughly) for a 10uH inductor.

If I connect a 1M resistor between the tank circuit and GND then there is always a response to to pulseIn(....) and the pulse period, and therefore the calculated capacitance value, is fairly stable and varies between 2uH to 10uH (roughly) for a 10uH inductor.

What is going on here?
 
Last edited:

The response AFTER the pulse has ended will only be a few (<10) cycles and they will rapidly shrink in amplitude. Adding anything in the ground of the tuned circuit will reduce it's 'Q' and make the ringing finish even faster. The circuit isn't very good and I wouldn't expect it to work with small inductances. As a guess, anything below about 2mH will not show at all because the diode and series resistor will be unable to charge the capacitors to any reasonable voltage that the comparator could reliably use.

This line "//delayMicroseconds(100); //make sure resination is measured" is wisely commented out as the entire measurement window might be finished before the delay ended!

The whole method of measuring a brief and decaying waveform is unreliable unless you have very controlled conditions, using an Arduino certainly doesn't fall into that category! Look at this design instead, it appears on many web sites with minor variations but it is reliable and far more accurate than the one you are trying : https://electronics-diy.com/lc_meter.php

Brian.
 

The response AFTER the pulse has ended will only be a few (<10) cycles and they will rapidly shrink in amplitude. Adding anything in the ground of the tuned circuit will reduce it's 'Q' and make the ringing finish even faster. The circuit isn't very good and I wouldn't expect it to work with small inductances. As a guess, anything below about 2mH will not show at all because the diode and series resistor will be unable to charge the capacitors to any reasonable voltage that the comparator could reliably use.

This line "//delayMicroseconds(100); //make sure resination is measured" is wisely commented out as the entire measurement window might be finished before the delay ended!

The whole method of measuring a brief and decaying waveform is unreliable unless you have very controlled conditions, using an Arduino certainly doesn't fall into that category! Look at this design instead, it appears on many web sites with minor variations but it is reliable and far more accurate than the one you are trying : https://electronics-diy.com/lc_meter.php

Brian.

Why do you even need to the link from tank to GND? It seems to ring nicely with it or with a high value resistor as the link.

I get the impression that the reason why this is unreliable is because microseconds on a low MHz cpu is rather imprecise?

When compared to milliseconds which is far more accurate on an Arduino.

I have seen the circuit you pointed out although I don't have any LM311 on hand.

I do have an XR-2209 - an unknown cap added to the timing cap of this will similarly change the frequnecy.

The trick is to get the same precision for low cap values at a frequency an Arduino can read.

Not sure how to do the inductance with an XR2209 though.

- - - Updated - - -

It would seem that, no matter which why you try it, there is simply no way of getting accuracy with inductance and capacitance with a 16MHz MCU.

You need at least nanosecond resolution which means at least a RPi.

Will have to content myself with the current approximate capacitance measurement using the time constant method and approximate inductance measurement with this method....hopefilly with some improvements if I can figure it out.
 
Last edited:

OK that's it - I am cured of this inductance circuit.

I can get capacitance measurements fairly reliably via time constant method and 3 charging resistors 10M, 10k and 100R.

But this comparator / ringing based circuit for inductance is impossibly unreliable.

I can get it to work with a mega and shield with a little bread board on it.

But there is no way in hell I can get it to work on an Uno soldered on to a little shield I made.

Checked all the soldering - found a broken connection and an unconnected pin but fixed them.

Multimeter shows similar measurments for all comparator pins on both the little bread board version and the soldered version.

And still one works and one wont with the same sketch.

Apparently there are too many variables that can upset this inductance scheme.

If I need to measure inductance think I will just buy the damn kit and have done with it - leave it t the experts iron out all the problems with tuned circuits!
 

Before going further, there is a variation of the LM311 on the internet that uses the internal comparator in the 16F628 instead of the external one, it makes the circuit even simpler.

The problem with the original design is it isn't an oscillator, all it does is 'kick' the LC circuit with a single pulse and hope it resonates for long enough to take a period measurement. An LC circuit with higher 'Q' will ring with higher amplitude and for longer so should be more reliable. If you add any resistance in the LC circuit you reduce the Q and instead of measuring the resonant frequency, you measure the tail end of it's own trigger pulse instead.

Brian.
 

Before going further, there is a variation of the LM311 on the internet that uses the internal comparator in the 16F628 instead of the external one, it makes the circuit even simpler.

The problem with the original design is it isn't an oscillator, all it does is 'kick' the LC circuit with a single pulse and hope it resonates for long enough to take a period measurement. An LC circuit with higher 'Q' will ring with higher amplitude and for longer so should be more reliable. If you add any resistance in the LC circuit you reduce the Q and instead of measuring the resonant frequency, you measure the tail end of it's own trigger pulse instead.

Brian.

Brian I am looking at the circuit you suggested: http://www.i1wqrlinkradio.com/antype/ch40/chiave135.htm and comparing it to this one Noname.jpg from the LM393 datasheet.

Essentially they do the same thing - generate a fixed frequency.

Now I can't simply swap an LM311 for a LM393 because, from my understanding now the author of your circuit will have fine tuned it to work with the LM311.

But the crystal in the circuit from the LM393 datasheet....does it really matter if it is a crystal in there or a CL tank circuit that resonates at 100kHz?

If so how would you go about connecting it in there?

If so then inserting an extra unknown cap or an extra unknown inductor will modify the frequency which I might be able to detect with an Arduino and essentially achieve the same result as the LM311 circuit.

I have some LM393s on hand.
 
Last edited:

This is the one I had in mind: https://www.electronics-lab.com/project/simple-lc-meter/

I think, but have not tried it, you can make it even simpler by substituting a 16F1847 and using it's internal oscillator.

Brian.
Applying a decade counter like CD4017 would increase the accuracy of measurements for an Arduino.

If you daisy chained a few together you could turn nanosecond pulse widths into a few to tens of microseconds which an arduino can do and therefore more easily attain a resolution of 1pF and 1nH?

I.E. Divide the pulse measured on the Arduino by 10 * the number of daisy chained CD5017s

The switching speed of these is in the MHz domain so it would have much effect on the measured pulse widths on the Arduino?

So Colpitts/Hartley oscillator -> comparator to produce square wave -> decade counter to expand pulse width to Arduino range.

Any merit Brian?
 

I'm getting muddled over which schematic you are talking about.

The original pulsed circuit relies on the pulse being very brief, the longer it is, the more the LC circuit is damped and therefore less likely to resonate. The critical timing is from the end of the trigger pulse to the start of measuring the ringing cycles.

Think of it's operation like this: the Arduino fires a small hammer at a tuning fork, a microphone hears the tone and the Arduino then measures it's frequency. From that it can tell the size of the fork. Substitute the LC for the tuning fork and the trigger pulse for the hammer. You can see that tapping the tuning fork with the hammer then removing it will make a tone but if you hold it against the fork it will absorb the resonant energy and silence it straight away.

What the circuit has to do is send a very short pulse to the LC circuit to make it 'ring', much in the same way as a tuning fork oscillates. The diode and resistor are an attempt (not a very good one!) to allow power to trigger the circuit but prevent it being drained back. A tuning fork has a very high 'Q' which is why it rings for several seconds but the oscillation from a typical LC circuit will decay within a few cycles (nS) which is why the Arduino has to measure very rapidly as the trigger pulse ceases.

Brian.
 

Simple oscillator using invert-gates (acting in bridged mode). The series LC has a particular resonant frequency. This is detected automatically by the circuit.

Logic gates contain a half-bridge driving the output terminal, like an op amp. Logic gates have high gain, resulting in 'snap-action'.

series LC oscill 2 invert-gates auto-detect resonant freq.png

I have played with this method in hardware. Experimentation is required, because LC arrangements are sometimes finicky to get oscillating. Try changing supply voltage, LC ratio, series resistance. Etc.

- - - Updated - - -

The resistor can be fewer ohms in than my simulation. Its purpose is to create a voltage that allows zero crossings to cause a change of state. In addition its purpose is to limit current to a few mA. If you were to construct a full H-bridge, then you could allow greater current to flow in the inductor, to test its capability in that manner.
 

Boylesg, I'm not sure what that schematic actually does or how it measures inductance. It seems to be two oscillators, the first driving a divider through an unbiased comparator and the second doing nothing useful at all.

Brad, It's certainly an oscillator but Boylesg is looking for a digital readout of inductance. Without further calculation based on frequency measurement it doesn't move us any further along. I think what he needs is something that you just connect an inductor across and it shows the value.
Incidentally that uses a MEGA328 MCU.
(sorry about the fur on the display - the cat is 'helping' me at the moment!)

Brian.
 

Boylesg, I'm not sure what that schematic actually does or how it measures inductance. It seems to be two oscillators, the first driving a divider through an unbiased comparator and the second doing nothing useful at all.

Brad, It's certainly an oscillator but Boylesg is looking for a digital readout of inductance. Without further calculation based on frequency measurement it doesn't move us any further along. I think what he needs is something that you just connect an inductor across and it shows the value.
Incidentally that uses a MEGA328 MCU.
(sorry about the fur on the display - the cat is 'helping' me at the moment!)

Brian.

Sorry Brian it is not the full circuit. Rather than going to an oscilloscope the last output of the last decade counter would go to an arduino pin that does the pulsePin(...) thing.

So instead of trying to measure a single pulse from the Hartley or Colpitts oscillators, the arduino measures the length of 10 or 20 pulses - divide by 10 or 20 in the arduino sketch to get the length of a single pulse.

I am getting the impression that micros() on arduino is not as accurate as millis() since it is only a 16MHz MCU? The smaller the difference in microseconds the less accuracy there is, apart from the fact that it is impossible to measure sub-microsecond time intervals which is necessary to measure very small values of capacitance and inductance.
Hartley oscillator (with added unknown inductor) for inductance measurement / Colpitt's oscillator (with unknown cap) for capacitance measurement. The best information re oscillating circuits is regarding these and apparently the caps/conductors need to be centre tapped in order for oscillation to occur, hence the reason for two separate oscillators for measuring inductance and capacitance. If you know of a way to measure both with one transistor circuit then I am listening.

You were saying that Arduino is far from controlled conditions for accurate measurement of inductance and capacitance via that ringing method. Is this part of the reason why that is the case? I.E. micros() not being as accurate as millis()
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top