//Copyright MRDare 2017 //Software free to use and modify for personal use and non commercial purposes float freq2, frequency,capacitance, mtmp; volatile unsigned long period, inductance, tmp; volatile unsigned t1ovf; // overflow register for t1. volatile unsigned int c,a=0,aint=0,tint=0,t1cnt1,t1cnt2; #define ledpin 13 #define capacitance 5.21E-6 //insert capacitance here. Currently using 5.21uF #define pi2 6.2832 //2*pi void setup(){ Serial.begin(9600); Serial.println("Inductance test"); //Serial.println(a); //a=0; DIDR1 = (1<1) { mtmp=period / 8; frequency=(1.E6/mtmp); freq2 = (pi2*frequency*pi2*frequency);// squared inductance = 1.E6/(capacitance*freq2);// value in microhenries if (inductance <1000){ Serial.print("Inductance "); Serial.print( inductance ); Serial.print("uH Frequency "); } else { Serial.print("Inductance "); mtmp = (float(inductance) / 1000); Serial.print(mtmp,2); Serial.print("mH Frequency "); } if (frequency > 1000){ frequency = frequency / 1000; Serial.print( frequency,3 ); Serial.print("KHz Period "); } else { Serial.print( frequency ); Serial.print("Hz Period "); } Serial.print(period>>3); Serial.println("uS"); delay(200); } } ISR(TIMER1_OVF_vect) //overflow interrupt vector { t1ovf++; //long time counts } //set comparator isr here ISR (ANALOG_COMP_vect) // { // process isr stuff here if (aint ==0){ TCNT1=0; digitalWrite(ledpin, HIGH); // sets the LED on digitalWrite(14, HIGH); // sets the LED on } aint++; if (aint >1){ c=TCNT1L; period=c+(TCNT1H<<8); ACSR = B00000010;//&= (0<