Dick Cappels' project pages http://www.projects.cappels.org
Return to HOME (more projects)
An Even Better LC Meter Based on the AVR ATTINY861
An improvement over "A Pretty Good LC Meter."  Enhanced capacitance self calibration, accurate operation without precision components, and only one micro controller.


Downloads
Download or view the WINAVR main source file: lcm.c
Download the complete package including the LCD library: Even-Better_LCM.zip (LCD Library provided with Peter Flurey's permission)
Download Gerd Sinning's: LCcalc tools for Windows (See bottom of page).

Find updates at http://www.projects.cappels.org


Introduction

If this picture (above) looks a lot like the Pretty Good LC Meter also on this web site, that's because its the same meter, but with some significant improvements. At this point, its a good idea to read the  Pretty Good LC Meter page because the rest of this page is based upon the Pretty Good LC Meter, and the Pretty Good LC Meter page explains how to build the meter. I have left the Pretty Good LC Meter page intact because it is a complete project and if one wants to build an LC meter based on the ATTINY2313 or AT90S2313, this is a very good project for that.

After building and using the Pretty Good LC Meter for a few months, I came to understand some ways in which it could be improved.  Here is what I corrected or improved upon:

• Improved accuracy at higher capacitance.

• Capable of accurate operation without precision components.

• Reduced drift of capacitance accuracy.

To do all these things, I need more flash memory for program space to perform computation. The flash in the ATTINY2313 of the original design was full with the basic LC meter program, so the first order of business was to get a controller with small footprint that has lots of flash - that turned out to be the ATTINY861 -8K in a 20 pin DIP. Oh, but look: there is no UART in the ATTINY861, so in order to send the display information to the LCD display controller, I would have to bit-bang a UART in C, but if I was going to go to that much work, why not bite the bullet and merge the LCD controller function into the ATTINY861. I had written a controller for the 2X16 LCD in assembler, and it was kind of messy, so I wasn't looking forward to doing it in C -at least not while I am still so new to C. That's was when I remembered Peter Fleury's C libraries.

A couple of clicks took me to Peter's web site, http://homepage.hispeed.ch/peterfleury/, and another click took me to the page with his AVR software http://homepage.hispeed.ch/peterfleury/avr-software.html. Looking though the offerings - AVR-GCC Source Examples, AVR-GCC Libraries,  an AVR Studio compatible Boot Loader, and a test program for his AVR Starter Kit. A couple of these look interesting to me, but it was the LCD library that I was after, so I downloaded the zip file containing the LCD library and had a look. The HTML documentation was very clear and direct -it seemed that I could make use of the libraries by merely placing the library and header files in the folder with the main program and then just calling the functions per the examples in the documentation.  I tried it out, and you know what? It's just as simple as the documentation said it would be. The LCD Library and header files are included in the zip file, Even-Better_LCM.zip, which contains the complete built project. To get the complete LCD Library, including the documentation, please visit Mr. Fleury's site, http://homepage.hispeed.ch/peterfleury/.

The LCD library's default setup generates the code to drive displays using the Hitachi HD44780U controller based displays, but if you have a display that uses the Samsung KS0073 controller, there is a switch that causes code for that controller to be generated.

I had picked up an extra 2 line x 16 character controller from a small surplus shop in Bahnmo Plaza in Bangkok just a few days before starting this project, so I quickly built up a small circuit board with an ATTINY861 and the surplus 2x16 display, and since the power and ISP connections on the ATTINY861 are different from those on the ATTINY2313/AT90S2313 and the AT90S1200, I wired up a jumper socket with an ISP programming plug (Lazy ISP Socket Adapter). Pretty quickly, I had my name on the surplus LCD (250 Thai Baht or US$7.50 well spent). . I ran some wires from the original "Pretty Good LC Meter" to the breadboard so I could use the osciallator already on the original meter, and I was ready to begin re-writing the ATTINY2313 C code for the ATTINY861.

The task of rewriting the code cosisted mainly of getting the timer and counter working on the ATTINY861, and after that, writing the new calibration and zeroing routines.

A couple of months after finishing the Pretty Good LC Meterr, I bough several 1% film capacitors from Digikey for the purpose of verifying the accuracy. Up until then, the only precision capacitors I had was a bag full of 1000 pf 1% polycarbonate capacitors. After all, how many capacitors can you put in series and parallel combinations before the parasitics generate an uncertainty approaching 1%? Running though the precision capacitors from 1000 pf through 0.47 uf, I saw that above about 0.1 uf, the errors became pretty large. This was a puzzle until I remember reading a paper that Chris Krah had sent to me, in which he analyzed this oscillator and showed the relationship between accuracy of oscillator and the Q of the circuit. I ran his formula and it showed that the low Q of the 1 millihenry inductor I was using for the capacitance measurement accounted for nearly all of the error.


Improved accuracy at higher capacitances.

The 1 millihenry inductor that I had been using to measure capacitance was selected to be precisely 1.00 millihenries as measured on my old B&K Precision 875A. The only problem is that its series resistance was 14.8 Ohms (Coincidentally, I had bought a bag of these inductors at Bahnmo Plaza in Bangkok at the same little surplus shop at which I had bought the LCD). 14.8 Ohms is ok for a power supply choke, bu it was  pretty poor for an inductor to be used in a resonant circuit.  The immediate problem was solved by selecting a high permeability toroid core from my available stock, and it worked out that I could get very close to 1.0 millihenries with a little bit of fiddling around. Over the following weeks, I noticed that a capacitor that I measured at night read very differently the next morning. Obviously the high permeability ferrite material is (typical of high permeability materials) variable with temperature.


Reduced drift of capacitance accuracy

The solution to this problem that revealed itself after fretting over the problem for some weeks, was to put a stable 1000 pf reference capacitor (remember, I have a whole bag full of 1000 pf poly carbonate caps) across the inductor. When zeroing and auto calibrating he meter in the capacitance mode, there is only the 1000 pf polycarbonate capacitor and stray capacitance across the inductor.  While one could use a 1000 pf precision capacitor,  knowing the stray capacitance, especially when test leads might or might not be used, was a problem. I came up with a way to program the total reference capacitance from the front panel, and have that stored in the ATTINY861's on-chip EEPROM as a calibration parameter.

During the zero/autocalibrate cycle in the capacitance measurement mode, the resonant frequency is measured, and based on the capacitance stored in EEPROM, the inductance of the approximately 1 millihenry inductor is calculated. This calculated inductance is then used to calculate the capacitance of the capacitor under test when the zero/calibrate cycle is over. In this way, a drifting inductor is automatically compensated for, providing that the capacitor is stable.


Capable of accurate operation without precision components

Recall that the value of the reference capacitor that is used to measure the inductance used to measure capacitance in the capacitance measurement mode is programmed from the front panel. The value programmed into the EEPROM  represents the total reference capacitance, 1012 pf as an example when using a 1000 pf reference capacitor with 12 pf of stray capacitance. If, instead of programming the actual capacitance into the EEPROM, a value that causes the minimum error when measuring capacitance can be used. This is the way I used it. I adjusted the reference capacitor value to obtain a acceptably low error when measuring a known capacitor.

Similar to the case of the reference capacitor for capacitance measurement, the value of the nominal 10,000 pf reference capacitor used for inductance measurement, is also entered in EEPROM as a calibration parameter from the front panel. As with capacitance measurement,  it is not necessary to  use a precision  reference capacitor if you have an accurate inductor with which to calibrate the inductance reference capacitance value. In my case, I used a 1% film capacitor so I would be confident of my measurements of high Q coils, but modified the value slightly to obtain minimum error over a range of inductances from 1 microhenry to 1 millihenry.

In the case of inductance measurement, a stray capacitance of 10 or 20 pf would be insignificant compared to the 10,000 reference capacitances, so using a precision reference capacitor would be enough to assure accuracy, and since the inductance measurement would not have to be measured, there is no need for access to a precision inductor with which to calibrate the meter.

With the ability ot change the value that the firmware uses as the value of the reference capacitors for capacitance and inductance measurement, it is possible to build an accurate meter that does not incorporate accurate components into the design, provided that one has access to precision components to calibrate the meter to.

The modification




The schematic showing all of the circuitry on both boards and the wiring.
Thanks to Robert Rinehart for catching
an erroneous connection from LCD pin 5 to ground.

One of  changes to the Pretty Good LC Meter  circuit are the replacement of two '2313 controllers with a single ATTINY861 controller. In the Pretty Good LC Meter, one controller performed the measurements and the second controller talked to the 2 line x 16 character LCD.

The other change is the addition of C1, a 1,000 pf stable capacitor across L2.

I changed the value of C2, which couples the LC resonant circuit to the rest of the oscillator. The value was 22 uf, but I changed it to 4.7 uf to obtain faster measurement settling time.

The firmware, of course,  is new.




On the physical circuit board, one of the 20 pin sockets was removed and the remaining socket was rewired to accommodate the ATTINY861. The 7805 regulator in the TO-220 package is way bigger than is necessary. given the 19 milliamps battery drain that I measured on this meter, but I have lots of them, bought in the same surplus electronics deal in which I bought all those 1000 pf 1% polycarbonate capacitors, all these 4 MHz crystals, that strange 10k pot, the 0.33 uf tantalum capacitor and the 100 uf aluminum electrolytic capacitor sown on the board. I had to buy the Berg pins, the DIP socket, the 27 pf capacitors and the perforated phenolic circuit board, and the ATTINY861 as new.



`
It may be difficult to see, but the circuit board is much cleaner with only one chip instead of two.




You can see the green core of the 1 millihenry toroid choke that replaced the blue molded choke 1 millihenry choke, and the 1000 pf polycarbonate capacitor (clear and silver, next to the toroid) that was added across the 1 millihenry inductor. The electrollytic capacitor toward the bottom of the oscilaltor board is the new 4.7 uf capacitor that couples the LC circuit to the rest of the oscillator. The wiring does not match the schematic in this picture
because it was taken before connections were rearranged.




Operating the new version of the meter

With 8K of flash memory, I found it difficult to stop changing and adding little things, but I finally gave in to the definition of the project: An accurate simple LC meter that is easy to build.

When power is first applied, the meter checks to see if the "zero" button is being held down, which would indicate the user's intention of entering a calibration value of the reference capacitor for inductance measurements or the value of the reference capacitance for capacitance measurements. More about that later. In the normal case, that of not entering calibration a value the meter proceeds to display the firmware version and then pause a moment before proceeding.

In the capacitive measurement mode when power is first switched on, the meter proceeds to calibrate the capacitance measurement components and zero the meter and then starts taking continuous capacitive measurments.

In the inductance measurement mode when power is first switched on, the meter immediately starts continuous inductance measurements. The reason it does not go through an automatic inductance zero cycle is that it is unlikely that the test device terminals will be shorted when power is first applied.

The LED labeled "Power" (green in the photograph) winks out for a few tens of milliseconds once every 1.1 seconds to indicate that a measurement cycle has completed.

To zero the meter, if in the inductance mode short the test terminals, and press the zero button. The "Power" LED will go out as feedback that the pressing of the zero button was recognized and it will remain out until the end of the zero/calibration cycle.

Reference capacitor values are kept internally as a bit offsets that are added to internal constants. For the nominal 1,000 pf reference capacitance used to calibrate the capacitance measurements, the basic internal constant is 990 pf, and the offset can be incremented in 1 pf steps for a total range of 990 pf to 1245 pf. For the nominal 10,000 pf reference capacitance used in the inductance measurements, the internal constant is 9,900 pf and the offset can be incremented in 10 pf steps for a total range of 9,900 pf to 12,450 pf.

Here's how you enter the reference capacitance values:

To enter the reference capacitance used to calibrate capacitance measurements:

1. Start with  power off and the L/C switch in the "C" position.

2. Hold down the zero button while turning power on.
The display will read: 
Ref cap adj
cap=XXXpf

3. Release the zero button.

4. The value of the reference capacitance will increment by 1 pf each time the zero button is pressed.

5. Increment the value of the reference capacitance by repeatedly pressing and releasing the zero button until the desired value is obtained.

6. To store the reference value in EEPROM, slide the L/C switch to the "L" position.

7. To exit reference capacitor value entry without modifying the value previously stored in EEPROM, turn off the power without changing the position of the L/C switch.


To enter the reference capacitance used in inductance measurements:

1. Start with  power off and the L/C switch in the "L" position.

2. Hold down the zero button while turning power on.
The display will read: 
                    L Ref cap adj
                    cap=XXXXpf

3. Release the zero button.

4. The value of the reference capacitance will increment by 10 pf each time the zero button is pressed.

5. Increment the value of the reference capacitance by repeatedly pressing and releasing the zero button until the desired value is obtained.

6. To store the reference value in EEPROM, slide the L/C switch to the "C" position.

7. To exit reference capacitor value entry without modifying the value previously stored in EEPROM, turn off the power without changing the position of the L/C switch.








Gerd Sinning from Germany has contributed this helpful Windows-based tool for LC calculations. The program was checked and found clean, but  it is offered only as-is with no warranty, with all risks of use being born by the user. LCcalc tools for Windows.

HOME
(More Projects)
 
Contents ©2007, 2009 Richard Cappels; updated 13October, 2010. All Rights Reserved. Find updates at www.projects.cappels.org
LCD library copyright by Peter Fleury  http://homepage.hispeed.ch/peterfleury/  and may only be used for noncommercial purposes and is provided here with his permission.

First posted in December, 2007, updated May, 2009, NOvember 2010 (addition of LC calc tool).

You can send  email to me at projects(at)cappels.org. Replace "(at)" with "@" before mailing.



Use of information presented on this page is for personal, nonprofit educational and noncommercial use only. This material (including object files) is copyrighted by Richard Cappels with the exception of the LCD library, which is copyrighted by Peter Fleury, and may not be republished or used directly for commercial purposes without permission. For commercial license, for Richard Cappels' material click here. For permission to use Peter Flurey's LCD Library, please contact Peter Fleury directly at the email address on his web site, http://homepage.hispeed.ch/peterfleury/ .


  Liability Disclaimer and intellectual property notice
(Summary: No warranties, use these pages at your own risk. You may use the information provided here for personal and educational purposes but you may not republish or use this information for any commercial purpose without explicit permission.) I neither express nor imply any warranty for the quality, fitness for any particular purpose or  user, or freedom from patents or other restrictions on the rights of use of any software, firmware, hardware, design, service,information, or advice provided, mentioned,or made reference to in these pages. By utilizing or relying on software, firmware, hardware, design, service,information, or advice provided, mentioned, or made reference to in these pages, the user takes responsibility to assume all risk and associated with said activity and hold Richard Cappels harmless in the event of any loss or expense associated with said activity. The contents of this web site, unless otherwise noted, is copyrighted by Richard Cappels. Use of information presented on this site for personal, nonprofit educational and noncommercial use is encouraged, but unless explicitly stated with respect to particular material, the material itself may not be republished or used directly for commercial purposes. For the purposes of this notice, copying binary data resulting from program files, including assembly source code and object (hex) files into semiconductor memories for personal, nonprofit educational or other noncommercial use is not considered republishing. Entities desiring to use any material published in this pages for commercial purposes should contact the respective copyright holder(s).