Introduction: Inductance/Capacitance Meter Saga
I had a bunch of random inductors in some random drawers and I wanted to know what values they were. These values are quite often not obvious by looking at the device. Colour codes for old ones were not standardized and some of the coloured rings on inductors can be faded or discoloured so that its impossible to tell what they are. Others may be unmarked and any that are hand-wound are just guess work without a meter. So I decided to make an inductance and capacitance meter which would be fairly accurate and work over several decades of value from a few nano-Henries to a few milli-Henries and also from a few pico-farads to about a micro-farad (hopefully). Sounded easy - what could go wrong?
This shows what I went through to do it. It is not a pretty sight, but rather than report the cleaned-up version with all of the screw-ups edited out I thought it would be good to show some of you gentler souls what can happen to the best of intentions when Mr. Murphy intrudes and decides that YOU SHALL NOT PASS!
But really, folks, just about everything that could go wrong with this project, did. I finally prevailed, however. And I also managed to accomplish, erm..., most of my design goals in the process. (!)
Step 1: Design Philosophy
OK, so how do you measure inductance or capacitance, anyway? After thinking about it for a while and researching how others did it, I found that there are three basic approaches:
1 - Tank Resonance: The unknown Lx or Cx is made part of a resonator which is used in an oscillator. The resulting frequency of oscillation is measured against a known precise time period and used to calculate the unknown value.
2 - Time Constant: The unknown Lx or Cx is partnered with a known resistor value. This circuit is charged or discharged with an abrupt voltage step. The resulting voltage charging time is measured with a known clock and used to calculate the unknown.
3 - Impedance Measurement (the most common): An AC current of known frequency is driven through the unknown inductor or capacitor and the resulting AC voltage across it is measured. The unknown value is calculated from this.
Both methods #2 and #3 suffer from the same inaccuracy. That is that the unknown inductor or capacitor also has an unknown resistance value that appears in series with it. This is a normal consequence of building real world L's and C's from wire and sheet aluminum. This resistance causes charge times and impedances to appear larger than they should and can make ind/cap readings to be as much as 5-15% too big or bigger. To be correctly taken into account, this series resistance would first need to be measured so that it can be figured into the calculation. This would have to be done in different ways for inductors or capacitors and would complicate the unit.
Method #1 does not suffer from this problem. The series resistance could make the oscillator slightly less strong but would not change its resonant frequency.
So I choose method #1. At this point, I must confess that I'm holding out some (vain) hope not to involve a microprocessor. (Ha!!)
The frequency measurement referred to above would suffer from much less calibration error, particularly with low values if what we actually measure is the change in frequency brought about by inserting the unknown into an already working oscillator. So first the frequency of oscillation using a known inductor and capacitor would be measured and then again with the unknown inductor inserted in series with the known one, or the unknown capacitor inserted in parallel with the known one. In each case the frequency of oscillation would be lowered by some small (or not-so-small) amount.
MATH ALERT!
So, the unknown value can be calculated from:
Lx = ( (fo/f)^2 - 1) * L
or
Cx = ( (fo/f)^2 - 1) * C
Where:
Lx and Cx is the unknown
fo is the frequency of oscillation without the unknown inserted
f is the frequency of oscillation with the unknown inserted
L is the known (built-in) tank inductance
C is the known (built-in) tank capacitance
As can be seen from these equations, if the measured freq, f, is the same as the reference freq, fo then the calculations go to zero. This makes sense and would be the case if the test terminals are shorted for an inductance measurement or left open with no component for a capacitance measurement.
Both of these equations can be derived directly from the equation for resonant frequency of a tank resonator:
fo = 1/ ( 2 * pi * sqrt(L * C) )
Step 2: Choice of (Cheap) Components and (Just As Cheap) Required Development Tools
Firstly, I fully expected to put this thing on a home-made PCB using the toner-transfer method which I did. (pictures follow)
But, after about 15 minutes of cogitation about a hardware-only solution, I realized that insanity lay that way and that a micro would indeed be necessary, 8-(. But, at least I could hopefully brush up my C code skills, 8-), but if driven to it I could resort to good old assembler programming, 8-|, (just like in the Good Old Days). Now, as with some other projects, I wanted to spend minimal money on this unit, so I went to see what uP/uC's I had on hand. After making a list of available chips I whittled them down to meet the following criteria:
1 – the parts are already in my hot little hands (or drawer)
2 – the development tools are already on hand: (cross-assemblers, device programmer, C compiler for ATMEL 8-bits, Microchips FREE C compiler for PICs)
3 – the chip has sufficient I/O pins and (cough) code space to do the job
This narrowed it down to two PICs from Microchip, the PIC16C57C and PIC16C58B and the ATMEL ATMEGA16. I've used the ATMEGA16 before and it is a lovely chip with lots of code space and a wide array of goodies on board but I thought it was overkill so I chose the PIC16C57C which had more I/O than its little brother, the PIC16C58B but only one timer to do several things. With the hard decisions made, I launched into the circuit design with (naive) gusto.
As I said above, the scheme is to insert the unknown into a tank circuit and measure the change in frequency of oscillation. The schematic fragment shown is the oscillator used. It is based on a standard comparator, the LM311 in dip-8 package. This circuit has been used by many for this but I first saw this used on www.radiolocman.com (http://www.radiolocman.com/shem/schematics.html?di=33994). I prototyped it to make sure it would work with a wide range of L and C values and it did. Furthermore, inserting series resistance into the unknown L/C made little difference to the frequency as measured by a (relatively cheap) counter, a Fluke 1910A good to about 5ppm accuracy and seven digits of precision. The math was verified with several known L's and C's inserted into an already operating tank circuit. As well, the frequency of oscillation was measured over different power supply voltages from 3.3V to 12.15V with a variation of less than 0.5% from min to max. So far so good.
Now, the PICs are good chips but I had only 1990's-era cross-assemblers (don't laugh – they work) for sw until I saw a reference to Microchips FREE C compiler on LadyAda's personal website. The chips are UV-erased and my handy Needhams programmer will program them! I had 4 specimens. All of the other parts would be garden variety stuff which I already had as well including a chunk of blank one-sided pcb material. Great!
At this point, I found that my handy 2002 Needhams programmer was dead! I have no schematic of it so tried to get help from the maker. Their website ( www.needhams.com ) didn't mention the unit so I called them in Florida. (Phone #303-861-8200 ). I could only leave a message with a service but was almost immediately called back by David who was doing tech support (and admitted that he'd rather be doing something else). However he said that they have NO schematics for the unit or any of their products sold prior to 2006 when they suffered a fire and was completely burned out! “We lost everything!” Many blogs say they are out of business but their site is still up AND with new products. However they accept orders ONLY over the phone, now (??) (EDIT: They will accept credit card info only by phone but will take orders other ways now.). I am here to say that I love that programmer and that all of their products are really great units at very reasonable prices. I would buy from them again in a heartbeat. But the current budget doesn't allow for it, so after 2-3 hours of probing with no documentation, I find the dead component (a common one), replace it and it works again as before. Whew!
Fortunately my UV eraser is still OK after all these years (last used in early '90s).
Step 3: Schematic Explanation
The oscillator is shown in the first picture in this step. Assume that there is a nothing between the test port connectors and that the switch is in C position. Thus the left end of inductor L1 is grounded.
The LM311 is a common voltage comparator. Its output goes high or low depending on the difference voltage between its two inputs ( + , - ). The negative input is automatically biased quite near the positive one by R5. Cap C5 serves to remove any oscillation from this feedback. When the power comes on pin 2 of the chip rises to some voltage between 1/2 and 2/3 of the power supply. The output will be high since pin 3 is momentarily held low by uncharged C5. Once C5 charges up through R5 and gets to the voltage on pin 2 of the chip, the output will go low. The inductor and capacitor, L1, C6 will ring at some frequency, fo causing pin 2 of the chip to ring as well at the same rate. This causes the output to switch at the resonant frequency. The DC voltage on the negative input of the chip will follow that of the positive input. The LC tank will continue to oscillate at fo, as it is driven from the output through R4.
With the switch in C position any capacitance put on the test port will go in parallel with C6. With the switch in L position any inductance on the test port will go in series with L1. In both cases the frequency of oscillation is reduced. It is this reduction that is used in the calculation of the test component value. So I needed some way to remove the test component from the circuit temporarily while the reference frequency is measured. The second picture shows how this is done with a DPDT relay driven from a port on the micro. The micro also needs to know which position the switch is in. This pic should show a connection going from R3 to off-page. This would be connected to another port on the micro.
A complete schematic of the first version of the unit is given next. Now, the PIC16C57C has only one timer and its limited to 8 bits. So if I wanted to count oscillator cycles and have some reasonable resolution I needed to have at least 4 more timer bits. So, I put a 4-bit prescaler counter, U2, between the Lm311 and the PIC which could be read by software. I would generate a fixed gate time to accumulate oscillator counts with a simple buzz loop in the code. This buzz loop would also handle the display digit multiplexing.
Since the micro had to measure the frequency of the tank with no test subject present I needed to momentarily switch the test port out of the circuit. Relay K1 with its DPDT contacts and driver transistor Q1, allow the PIC to do this.
All of the segment and digit drives for the display come directly from the PIC and go through connectors JP1, JP3 to the transistor drivers on the top board. The displays I had were common cathode so all of the segment signals from the PIC are pull-down to turn on while the digit drive signals are pull up to turn on.
Putting the MEASURE button and an LED on the same PIC pin forced me to make a trade-off. That was that when I pressed the button the LED was allowed to come on not under sw control but the sw could turn it off and then on after that and after I raised my finger too. So the LED could be flashed while measurements were being made (that is while my finger was down) yet when the button was released the PIC could still turn the LED off and check the button.
Since the test port and the DPDT switch had to poke through the top of the tin, all of their signals also went through the connectors to the oscillator. This would add some extra wiring (and inductance) to the measurement but could be taken out again in the calculation.
The power supply section is standard stuff and was designed after I scrounged up a 9 VAC wall wart and patched on a connector. The 7805 regulator needed a small heatsink to keep it from smoking.
At about this time, as luck would have it, my wife came to me with a neat round metal candy box (now empty) and said “Why don't you put it in this?”. So I looked at it and said “Why not?” You can see it in the last picture under my desk lamp. The computer shows the layout in progress.
Attachments
Step 4: PCB Creation - Ver A
I finished the hardware design using only parts that I had and proceeded to calmly start a PCB layout for a 4” diam. round board to fit into the candy tin.
It wasn't very long before I realized that not everything would fit. So I split the circuit into two parts to go onto two round boards that would be stacked on standoffs and arranged for a 24-pin connector to connect the two. Both boards are single-sided copper. I planned to print the legend on the top side, too.
After laying out the circuit for two round PCBs, I finally got around to building something. As I said before,I used the toner-transfer method of PCB fabrication. This involves the following steps:
1 - print the copper pattern as black onto GLOSSY photo paper using a laser printer
2 – cut a piece of single-sided copper-clad board to size and scrub it good with FINE steel wool
3 – cut the printed pattern to size and tape it to the PCB with toner against copper side
4 – with clothes iron on hottest setting, iron the pattern with heavy pressure for about 5-7 min
5 – put BOILING water into a tray and dump the board in to soak for about 10-15 min
6 – rub the board with thumbs to get all of the paper off of the board; remove tape
7 – scrub the board with toothbrush, dipping in HOT water frequently, until paper fibres are gone
8 – place it into an acid bath (I used ferric chloride)
9 – rock the board often and check etching progress until all tracks are separate and distinct and NO copper left on open areas
10 – wash PCB in running water for at least 60 sec
11 – dissolve remaining toner resist with acetone and wipe with paper towel
12 – put chemicals away (very important)
13 – drill all holes (hint: use carbide drill bits – they last much, much longer than HSS bits)
14 – put two resistor leads (or other small wire) through two holes on opposite edges of the PCB
15 – punch these wires through correct points on printed legend on GLOSSY paper against non-copper side
16 – repeat steps 3 thru 7 to print legend
One thing I should mention about the ferric chloride: THIS IS SERIOUS STUFF! I kid you not! Do not be dumping it down the drain in large quantities unless you like large plumbing expenses! Carefully put what you have in the etch tank back to the container it lives in. Rinse all items that came into contact with it in fresh water very well and in the laundry sink (or, better yet, under a garden hose). Do none of this in the kitchen sink! This stuff stains anything and everything it contacts, eats stainless steel for breakfast and can be a marriage breaker if it splashes anywhere it shouldn't (such as on your best shirt or the kitchen counter). Wear old scrubby work clothes while doing all of the above.
Step 5: PCB Creation - Ver a (Again)
The first board I did was the top board with all of the display stuff on it. Did I mention that the copper pattern on the bottom side must NOT be printed mirror-image so that it comes out right on the copper? No? Well, I printed it mirror-image the first time so... back out again with all of the PCB stuff, make a new (non-mirrored) print of the copper pattern again and find another piece of copper-clad board so I could do it right this time. The first picture shows what I got the first time but the pattern is mirrored left to right. Compare this with the board on the right in the third picture.
The next picture shows the iron in place to transfer the toner. You have to press very hard for 7 minutes at a stretch and work the iron into all corners of the board to get good results. The third picture shows both boards after having been etched and are ready for the legend to go on the other side. The next one is of the two with the legend pattern taped and aligned with the copper on the other side. The next shows me rubbing the paper off the legend side. The legend toner can be just seen through the residual paper.
Step 6: Assembly of Ver A
After drilling, the boards are soldered up with components. Some of the ones on the top (display) board hang down between the two since they are too tall to stand up under the top of the tin. That's why the TO-220 transistors are shown being soldered to the copper side of the board instead of the top side.
Step 7: Software for Ver A
I worked on the sw for several days to figure out the best way to do all of the calculations, measurements, button/LED management, etc. while keeping the display scanned without disturbances of any sort. I felt I was finally getting a handle on it. Each display digit slot time would have other tasks assigned to it to spread the load. Remember that these PICs have NO interrupts and only ONE timer to work with.
Now, its going to be difficult to get at the PIC when the boards are stacked to make the 24-pin connectors come together. In fact, its going to be a real pain if I'm taking it apart and putting it together all the time and have no convenient way to probe circuit points between the boards. So I made a patch cable to go from one board to the other so that they could be spread apart while debugging.
Step 8: Why Ver a Won't Work
The micro is an old one in a ceramic DIP-28 package with a quartz window in it. It is programmed in my device programmer, the Needhams EMP-21 (remember the Needhams programmer?). When changes are needed to the software the chip needs to be taken out of the socket and put into my UV eraser for about 25 minutes then re-programmed and put back into the socket to test it. Its not pretty but its doable. In fact, it's how I did many projects during my career as an engineer.
I have four specimens of this chip so I expected to be cycling them through the eraser/programmer setup regularly.
At this point, what the hell, since I did have some code written, I decided to try programming it into them using my newly fixed EMP-21.
The first one could not be programmed by the programmer. Neither could the second.
Or the third.
Or the fourth.
In fact, none of my four chips could be read or programmed.
I also had four of the PIC16C58B chips which are in the smaller DIP-18 package (shown). I tried all of them and they were all recognized, read, and programmed successfully as well as a random EPROM chip. That exonerated the EMP-21, the setup, my laptop and the four PIC16C58B chips. And I was screwed because all of the bigger chips were toast. (And before anybody mentions it, I DID make sure that the right personality modules, chip types, etc were selected on the EMP-21.)
I decided that the best way forward was to switch to the smaller PICs. 8-(. At this point it was either rebuild from scratch or do a very nasty patch on the existing PCB to change the micro footprint and include some extra chips. I opted for the former.
The smaller chip was identical to the larger PIC except that it didn't have as much I/O available so if I wanted to use it I would have to change the circuit fairly dramatically and go back to square 2 (step 3) and do over. So that's what I did. I redesigned to get more I/O from the smaller chip, re-layed out the lower (micro) PCB, refabricated as before and re-assembled it. Most of the parts from the first Ver A had to be ripped off the first board and put onto this one.
Step 9: Schematic Redesign (#1)
Now look at what the schematic has become in its second (Ver B) incarnation. The original PIC has been replaced by the smaller 18-pin version and two shift registers, U10 and U12, TPIC6B595, have been added to get the I/O signals back. The s/w now has the additional burden of organizing all of the I/O bits together and shifting them out one at a time into the SRs so they can be used. This extra overhead goes into the display routines. The new micro, PIC16C58B, is otherwise the same as the previous one.
Attachments
Step 10: PCB Creation - Ver B
Fortunately, I only had to recreate the lower (micro) board. According to one of my pet rules, which is to use only the smallest piece that does the job (this keeps bigger pieces available for who-knows-what) I chose a piece of PHENOLIC copper-clad board to make this one. It had a sizeable chunk missing out of one edge but would just fit the circuit.
The shots here show it being made. In the first shot, to the right, you can see the acid bath sitting on a warming pad wrapped in a plastic bag and weighed down by my box of drill bits. This was to warm the acid up some. The temp of the acid can have a dramatic effect on the etch time. That's why you have to keep a close watch on it. The weather was pretty cold then and my work room was also pretty cool even though the fireplace (!) was on for about an hour. The second and third shots show the board soaking in the hot water. If you squint you just might see steam rising from the tray. After etching, I'm doing the legend and in the fourth shot the two aligning resistor leads can be seen just before the paper is taped down. The result is shown next. Alignment is OK but the lines are only so-so. The copper side is shown next with the surface mount patterns for the two shift register chips.
Well of course, it had been a couple days since Mr. Murphy showed up, but I didn't have long to wait. I hadn't trimmed the board to size prior to etching and tried to do that afterwards. With the board clamped in the vice and sawing away with a coping saw, the saw bent the brittle phenolic enough to crack it from side to side!
Now what – make another or patch it together? So I patched it with bits of wire and lots of solder.
If you look closely you can see the crack on the assembled board in the next shot running right past the relay.
Step 11: Onward And... Upward ?!
It is now several months after starting this project and after writing/rewriting code and doing many trial compiles I have come to the following conclusion: that it's just not going to fit into the 2K space available on the PIC. Many people would advise me (and some have) to junk it and buy wine. But I am just such a sucker for punish...that is, a stalwart engineer that I decide to soldier on.
So, I need to migrate it to a bigger code space. That leaves me with only one option left from my original three: use the Atmel ATMEGA16 chip with all of its on-board goodies and a whole 8K of codespace. Despite my initial reticence against using it since it seemed to be overkill, it looks like I'll be doing just that.
Step 12: Redesign (#2)
Over the next few days, again I re-design the circuit to include the Atmel chip (dispensing with the shift registers and the prescaler counter), completely re-work the layout for the bottom board, re-fabricate it with all of the usual stuff, rip most of the parts from the old Ver B PCB and re-drill, repopulate the new, Ver C board. Again the ATMEGA16 is a SMT device so much care is needed to put it on the board. The fine pitch of its pins also was at the limit of the resolution of my abilities to etch it but I got it on the board.
The schematic here reflects what I came up with. In retrospect, I wonder now if I couldn't have actually fitted it onto one board after all.
Attachments
Step 13: New Required Development Tools and Software for Ver C
Finding a C compiler for the Atmel chip was no problem. I already had a very decent one from Imagecraft (from 10 years ago). It runs under Win XP and uses a hardware dongle on a parallel port (my choice) as a licence. The compiler passes its output *.HEX file onto Atmels tool, Studio+ (also 10 years old). It communicates with an Atmel interface gizmo (the AVR-ISP) which plugs into the laptops COM1 serial port and into a 10-pin programmer port on the board. This port is on the schematic as J2. You have to be very careful to get the MISO & MOSI connections the right way around but when its all connected correctly it can work like a charm. Only mine didn`t.
Was it the AVR-ISP or the COM1 port on the laptop in my lab? After trying many things on the laptop including plugging different things into the COM1 port, probing the AVR-ISP and checking/rebuilding various cables. Nothing helped. Atmel has a newer version of their AVR-ISP (AVR-ISP Mk II for $45 from Digi-Key) and from Atmels website are free Studio+ tools with USB support so I got those after about a week. Installing those went without a hitch (surprised me!) and downloads went ahead. USB is so much more reliable than RS-232 as anybody who has survived the 1980s can attest to.
Since this chip has so much more in the way of resources (many interrupts for peripherals, three timers with prescalers, multiply instructions (yes, plural) and more stack space as opposed to the miserly two levels of subroutine calls allowed in the PICs) the code could be organized in a more straightforward fashion with a mainline, display interrupt service routine and other functions so that all of these things worked transparently to actions of the others. I didn't have to mix the calculations with the display multiplexing, etc.
With the PCB finally fixed up and sw tools actually working I plowed ahead on code. It used up about 28% of the available room including whatever floating-point routines the compiler had to include. Since the values of the built-in L and C were programmed into the code in uH and pf, resp, the calculated value would be in the same units. It was just a matter if shifting the display value left or right and lighting the correct decimal point so that the display was right. So the display auto-ranges and with leading zero suppression as well. The only thing I left out was a couple of LEDs to tell me whether the reading is in nf or pf (or mH or uH), but I figured that if I couldn't guess that by myself I shouldn't have built the unit at all.
BTW: at about this time the HDD in my laptop decided to give up the ghost and I had to buy another XP laptop, but that's another story. (Fortunately I had a backup copy of the s/w to date.)
Step 14: Don't Beat Me Up About the Box
At least it all fit in (eventually).
The original label on the lid was removed with hot water and acetone. Then by taping a copy of the top board component placement to the lid of the tin the required holes could be cut with either a drill or a Dremel tool with a cutting wheel on it. The sharp edges were softened with a small file.
Then the whole tin was painted with a black spray bomb and trial assemblies were attempted. The switch which I thought would have to stick out the side of the tin had to be moved topside because – well, just think about it for a second. Putting the switch horizontally between the boards would have been impossible to assemble. I cut a space out of the top board for it to hang down into while it was screwed onto the top. You can see it in the third shot.
I had a hell of a time getting the lid onto the box with the boards in there. Then, of course, it had to come apart again for something, and I had an even worse time getting it apart. The rolled lip on the tin would wedge itself between the lid and the switch so some adjustments were necessary.
Step 15: It's Finally Working (and No Smoke)
The next shots show actual values being displayed and they're fairly close to what they should be! I show a few parts being measured. In order, these parts are marked as:
an 82 uH inductor
a 10 nf cap
a 50 nf cap
a 20 nf cap
a 75 uH inductor
a 35 uH hand-wound inductor (give or take)
an unmarked inductor showing 124.8 uH
The unit will continuously make measurements as long as the button is down. This turns out to be about 4 measurements per second. It will show changes in inductance or capacitance over time so variable capacitors can be measured from min to max by just turning the rotor. The effects of just touching the device can also be seen. The last value measured freezes on the display when the button is released.
Step 16: Top Label
The top label was generated entirely in Paint and printed onto some thin card stock then glued to the tin with super glue. This cardstock actually was the backer for some dollar-store decorative paper that I thought I would use but after looking at it, I liked it better on the backer, not the actual stuff they sell for money!
Step 17: OK, But How Do I Calibrate It?
Now, there's been the ugly spectre of a known issue that I had no solution for since I began this thing.
Even with a zero value part (short for L or open for C) in the test port a number was displayed. This is a consequence of the difference in residual inductance and capacitance in the connections between the test port and the oscillator and just the oscillator when the relay operates. It was easy to just subtract that number from the calculation to calibrate the meter for zero. Much more difficult is calibration for range.
When building something that will need to be calibrated you need to be able to verify that calibrated something by an entirely different measurement method that you have a lot of confidence in being accurate at least three time better than your own device is supposed to be.
I don't have that. I thought I might have it since I do have a some very precise resistances (inc 172.22 Kohms +/- .05%) that I ripped out of an old Fluke 6 1/2 digit meter, a very precise voltage (1.225V +/- .005V) and a reasonably precise time measuring device (the old Fluke counter). Using the C cap from my new meter and with these other parts I thought I could drive a precise square wave into a resistor-capacitor combination and measure the time constant to tell me what the capacitor really was, to (hopefully) within 1%. The cap was marked 1.6 nf, and in fact one just like it measured as 1.632 nf on my new gizmo. But my calibration setup showed it, after a bit of calculation as 2.7 nf, a 68% error! I just gave up.
One of these days maybe I'll stumble across a standard capacitor or inductor (they exist) that will allow me to calibrate the device for real but for now being within a few percent will have to do.
Another aspect of the calibration is that the amount that the reading is out changes as the value measured gets close to zero. It goes to zero faster than the component does for very small values (say LT 50 pf or LT 100 nH). The measured value also gets weird as the measured value gets large. The oscillator cannot maintain consistent frequency. This happens for capacitances close to 1 uf. I don't know where this happens for inductors yet. The largest inductance I have measured so far is 81 mH.