Project
The time that the capacitor takes to reach half of the
applied value, t1/2 is:
t1/2 = RCln(2)
As the MicroConverter has measured t1/2 and R is
known, it is easy to determine C. In fact:
C = t1/2
Rln(2)
Practical Matters
C = 0.0000694N = 0.0000694N ≈ 10NnF
100001n(2) 6931.5
With the timer set like this, no calculations need to be
done. The number of cycles determines the capacitance
in a very simple way. In order for a measurement to be reasonably accurate, should be at least 10. In order that the
measurements not take too long, should not be too large. I
allowed up to 10,000. Thus, the capacitances for which this
simple meter can be used range from 100 nF to 100 µF. The
range can be adjusted by changing the value of the resistor.
Fundamentally, this capacitance meter is easy to
build. The devil is in the details. Calculating is no problem
at all if you have a microprocessor that knows how to
divide. Unfortunately, the 8052 barely knows how to multiply. To avoid the necessity of multiplying or dividing, I
played a simple game. I set the timer to overflow every
0.0347 milliseconds. Thus, to overflow twice took the
timer 0.0694 milliseconds. I had the microprocessor keep
track of how many such periods went by from the time
that 2.5 V was first applied to the resistor until the voltage
on the capacitor rose to 1.25 V. (That is how the
MicroConverter stores the elapsed time.) Let the number
of periods that elapsed be N. Then, t1/2 = 0.0694N. Let us
see what that says about C as a function of N. Plugging
in the values we find that:
The Physical Connections
In order to connect the resistor and capacitor to the
correct pins on the development kit, you must know
where each of the lines that is called for is physically
located. The analog ground of the circuit is available in
the prototyping area of the development kit on a strip
labeled 'AGND.' For the A/D and the D/A connections,
look for the ANALOG I/O connector on the development
kit. This connector is clearly labeled and is located
between LK1 and LK2. The first channel of the A/D
(ADC0) is led off to the leftmost pin on the row of pins
that is nearest to the edge of the development kit. The
first channel of the D/A (DAC0) is led off to the third-to-last pin on that row of the ANALOG I/O connector.
Thinking Smarter — Not Working Harder
F
o
r
E
l
e
c
t
r
o
n
i
c
s
NUTS & VOLTS
E
v
e
r
y
t
h
i
n
g
Many microcontrollers either do not support division or support division to a limited extent. And even when they do, it is often
a time-consuming operation. In the case of 8051 type microcontrollers, division of two eight bit words takes four instruction clock
cycles to execute. (Multiplication and division are the only operations that take so long.) To do 16 (or more) bit division takes more
time and is more complicated.
When time needs to be measured, it is best to set up your
time-base in a fashion that minimizes the need to use expensive or
complicated operations. One operation that can often be simplified
is the calculation of a quantity that depends directly on a measurement of time. In order to measure capacitance, we measure a
time — t1/2 . We have seen that:
t C = 1/2
R1n(2)
We want to make sure that the calculation of the capacitance
is as simple as possible. Suppose that you check the voltage at the
output of the RC filter every τ seconds. Then the first time for
which the voltage is greater than half the input voltage is t1/2 = Nτ.
Thus, the capacitance is:
τ
C= N
R1n(2)
In order to avoid the need to perform any calculations, and to
calculate the capacitance from N, you must choose the values of the
resistor and the sampling time in such a way that:
τ
R1n(2)
is particularly "nice."
Suppose, for example, that you would like to measure capacitances that are between 1 µF and 1 nF. Ideally, you would like to
have N be reasonably large, even for 1 nF. Let us suppose that we
would like N = 10 when C = 1 nF. Then we find that:
1x10-9 = τ 10
0.69315R
That is:
t = 6.9315x10-11R
On practical grounds, we do not want to choose odd resistor
values, nor do we want to have to sample too often. Suppose that
we take R = 1MΩ. Then, we find that τ = 6.9315x10-5. Setting our
sample rate to 1/τ = 11,427 samples per second will do the trick.
With this sampling rate and resistor value, the capacitance measured will be C = 10 NnF. Displaying such a value (as we do in the
accompanying program for the ADuC812) is a triviality. We converts the number N into a string and then add a "0" to the end of
the string. The string now holds the capacitance in nanofarads, and
no calculation was performed.
44
FEBRUARY 2004