Capmeter - Kapazitätsmessgerät mit dem AVR
Kapazitätsmessgeräte ("C-Meter") kann man kaufen. Man kann sich aber auch eines mit einem Mikrocontroller selbstbasteln.Auf der Suche nach einem nachbaufähigem Projekt im Internet bin ich auf das Projekt von Lars Pontoppidan (http://pontoppidan.info/lars/index.php?proj=capmeter) gestoßen. Das Gerät ist mit einem AVR-Controller aufgebaut und misst Kapazitäten zwischen einigen Picofarad und einigen Tausend Microfarad. Ich beschloß nach diesem Bauvorschlag vorzugehen. Das Gerät baut allerdings auf dem ATmega8 auf und es ist kein Platinendesign mitveröffentlicht. Daher habe ich mir dort im wesentlichen nur das Grundprinzip geholt und ein ähnliches Gerät mit dem ATmega32 aufgebaut. Die Software habe ich komplett neu geschrieben.
Im folgenden zunächst Erläuterungen in deutsch, dahinter meinen englischer Text aus dem Source-Code, der auch detaillierter auf die Software eingeht.
Theorie zum Messverlauf
Die Zeit, die ein Kondensator braucht, um aufgeladen zu werden steht in
einer Beziehung zur Kapazität des Kondensators. Während der Aufladung
gibt es einen Bereich, indem die Ladespannung linear ansteigt. Aus der
Steigung der Kurve kann man die Kapazität des Kondensators berechnen.Die folgende Skizze stellt den Messvorgang genauer dar. Der Kondensator wird entladen, dann wird mit dem Laden begonnen. Die Y-Achse stellt die Spannung, die am Kondensator erreicht wurde, dar. Die X-Achse ist die Zeit.
Verlauf einer Messung. Entladung bis deutlich unter Schwellwert 1 (T1).
Dann Start der Ladung des Kondensators. Messung der Zeitpunkte "Threshold 1 erreicht" und "Threshold 2 erreicht".
Aus den beiden Zeitwerten kann dann die Kapazitöt berechnet werden.
Der Ladevorgang startet in der Nähe von 0V, bei einem festen Spannungswert "Threshold 1". Die Ladung wird durchgeführt bis ein bestimmter weiterer Spannungswert "Threshold 2" erreicht ist. Die Zeit, die zwischen dem Durchgang durch die beiden Thresholds vergeht, wird gemessen.
Die beiden Threshold-Spannungen werden durch einen Spannungsteiler
aus der Betriebsspannung +5V gewonnen. Der Spannungsteiler stellt drei
Spannungen bereit.
Der zu messende Kondensator Cx wird über die Widerstände 1M8 bzw. 1K8 geladen. Die erreichte Spannung am Kondensator wird über den analogen Eingang AIN0 des AVRs gemessen. Die LED leuchtet im Original während des Messvorgangs.
Der oben erläuterte Referenzspannungsteiler wird an die analogen Eingänge ADC1..3 angeschlossen.
In blau ist der Anschluß eines Quarzes und an die Versorgungspannung dargestellt. Wenn man ein vorhandenes Experimentierboard wie das Pollin-Board einsetzt. braucht man diese Anschlüße nicht beschalten.
Am Port C wurde das LCD-Display (hier SEIKO 2432) angeschlossen.
Im folgenden ist beispielhaft der zeitliche Verlauf des Meßzykluses dargestellt.
Die Entladung erfolgt in etwa 25ms bis auf den Schwellwert 880mV des
Spannungsteilers (weiße Linie). Dann beginnt die Aufladung. Ist diese
(nach hier ca. 75ms) beendet, beginnt nach kurzer Zeit der Meßzyklus
von vorn. Bei der
gewählten Kapazität wird mit einer Frequenz von ~3,8Hz die Messung
wiederholt. Mit anderen Kapazitäten ergeben sich andere Zeitwerte, das Prinzip bleibt aber gleich.
Der gemessene Kondesnator hat einen aufgedruckten Wert von 6800µF. (Dieser Kondensator weicht relativ stark nach oben von seinem Sollwert ab)
Beim Belichten der Platine habe ich nur eine Transparentfolie
(statt der empfohlenen übereinanderliegenden zwei oder drei) verwendet. Die Platine hat daher viele kleine Löcher im Kupfer, war
nach Prüfung mit dem Ohmmeter aber
dennoch verwendbar.
Einbau in ein Gehäuse: Das LCD-Display wird ins Gehäuse eingeklebt.
Die Platine mit dem AVR wird mit Abstandsbolzen befestigt und die
Lochrasterplatine aufrecht stehend angebracht.
Capacitance Meter with AVR
Introduction
This code implements a capacitance meter using an AVR and some external parts. The idea and the hardware is based on the capmeter described at: http://pontoppidan.info/lars/index.php?proj=capmeter
The capmeter is able to measure from small capacitors of some picofarads up to large ones of at least >7000microfarads. My largest Capacitor is 6800 Microfarads (which measures itself as a 7200uF value), so I cannot test it for larger values than this. I assume that even values of lets say 50000uF can be measured.
Usage
Automatic calibration
Switch the device on. The device does a self calibration at startup (displaying this state as "Calibration" at the LCD display). During self-calibration, nothing should be attached to the probes (otherwise all subsequent measurements will display wrong results). After calibration, the device enters the measurement loop.
Doing Measurements
After calibration finished, the device will just repeat measurements. If nothing is attached to the probes, the device will display "0pF". If something is attached to the probes, it will display the state of the measurement and the last result measured. Measurement time increases with cap size, a large cap will need some seconds to be measured.
These are all things to be known for doing measurements.
Hardware
See config.h for pin assignments. This software uses 4 Pins.
- Discharge Pin and Analog Comparator Pin (both functions on one pin)
- Charge Pin for "high current" charging (via 1K8 resistor)
- Charge Pin for low current charging (via 1M8 resistor)
- LED Pin. Led lights during measurement. Not very important, because the LCD shows the same info.
For charging there are two resistors and for discharging there is one resistor.
Basic idea is to measure the time that is needed by the capacitor-in-measurement ("CX"). to be loaded from one voltage level to a higher voltage level. The time is somewhat proportional/linear to the capacity.
Time measurement is done incrementing a timer start running if the load crosses the lower threshold (voltage level) and stop running if the higher threshold is crossed.
Because for small capacities the time for loading is very short, for these the low current charging is used. For high capacities the "high current" charging is used. All measurement cycles are started assuming a small cap. The cap is loaded with low current. If a timeout is reached without having crossed the higher threshold, it is assumed that the cap is a large one. Then the cap is discharged and loaded with high current.
Theory of operation
The loading of a capacitor via a resistor is e.g. described here: http://en.wikipedia.org/wiki/RC_time_constant (German: RC-Glied, http://de.wikipedia.org/wiki/RC-Glied)
The time constant "tau" can be calculated from
tau = R*C.
The voltage at the capacitor during loading is described by the formula:
U(t) = Umax * (1 - e^(-t/tau))
This can be changed to
t = -tau*ln(1-U(t)/Umax)
Using the voltages resulting from the resistor network, the following values for t can be calculated: (All these things are taken from http://pontoppidan.info/lars/index.php?proj=capmeter, all credits go to Lars Pontoppidan. I just repeated it to understand what he was doing.)
Ti=Threshold i
All Values "x" in the table should be used as "tau*x"
Ti | t for 0..Ti | t for Ti-1..Ti | T for T0..Ti
----+---------------------------------------------
0 |0.191891 | - | -
1 |0.43261 | 0,2401 | 0.2401
2 |0.7461127 | 0.313502 | 0.554
Umax=5,04V (from a 7805 voltage regulator).
The timer creates a time value "tclocks".
What we need is a formula capacitance = f(tclocks).
For the interested reader, to get that, please follow the next steps:
The time t actually spent in charging can be derived from tclocks using the xtal frequence of the AVR "F_CPU":
0. t=tclocks/F_CPU
For tau we know two things:
1. tau*K = t , where K is 0,2401 or 0,554 from the table above
2. tau=R*C
Using these three input formulas 0,1 and 2, we can proceed:
C=tau/R (using 2.) = t/(K*R) (using 1.) = tclocks/(K*R*F_CPU) (using 0.)
For low current charging, R=1800 Ohms. For high current charges, R=1.800.000 Ohms. (You can measure and use the real values of your resistors with a good ohm-meter to get the best results).
So we have everything to calculate C from tclocks value.
Software
The software uses the UART lib for rs232 output and the LCD Lib for LCD access. These two libs are from Peter Fleury.
The software offers some basic functions to control the ports:
- discharge()
- charge()
- led()
- charging via high pin (high current mode, via 1K8 resistor)
- charging via low pin (low current mode, via 1M8 resistor)
- supporting discharge using internal pullup resistors of AVR (not really a "charge" mode)
- init_devices()
- init_timer()
- init_comparator()
- init_vars()
- init_uart()
- do_measure()
- do_discharge()
Finally there is main(), which does:
- Initialisation
- Calibration
- Repeat measuring cycle
- Print out on LCD and RS232
- Discharge cap below lower threshold
- Charging using low current from LO to MID Threshold
- If a result can be measured, it is print out and the cycle starts from beginning
- If no result could be got (a timeout was reached), cap is discharged again
- Charging using high current from MID to HI Threshold
- If a result can be measured, it is print out and the cycle starts from beginning
- Anyway, the cycle starts from beginning
In fact, calibration eliminates the capacity created by the board, the probe cables etc.
During the calibration, displays second line shows the text "Calibration...".
Weiterführende Links