You are on page 1of 5

# Constructional Project

PIC
LCF METER
JOHN BECKER
Simple monitoring of inductance, Using this formula, if any two values are
capacitance and frequency values known, the third can be readily calculated.
For instance, if C and F are known, then L
can be calculated using the formula:

T
HIS simple PIC-based unit was
designed to measure and display the
values of inductors and capacitors. L=
( 2 × p1 × F) 2

As a by-product of the technique used, it C
can also display the frequency of an exter- Similarly, using the capacitance-resis-
nal 0V/+5V signal source. tance oscillator configuration shown in
The ranges are approximately: Fig.2, the output frequency can be calcu-
Capacitance: 1pF to 6500mF lated for known values of R and C. Several
Inductance: 1mH to 10H formulae exist for this calculation and the
Frequency: 0·05Hz to 5MHz Fig.1. A basic inductance and capaci- one used in this application is:
tance (LC) oscillator.
OSCILLATOR F=
1
p×R×C
CONCEPTS
The design is based upon the concept One technique for using an inductor in a
that oscillators can be constructed from CMOS oscillator circuit is that shown in from which the value for C can be calcu-
CMOS NAND gates or inverters, and that Fig.1. Here the oscillation frequency is lated if R and F are known:
their oscillation frequency depends on the determined by the formula:
1
values of inductance, capacitance and C=
F=
1 p×R×F
resistance in their feedback paths. The
principles were discussed by George 2 × p × Ö(L × C)
Hylton in his two-part series Logic Gate where:
Inverter Oscillators of Sept/Oct ’02.
Using a suitable microcontroller, such F = frequency
as one from the PIC16F62x or PIC16F87x C1 × C2
families, software can read the frequency C=
C1 + C2
of an oscillator and calculate the value of
an unknown component if the values of the L = inductance
other components are known. In this p = 22/7
design, a PIC16F628 is used and the Fig.2. A basic capacitance and resis-
results are output to an alphanumeric liq- tance (CR) oscillator.
uid crystal display (l.c.d.).
FREQUENCY TO PIC
Referring to the full circuit diagram for
the PIC LCF Meter in Fig.3, two indepen-
dent oscillators are used, one based on
inductance and capacitance (LC) values,
the other on capacitance and resistance
(CR) values.
The LC oscillator is formed around
NAND gate IC3a. The inductance is pro-
vided by inductor L1, used in series with
the external inductor whose value needs to
be measured. The external inductor is con-
nected across probe clips P1 and P2 and
switched into circuit by rotary switch S2 in
position 1. The capacitance is provided by
capacitors C5a, C5b, C6a and C6b.
Two pairs of capacitors are used so that
the value of C in the LC formula is simple
for the software to process. The values for
each of the four capacitors is set at 10nF.
92 Everyday Practical Electronics, February 2004

