1613

Here is a small project that shows how to measure inductances and capacitances with a microcontroller and a few extra parts.

Measuring resonances

Various methods can be employed to measure inductance and capacitance; in this article we will use the resonance approach. This means that we use the device under test (DUT) to create an oscillator and then measure the frequency of the oscillator’s output signal. Because we know the oscillator’s characteristics it is possible to use this frequency calculate the inductance or capacitance value of the DUT.

Two oscillators and clever software is all we need

The oscillators are shown in the schematic below. There are two, one for inductance and one for capacitance. IC1.A and IC1.B together with Lx, C1 and C2 form a digital Colpitts oscillator. When the two capacitors have the same value, as they do here, the oscillating frequency is calculated as:

f = 1/(2π∙√(0.5∙Lx∙C))
 
We can work this equation around to obtain:

Lx = 1/(2∙π2∙f2∙C)
 
Because the frequency is a bit high when Lx is small, it is divided by 16 by IC2.A before being sent to the microcontroller.

Resistor R1 makes sure that the oscillator does not oscillate in the absence of Lx whereas P1 is available to calibrate the frequency with a known Lx.

The second oscillator is of the relaxation type. The frequency of this oscillator is given as:

f = 1/(2∙R4∙Cx∙ln(1+2∙R2/R3))
 
Swapping f and Cx gives:

Cx = 1/(2∙R4∙f∙ln(1+2∙R2/R3))
 
This equation is pretty precise but the switching levels of IC3.A do influence it. Even though it is powered from a symmetrical power supply this does not solve the problem completely. Luckily the software can compensate for this after calibration.
Rectifier D1 together with IC1.D ensure an output signal between 0 and 5 volts. The negative supply for IC3 is created by IC5, a popular voltage inverter IC.

The multiplexer built with IC4.A and IC4.B lets the MCU select the best capacitor test frequency for both a rapid response (the larger the capacitor value, the lower the frequency and thus a longer measurement period) and best precision. Those who prefer simplicity can leave IC4 off the board and strap its pins 1 and 2.

The software does the hard work

From here the MCU takes. It is programmed as an Arduino sketch making it easy for anyone to modify and play with. As is usual for a device with a nice user interface (UI), most of the program is dedicated to the UI. Displaying values with the right units, at the right position on the display; handling the rotary encoder and its integrated pushbutton, at least 80% of the programming effort ends up in the UI.

To measure the frequency produced by the DUT, the sketch uses the Arduino pulseIn function. This is a rather precise way of doing things as it returns values accurate to the microsecond. The inconvenience is that it is a blocking function, meaning that the MCU cannot do anything else while it is executing it. In our case this is not a problem, because the MCU doesn’t have to do anything else in the meantime.

Except in the case when COUT is measured directly, the signal has a theoretical 50% duty cycle due to the dividers IC2.A and IC2.B. Measuring only the pulse width therefore would be enough, but for better precision, and because things are never ideal, the signal period is measured too. The obtained frequency value, corrected for any division factors, is plugged into one of the equations (Lx or Cx) above and the value of the DUT comes out. It is that easy.

Build the LC meter

Finally, a word on assembling the LC meter. The add-on board is not very difficult to populate. The only thing to keep in mind is that K1 (optional) and K4 to K7 are to be mounted on the solder side of the board.

Also an assembled Platino is required (see below). Because the add-on board does not need K1 (it is there just in case), the board can also be used with an Arduino Uno. If you do, you will have to change the user interface, of course. Controlling the LC meter over a serial port is possible and would make for a good coding exercise.

A quick word about Platino

Platino is a universal circuit board for AVR microcontrollers in DIP28 or DIP40 packages. It can be equipped with user interface objects like pushbuttons, LEDs, buzzer, and displays. Everything, and we mean everything, about Platino can be found on the Elektor Labs website (see below) and on the GitHub repository of Elektor Labs.

Experience has shown us that Platino users find it hard to configure its solder jumpers. This is understandable, as there are many. This table shows the settings for this project. The Position column corresponds to the labels printed on Platino PCB version 150555-1 v1.4. Note that we recommend setting solder jumpers before mounting any parts.

And while we’re on the subject of parts: for this project we need a fully assembled Platino with a 28-pin MCU (ATmega328P-PU) — so no need for a 40-pin socket —, a 2x16 alphanumerical LCD with backlight, a rotary encoder with integrated pushbutton on position S5A or S5C (depending on your preference).

Click here for the Platino bill of materials.
 
Jumper Position Function
JP1 C PB4 is used by add-on board
JP2 - does not exist
JP3 C LCD backlight on PC5
JP4 C Rotary encoder A on PC0
JP5 C Rotary encoder B on PC1
JP6 C Rotary encoder pushbutton on PC2
JP7 C PB3 is used by add-on board
JP8 DIP28 PC6 is reset input
JP9 XTAL Use 16 MHz crystal
JP10 XTAL Use 16 MHz crystal
JP11 DIP28 ISP SCK on PB5
JP12 DIP28 ISP MISO on PB4
JP13 DIP28 ISP MOSI on PB3
JP14 B LED1 blue is standard Arduino LED
JP15 D LCD RS on PD2
JP16 D LCD E on PD3
 

Add-on board component List

Resistors
R1 = 47 kΩ
R2 = 4.7 kΩ
R3,R5 = 1 kΩ
R4 = 8.2 kΩ
R6 = 10 kΩ
P1 = 10 kΩ trimpot
 
Capacitors
C1,C2 = 27 nF, 5 mm pitch
C3,C4,C7 = 100 µF 50 V, 3.5 mm pitch
C5,C6,C8,C9 = 100 nF, 5 mm pitch
 
Semiconductors
D1 = 1N4148
D2 = 1N4007
IC1 = HEF4011
IC2 = SN74HC393
IC3 = LM393
IC4 = CD40676BE
IC5 = MAX660CPA+
 
Miscellaneous
LX, CX = 2-way terminal block, 3.5 mm pitch
K2 = 2-way terminal block, 5.08 mm pitch
K1 = 10-way (1x10) pinheader socket, 0.1" pitch (optional, mount on solder side)
K4,K5 = 8-way (1x8) pinheader socket, 0.1" pitch (mount on solder side)
K6,K7 = 6-way (1x6) pinheader socket, 0.1" pitch (mount on solder side)
Optional: 14-way DIL socket for IC1, IC2 & IC4
Optional: 8-way DIL socket for IC3 & IC5
PCB # 130341-1