Update on Inductance Meter

It seems I may have been incorrect with my math.  The resonant frequency from the formula for a damped oscillator I was using does not match the frequency the circuit rings at.  I did improve the code a little though, by using timer1 directly instead of micros().  This significantly improves the resolution of the measurement.


//this is based on a measurement technique from
//reibot.org, the parts count has been reduced by using the avr internal comparator

double pulse, frequency, capacitance, inductance;
bool detected = false;
long timeStamp[4];
unsigned int tcnt[4];
int sample = 0;

void setup(){
pinMode(11, INPUT);
pinMode(13, OUTPUT);
Serial.println("Why hello!");

//set up the comparator and the interrupts for it
ADCSRB = 0;           // (Disable) ACME: Analog Comparator Multiplexer Enable
  ACSR =  bit (ACI)     // (Clear) Analog Comparator Interrupt Flag
        | bit (ACIE)    // Analog Comparator Interrupt Enable
        | bit (ACIS1);  // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on falling edge) AIN0 is D6 AIN1 is D7 

//set up timer1 instead of using micros();
TCCR1A = 0; //this kills some PWM pins, but it allows timer1 to count all the way to 65535
TCCR1B = bit (CS10);

  timeStamp[sample] = micros();
  tcnt[sample] = TCNT1;
  if(sample < 3)
void loop(){
digitalWrite(13, HIGH);
delay(5);//give some time to charge inductor.

///comparator stuff here

pulse = 0;

 sample = 0;
 if(sample < 1)
  Serial.print("time out\n");
 pulse = (tcnt[1]-tcnt[0])/16.0;

//end comparator stuff
capacitance = 2.2E-6; //insert capacitance here im calibrating to a known inductor, the .95 is my fudge factor. 
frequency = 1.E6/(pulse);
inductance = 1./(capacitance*frequency*frequency*4.*3.14159*3.14159);
inductance *= 1E6; //note that this is the same as saying inductance = inductance*1E6
Serial.print("High for uS:");
Serial.print( pulse );
Serial.print("\tfrequency Hz:");
Serial.print( frequency );
Serial.print("\tinductance uH:");
Serial.println( inductance );

Leave a Reply

Your email address will not be published. Required fields are marked *