Therefore the parallel value of C5a/b = is basically set by resistor R4 and capacitor The CR oscillator is similarly controlled. there is no conflict of fre- effect of providing a degree of frequency ten times the value of R4 and is ignored in the quencies passing through IC3d. The maxi. Conversely. IC1. its frequency is passed through the signal being fed back through the from 1pF upwards. jointly fed to the inputs of NAND gate pal purpose is to ensure that oscillation Because the reference value has been set IC3d. As with L1. Everyday Practical Electronics. typically oscillating. IC3a input pin 12 is taken high by PIC pin and input rates in excess of 5MHz can be The CR oscillator is formed around RA0. Fig. In this circuit it has been chosen to be at any time. latter provides a minimum inductance allows the oscillators to be selectively value against which the circuit is “nulled” turned on and off by the PIC microcon. FREQUENCY CAPTURE prior to taking measurements. IC3d via pin 8 since pin 9 is now held high inductor than the output of the gate itself It should be noted that the value of resistor by IC3a’s output pin 11. the oscillator stops with IC3b output 10nF. R3 also has an effect on the oscillation fre. The external capacitor whose value is PIC pin RA1 when high allows the IC3b/c standard capacitor ranges). February 2004 93 . can allow. For high frequency monitoring. C6a/b = 20nF (a value not obtainable in C7. C7 by switch S2 in position 2. other input. to be measured is connected between the configuration to oscillate. The The use of NAND gates in this circuit counter/timer. It is this fact that also NAND gates IC3b and IC3c. when IC3b/c is impose a more pronounced phase shift on small capacitance differences. The out- control. When RA1 is as expanded above. which the software is capable of discerning very output pin 4. the value for C is thus probe clips and switched in parallel with low.3. Its princi. VR2. In the formula. Complete circuit diagram for the PIC LCF Meter. R5 to PIC pin RB6. stray capacitance into an unimportant role. This pin is used as In use. is held high by IC3b’s tionship with capacitors C6a/b. is also C7 provides a minimum reference against The outputs from IC3a and IC3b are included in the feedback path. with IC3a output pin 11 being makes this circuit suitable as a frequency mum frequency at which the oscillator runs held high. When RA0 is low the oscillator is registered correctly. the inductor whose value is to be GATE CONTROL the input to the PIC’s TMR1 16-bit measured is placed in series with L1. Its use min. the PIC imises the effect of stray fields within the The LC oscillator becomes active when is set for non-synchronous input to TMR1 physical circuit assembly. although this is not important in frequency calculation formula. inhibited. As only one oscillator can be selected Potentiometer VR2 also has the side quency. When IC3a is oscillating. A preset potentiometer. its frequen- starts reliably and then continues in a sta. pin 8. counter up to about 5MHz. to be high enough to effectively “swamp” cy is passed through IC3d via pin 9 since its ble manner. The effect is due to its rela. put from IC3d pin 10 is fed via resistor this application. troller. which the circuit is “nulled”. pin 4 held high.

the function of switch insert IC1 and IC3. It will cally on the board. C8 100n ceramic disc. 5mm pitch is to measure. C6b. (whose p. terminated in miniature crocodile clips Switches S2 and S3 are also used to set with different coloured insulating covers Miscellaneous “corrective” factors should any be found indicating their polarised identities. X1 3·2768MHz crystal between +7V and +12V d. programmed PIC microcontroller. one each The system is operated at 3·2768MHz. either inductor or capacitor.c. The latter should only be 5mm pitch (2 off) is set so that the component is connected to done once you are sure that everything else C3. to suit the PIC and the l. covers.l. and then in ascending order of All 0·25W 5%. solder. The switch has been checked. It is monitored by PIC pin In the test model. C5b. software. components C5a. Ideally all COMPONENTS nal is input directly to PIC pin RB6 via should be 1% devices. Component position and track layout After each sampling period. 1mm terminal pins. There is no is correctly positioned and soldered.s. available from additional power line stability. and then go through the following main case. the frequency With the prototype. followed wire.i. Switch on the power.c. 14-pin dard configuration for programming PICs check routine: d. SK2 socket. 18-pin d. min. In the (see text). components (see photograph). exact value of capacitor C7 and any stray In order to obtain the best potential accu. For the prototype. S2.c. X2.4). Ensure that electrolytic Potentiometers capacitors and the semiconductors are VR1. The component to be mea. with its other lead plate.’s screen contrast. self-adhesive (4 programmed via this option due to the con. For external frequency counting the sig. resistors R3 and R4.c. This board is displayed capacitance value of 1227pF. ideally 1% be obvious from the measured results if the trimmed to serve as a terminal pin. with insulating figuration settings installed during manu. should only be programmed on the board by CAPACITOR. will first briefly display an opening mes. (They must be retained capacitor C7 and any stray capacitance pre- even if on-board programming is not sent around the assembled unit. When in position 1. component size. R3 and R4 should have the best measurements of a capacitor connected 94 Everyday Practical Electronics. about 15cms long. extra-flexible wire was IC3 4011 CMOS quad RA2. Semiconductors line to PIC pin RA4. on line 2.c. required. 5mm pitch (2 off) its appropriate oscillator circuit. VR2 10k min. regulator measurements. C2 and C8 help to ensure adjust preset VR1 until the l. round MODE SELECTION inserted the correct way round. Preset VR1 sets the author did not use 0V socket SK2 (see SK1. R5. this time. The screen off).c. with resistor R5 providing a having such close tolerance are not widely buffer between the signal and the output of available and you may have to accept 2% or IC3d. +5V supply voltage is still correct.d. Such PICs sage on line 1.b. screen Printed circuit board.p. socket. preset. It will be wrong at CONSTRUCTION monitoring is in Hertz (cycles per second). code This is the value which results from the 434. C6b 10n ceramic disc. which is biased low by resistor R2 used for the probe leads. the frequency at this details for the PIC LCF Meter’s printed cir. push-to-make tions are output to the 2-line by 16 charac. contrast is satisfactory.b. wards in the light of experience. so that the frequency in terms of capacitance. Below it is stage is typically about 247000Hz with a cuit board are shown in Fig.d.l.. crocodile clips.i. sockets. connecting facture (adverse LVP setting). Adjust S2’s (see text) Switch S3 is a push-to-make type and is lugged washer so that only positions 1 and IC2 78L05 +5V voltage used to “null” the circuit prior to taking 2 can be selected. except where stated ing normal logic-level signals. Brand new PICs should not be Leave the probe clips unconnected (open mounting supports. Diode D1 and resistor R1 prevent the programming and unit supply voltages The software then assesses the frequency generated by the CR oscillator in relation to Approx. extra-flexible wire.4. circuit).c. EPE LCF METER. but do not (2 off) As stated earlier. connections are in the Capacitors sured.d. been suitably drilled for the panel-mounted S3 s. socket.c. available from the EPE PCB Service. danger of component or circuit damage if Note that inductor L1 is mounted verti. Switch off power the EPE PCB Service. insert IC3 and the pre. s.d. This is controlled by S2c. p. is displayed on screen line 1.c. 150mm x 80mm x 50mm. later). C1 22m radial elect. February 2004 . also see Fig. or connect the l. plastic Connector TB2 is in the author’s stan. a plastic case (the S1 min. IC1 PIC16F628 monitors the logic on RA4 and reacts wiring them permanently once the case has microcontroller. size as l. RA4 is The switches and socket SK1 need only D1 1N4148 signal diode held at 0V via resistor R6. author’s standard order. P2) to the poles of S2a and S2b. toggle author’s “orange box” again!) measuring switch OTHER COMPONENTS 150mm × 80mm × 50mm was used. Software be temporarily connected at this stage. until the circuit has been nulled.c. R6 10k (3 off) The frequency output from IC3d can be Assemble in your own preferred order – R3 10k 1% connected via R5 and socket SK1 to an that preferred by the author is wire links. The resistor also provides a buffer 5% for them.d. R2. line) alphanumeric Regulator IC2 reduces the input supply Switch on power and recheck that the l. R4 1k 1% page external frequency counter suited to accept. at about 9mA connect the l. pre-programmed accordingly.) Sampling is done at approximately one. as discussed later. shown the interpretation of that frequency second intervals. capacitance in relation to the values of racy from this unit. C5b. X2 2-line 16-character (per for a 9V supply. cable ties. with WAITING TIMING of a dedicated PIC programmer. R1 1k SHOP TALK (Oct-Nov ’01) – see later. S2 is two-fold. ceramic inform the PIC which type of component it instability in the oscillation frequency due disc. Cost Guidance Only £25 from interacting. 5mm pitch wrong path has been chosen! prototype it was originally mounted flat on (4 off) The second function of switch S2 is to the board but it was found that this caused C7 1000p (1n). panel mounting The results of component value calcula. although capacitors socket SK1. to the proximity of a signal-carrying p. NAND gate when S3 is not pressed. C4 10p ceramic disc. module voltage to +5V. i. been prepared and assembled. TESTING red and green as set by crystal X1 in conjunction with suggested capacitors C3 and C4.b. preferred.c. It can be powered at When initial checks have been made. C6a. S2c connects the +5V track running in parallel with the inductor. C5a.. knob for in-situ should readers wish to modify the Set switch S1 to position 2 (capacitance). When taking active C6a. 16V nect via crocodile clipped leads (P1 and until the correctness of the power supply C2.d. or the wrong switch setting is selected.p. is con. tolerance that you can obtain.d. etc. Then Capacitors C1. having S2 3-pole 4-way rotary switch. code 434. Note that the switch ters per line l.t. one each red and green sug- gested. L1 10mH axial inductor necessary. The software has an offset when the PIC is programmed in-circuit compensation facility should you need to Resistors See from a system such as PIC Toolkit TK3 correct displayed values upwards or down..c. In position 2.

followed by the capacitance value being reset to zero on line 2. in order to obtain better accuracy than with pulse counting for low frequencies. At the end of this cycle the counter is stopped. It then starts a timing counter (TMR1) which runs until the pin status has changed twice more. the screen shows a frequency of 311·138Hz and a value of 0·974mF (not a bad value for a 1mF capacitor whose tol- erance is nominally ±20%!). However. say. Fig. of course. Clip the probes to a capacitor nominally specified as. the PIC assesses the logic status of the signal on its RB6 pin. Typical Observe the capacitor’s displayed value l. Secondly. Using a test capacitor while writing this. is shown as having a real value of 492pF. and then converted into the equivalent frequency (F) for that timing (F = 1/T). well within its catalogue- stated tolerance of ±5%. represent- ing a complete cycle of the waveform. Note that the frequency value on line 1 is always the actual oscillation frequency and is not affected by the “nulling”. Two points are worth noting in relation to this displayed value.c. A 470pF ceramic capacitor being moni- tored while this text is being written is pro- ducing a frequency of 177653Hz and. In this mode the reference value is too low to be of interest and is ignored. this mode produces frequen- cy results that have three places of deci- mals and a decimal point is displayed Everyday Practical Electronics. 1000pF and its actual value will be displayed on line 2.d. Now clip an electrolytic capacitor in place of the previous one. It then waits until this logic phase changes. This is confirmed by the word NULLED being shown on line 1. which is entered automat- ically if a frequency below 1024Hz (a binary “round” value) is detected. this “reference” value is subtracted from the result of the measurement. between the probe clips. Pressing switch S3 sets the reference value into temporary memory within the PIC. which are polarity sensitive. say a value of 1mF. is converted into microseconds (T). Having released switch S3. correctly connecting the positive clip to the positive capacitor lead – an important point to note when measuring electrolytic capacitors. pinouts are shown to the right. February 2004 95 . as set when the power is switched on. a different timing technique is used for frequencies that are below 1024Hz. Component layout and master track pattern for the PIC LCF Meter. the next sam- ple value should also read zero until the capacitance across the probes is changed. after the reference value has been subtracted by the software. The count value. First. In this mode. on screen.4. Be aware that the act of touching the probe leads with your hands will introduce additional capacitance across the probes. which is in relation to the 3·2768MHz crystal used. so do not hold them while taking value measurements. At pre- sent it is subtracting zero from the value. the PIC must be “told” that this is the value to use.

it and the PIC LCF Meter could un-nulled values are 468608Hz and CORRECTION. With power switched off. to each other (as a short circuit). that circuit is likely to result in incorrect results are shown on the upper and lower sage on line 1 stating which correction readings. The for the capacitance or inductance mode you measurement. ing a suitable pause before doing so to trolytic capacitor. counter. switch off and then switch on again. for the same reason as tion values is 1 to 199.wimborne. Note the “nF” suffix – the soft. On the other hand. say. allow the software to be told to exit correc- obtained by the “uF” route). (The Now. STABILITY A point to appreciate is that this simple INDUCTANCE TEST unit has no temperature compensation To test the LC oscillator. A selection of Peter’s routines is in the PIC ues of inductance. “nulling” factors referred to earlier are not say. i. Wait briefly for the software to exit a switch debounce routine (about 0·5 seconds). Be patient when monitoring higher val. applied to each value calculation. the PIC’s software Finally. In this used with the oscillators are not exactly For higher capacitance and inductance configuration inductor L1 completes the those for which the software has been writ. and without which this technique are displayed in henries. ware. then a common 0V (ground) con. For instance. though.5in disk (for which a nominal handling case showing that the external inductor is charge applies). however. The inductance value should read 0·000uH Now clip an inductor of. value. is 99. At worst. ters clockwise rotation (about 7k5). set switch S2 always “null” the meter prior to taking a quency value shown on screen line 1.epemag. for example CAP powered. the monitored frequency is below a certain In normal running mode the calculated co. tion value is 100. The correction value can now be changed using both S2 and S3. which oscillates ten. for inductance nulling they should various wiper settings and chose the best – recognising the pressed status of S3 during be closed (shorted). the prototype displayed a frequency Because switch S2 does not cause the correction values for the two oscillator of 1305Hz. if the correction design would have been extremely difficult suffix of “H”. divided by 100. For accordingly. representing a value of internal oscillators to be inhibited during modes are recalled from memory and 231·210nF. internal oscillator frequencies to an exter. be stored to the PIC’s internal non-volatile expressed in microfarads (mF – but shown Resistor R5 prevents the signal from (EEPROM) memory.305H.801mH would by 1.e. the drift is insignificant. 100. If a scope is not available. Hemsley for his excellent maths routines be displayed as 0·100801mH. allow the circuit’s power line capacitors to while the values are assessed. nal frequency counter. On be open. since up to ered by the same power supply source as discharge. it is not critical. connect decremented. Each time the unit is switched on. a multiplication Tricks folder on our Downloads site. then the effect is a multiplication by to achieve. FREQUENCY If S2 is in position 2 (capacitor) then each press of S3 causes the correction value COUNTING to be incremented. especially those in the “mF” and feedback circuit for IC3a. When the screen shows that correction mode has been entered. if you have a capacitor to hand of. when registering a calculated value quency will always be accompanied by an It would have required an extra switch to of less than 10000 (but which has not been inductance or capacitance value on line 2. author always uses a common workshop power supply for all circuits. the pulse ble via the Downloads click-link on our width assessment technique is used when home page at www. you need to be patient Note that if the LCF Meter is not pow. first setting followed by one complete cycle. The oscillator frequencies can position 1 (inductance) and clip the probes In the event that the component values and will drift with temperature changes. but otherwise shows “pF”. It is also available for free pretty close to its marked value. external frequency input. where it remains even as “uF”). \$ for larger values of capacitance. power-up. you should rate appears stable. for example 7. Pressing “null” switch S3 the correction value will be displayed. if S2 To monitor an external frequency. 96 Everyday Practical Electronics. which is in position 1 (inductance) then each press must conform to normal logic levels of S3 causes the correction value to be (swinging between 0V and +5V). the existence of other components within Again the frequency and calculated This will be confirmed by a screen mes.e. as indicated by the fre. 220nF (0·22mF). being adversely affected by the running of after power has been switched off. the dom. the displayed fre. 16384Hz for inductors. 0·99 (a 1% decrease). The range of correc. jumps to the appropriate correction routine of components that are “in-circuit”. 10mH default is 100. setting will be obvious if an oscilloscope is want to modify. which have been used extensively in the Values obtained using the pulse width the effect is to multiply the value by 1·01 (a PIC software. since multiplying by 100 and then dividing by 100 is the same as multiplying ACKNOWLEDGEMENT The author gratefully thanks Peter millihenries (mH). switch S2 to ALIGNMENT circuitry. clip it to the probes Frequencies from about 0·05Hz to stored beyond switch-off. A typical display available from the EPE PCB Service on might then be 342348Hz. On line two the existing be damaged. routine selectable when the LCF Meter is lower component values (i. For nection between them must be provided via switch S1 to the opposite position prior to instance.e. then there is no correction values less than 100mH are displayed with a “uH” suffix. three logic half cycles may need to be the external signal source or frequency Correction for the other oscillator’s rou- processed – the initial logic level change. In this 3. compensation is possible through a “H” ranges. In the prototype SK2 was omitted as the od of 0·060Hz. i. Taking one at ran. accessi- As with the capacitance mode. Conversely. leav- Note that with larger values of elec. In the prototype the author its initialisation routine. If the correction value is 101. otherwise they are shown in applied. tine is entered in the same way. In the prototype typical mode has been accessed. February 2004 . Additionally the value is now may be in either position. On the normal frequency counting range. monitored as 5055mF had a full cycle peri. range of 0·01 to 1·99. gives an “nF” Socket SK1 may also be used to feed the tion mode and the only way out of it is to suffix. try VR2 at pressed while the power is switched on. values. never try to measure the values set the wiper for approximately three-quar. release S3. either internal oscillator. Read this month’s Shoptalk page for frequency value is shown with three deci. with a 1% increase). higher Adjust preset VR2 until the oscillation first switched on. Switch S2 Each press of S3 causes the new value to accordingly. if the correc. At best. greater than 5MHz can be monitored. download from the EPE website. 9·969uH. the signal source to socket SK1. PIC LCF Meter. tiplied by the correction value and then information on component buying for the mal places.uk (path PICs/LCFmeter). if the other circuit is lines of the screen. Press switch S3 and hold it For capacitance nulling the probes must used. a random test with an electrolytic socket SK2. selected by S2. 11. Again the capacitance and inductance values are mul.492mH. oscillation rates). RESOURCES The software for the PIC LCF Meter is between the probes. so leaving the value unchanged.) and examine the result.