\section{Measurement of inductance}
The measurement of inductance values will be done as separate part with all found resistors with
less than \(2100\Omega\).
The methode of measurement is based on the growing of current by formula \(Il~=~Imax~\cdot~(1~-~\exp{\frac{-t}{\tau}})\) 
after switching on the current.
The time constant \(\tau = \frac{L}{R}\) is proportional to the inductance~\(L\), but reverse proportional to the
resistor~\(R\). 
The current can only measured indirectly with the potential drop of a resistor.

Unfortunately the time constant will be reduced additionally by the relative high resistance \(680\Omega\),
for that the measurement of little inductance values is additionally made difficult with the \(8MHz\) clock.
To get the time constant, the voltage at the \(680\Omega\) resistor will be monitored by the analog
comparator.
If the voltage drop at the \(680\Omega\) resistor is higher than the voltage of the internal reference, this
event will be notified to the 16-bit counter, which is started at the same time of switching current on.
The counter will save the state of this event.
If the counter will overrun, this will be counted by the program.
After the event, the counter will be stopped by the program and the total time will be build with the saved
counter stage and the overflow counter.
The positive side of the coil will be switched from VCC to GND and hold in this stage until  monitoring 
of the voltages of both pins shows, that no current is detected.
The figure~\ref{fig:Inductance} shown a simplified diagram of the measurement situation.

\begin{figure}[H]
\centering
\includegraphics[]{../FIG/Inductance.eps}
\caption{Measurement of inductances with the comparator}
\label{fig:Inductance}
\end{figure}

With the supply voltage VCC and the sum of all resistors in the electric circuit the maximum current Imax and from
that the percentage of the reference voltage to the maximum voltage at the \(680\Omega\) resistor can be calculated
\(Umax~=~Imax~\cdot~(680~+~19)\) .
With the formula \(L~=~-\frac{t~\cdot~Rges}{\log{(1~-~\frac{Uref}{Umax})}}\) the inductance can be calculated.
The natural logarithm will be taken out of a build in table.
A inductance resolution of \(0.1mH\) is taken for this type of measurement.


In order to also measure lower inductance values, the \(680\Omega\) resistor will be omitted in the current loop,
if the resistance value of the inductor is measured with less than \(24\Omega\).
Only the output resistance of the port (\(19\Omega\)) will be used for measurement of the current.
In this special case the peak current will be greater than the value, that the specification of the ATmega allows.
Because this will be true only for a very short time, I expect no damage of the ATmega ports.
For this type of measurement a resolution of inductance of \(0.01mH\) is selected.
To avoid a longer time with excessive current, the additional measurement with delayed start of the counter will always be
done with the \(680\Omega\) resistor.
To get better fitting measurement results, a zero offset of 6 is subtract from the counter reading, 
if the measurement is done without the \(680\Omega\) resistor. Otherwise a zero offset of 7 or 8 is subtracted.


With great inductance values the parasitic capacity can cause a quick rise of current, so that the comparator
will responce inmmediately.
To get the value of the inductance anyway, the measurement will be repeated with a delayed start of the counter.
With this methode the voltage grow caused by the current increase of the inductor will be detected by the
analog comparator instead of the current peak of the parasitic capacity.
The measurements are always done in both current directions.
The program will select the higher result of measurement in the same current direction, but the
lower result of the different current direction as the displayed result.

\subsection{Results of the inductance measurements}
The figure~\ref{fig:Induct328p} shows the results of the measurement of different inductors.
The Inductors above \(1H\) are relays or primary sides of power transformers, for which
measurements are difficult because the iron core has residual remanence.


\begin{figure}[H]
\centering
\input{../GNU/induct328p}
\caption{Error of inductance measurement of 15 different ATmega}
\label{fig:Induct328p}
\end{figure}

\subsection{Measurement of small inductances with the sampling method}

The smallest detectable inductance is 0.01~mH with the normal measurement technique.
For high frequency application the measurement of smaller inductances is required.
The normal method use the speed of the current grow to measure the inductance.
This method can not be used for the sampling technique, because the measurement circuit
uses no additional resistors with the coil. The current will grow to forbidden high values
very fast. We can prevent a damage of the ATmega only with a very fast break of the current flow.
For the sampling method it is difficult to get this fast current turning-off and
additionally this critical process must be done many times in series.
For this reason the radio amateur Pieter-Tjerk (PA3FWM) has used another method to
get the inductance values.
Together with a parallel connected capacitor the inductor build a resonant circuit.
With a short current pulse this circuit begins to oscillate some times without further stimulation.
With the sampling method the frequency of this oscillation can be measured.
Because one side of the coil must be connected to GND level for this measurenent,
there are two problems with the measurement.
Once the negative voltage of the oscillation is limited by the internal protection diode
of the ATmega to about 0.6~V.  
For this reason the positive part of the oscillation will never reach a higher voltage
than 0.6~V too.
Additionally the ADC of the ATmega can only measure positiv voltage values.
Therefore all negative parts of the oscillation is read as zero.
Anyway could Pieter-Tjerk find a solution, to measure the resonant frequency with
a practical precision.
With the resonant frequency the inductance can be computed, if the capacity value is known.
For this reason the calibration program is extended with a capacity measurement for
later inductance measurement use.
The capacitor will be requested with the message '' \mbox{1 \electricC 3 \(10-30nF\)(L)}''.
A default value of 18~nF is preselected for the uncalibrated tester.
The value of the parallel capacitor for inductance measurement should be selected
rather high to get a low resonant frequency with small inductance values.
A capacitor with high quality like foil-type should be selected because
the quality factor of the resonant circuit is additionally measured by
monitoring the decrease of the amplitude.
With a high quality capacitor the total quality factor of the resonant circuit
is build by the quality factor of the coil.

There is no additional operation required with the parallel connected capacitor.
The resonant circuit is usually detected automatically.
When the resonant circuit is detected, the text "if" and the expected value
of the parallel capacity is written behind the inductance value in line 2.
In this case the resistance value of the coil is written at the end of line 1.
You should check the resistance value with a separate coil measurement without
the capacitor, because the resistance measurement of the resonant circuit often fail!
A additional output line shows the measured resonant frequency and the quality factor (Q=)
of the resonant circuit.

If there is no resonant circuit detected, the resistance value and the inductance is shown
in line 2.
When a resonant frequency of a single coil is detected, the frequency value and the
quality factor of the coil is also shown in a additional line.

For a air coil with 6 turns and a parallel connected capacitor with 18~nF
the sampling method get the following result:
\begin{verbatim}
272nH if 18.0nF
2256kHz Q=38.7
\end{verbatim}
This result was measured with a operation frequency of 8~MHz. A simular result
was also measured with a 25~cm long copper wire, which was formed to one big circle.
Probably smaller inductance values can be measured with a 16~MHz operation of the ATmega.

