e013022.PDF
(
79 KB
)
Pobierz
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
BEGINNERS’
COURSE
PC Serial Peripheral
Design (7)
voltage measurement
By B. Kainka
In previous articles in this series we have described an A/D converter
based on a counter. A ‘real’ A/D converter, however, converts a voltage into
a measured value. Usually, this is thought to require an IC; however, as
we shall see, a much simpler alternative is available.
A real A/D converter with a voltage
input can be constructed using a sin-
gle transistor. The transistor in
Fig-
ure 1
operates as a comparator, com-
paring the voltage on the capacitor
with a reference value, here 0.7 V.
The capacitor is alternately charged
and discharged by the DTR output
via a resistor, in such a way that the
voltage across it is always near to
the comparator reference. Depend-
ing on the input voltage the output
will need to be turned on more or
less frequently in order to establish
the desired voltage. The count of
these events leads to the converted
value.
Figure 2
shows how the cir-
cuit can be constructed.
RI falls. Conversely a lower capaci-
tor voltage turns off the transistor
and RI goes high. The measurement
loop must drive the voltage on DTR
in the opposite direction: when the
voltage is too low, DTR must be
turned on; when it is too low, DTR
must be turned off, setting the out-
put voltage to –10 V. It is important
that the switching happens at pre-
cisely regular intervals, for example
exactly one per millisecond. The
number of millisecond periods for
which DTR is turned on must be
counted. If no input voltage is pre-
sent, we might expect that the posi-
tive and negative states of DTR
would be equally common, making
the averaged voltage across the
capacitor zero. If we look a little
more closely, however, we see that
we need to consider the threshold
voltage of the transistor (about
0.7 V), and so the positive state will
be slightly more frequent. With an
applied voltage the ratios change.
The charging current from the DTR
signal must compensate for the
charging current from the input.
A negative input voltage leads to
more positive DTR states, and con-
DTR
+10V
RTS
R1
R3
R I
T
R2
1k
R4
27k
C
–6 ...+10V
47µ
GND
000074 - 7 - 11
Figure 1. The simple A/D converter
K1
A/D converter program
000074-1
T BC548
10
9
8
7
6
5
4
3
2
1
GND
RI
R2
CTS
The program in
Listing 1
contains a
loop which attempts to keep the
voltage across the capacitor as close
as possible to the comparator refer-
ence voltage. Information on the
voltage across the capacitor is avail-
able on the RI input: if the voltage
lies above the switching threshold of
the transistor (about 0.7 V), a collec-
tor current flows and the voltage on
C
RTS
DSR
R1
GND
R3
DTR
R4
TXD
RXD
DCD
000074 - 7 - 12
Figure 2. Voltage measurement with the simple
A/D converter.
22
Elektor Electronics
3/2001
BEGINNERS’
COURSE
Listing 1. Conversion of an 8 bit value
Private Sub Form_Load()
i = OPENCOM(“COM2,1200,N,8,1”)
If i = 0 Then
i = OPENCOM(“COM1,1200,N,8,1”)
Option1.Value = True
End If
If i = 0 Then MsgBox (“COM Interface Error”)
RTS 1
DTR 1
Counter1 = 0
Timer1.Interval = 500
End Sub
Private Sub Form_Unload(Cancel As Integer)
CLOSECOM
End Sub
Private Sub Option1_Click()
i = OPENCOM(“COM1,1200,N,8,1”)
If i = 0 Then MsgBox (“COM1 not available”)
RTS 1
DTR 1
End Sub
Figure 3. Display of digitised value.
Input
Display
Private Sub Option2_Click()
i = OPENCOM(“COM2,1200,N,8,1”)
If i = 0 Then MsgBox (“COM2 not available”)
RTS 1
DTR 1
End Sub
open
118
0 V
110
–3.6 V
68
+3.6 V
152
Private Sub Timer1_Timer()
RTS 1
DTR 0
U = 0
TIMEINIT
While (RI() = 0) And (TIMEREAD() < 300)
Wend
TIMEINIT
For n = 1 To 255
If RI() = 1 Then DTR 1 Else DTR 0: U = U + 1
While TIMEREAD() < n
Wend
Next n
DTR 1
Label1.Caption = Str$(U) + “ “
End Sub
We can see that an open-circuit input does
not display zero, but a rather higher value.
Comparing the measurement results for the
voltages -3.6 V, 0 V and +3.6 V, we can imme-
diately see that the difference between the
negative voltage and zero is 42, as is the dif-
ference between the positive voltage and
zero. This is encouraging, since it indicates
that the converter is linear.
The digital values can now be converted
into voltages. The following calculation does
the trick:
Voltage = (Display – 110)/11.2
This expression contains the measured zero
value and a multiplicative factor giving the
number of digital steps per Volt. Both these
values will vary from circuit to circuit. It is
therefore worthwhile calibrating the circuit.
Program AD2.frm (
Listing 2
) provides two
slider controls which start off at preset val-
ues. The left-hand slider, with a range of 105
to 115 and an initial setting of 110, sets the
zero offset. The right-hand slider, with a
range of 124 down to 100 and an initial set-
ting of 112, sets the slope. To use the program
first short the input leads together and set
the zero offset slider appropriately. Then a
known voltage must be applied to the input,
and the display set to the correct value using
the right-hand slider. The A/D converter con-
structed here uses as a reference the voltage
on the DTR output, which is not particularly
versely, a positive voltage leads to
more negative DTR states.
The program starts by setting
DTR to 1. This is important to ensure
that the capacitor is not charged
with the wrong polarity. The voltage
across the capacitor does not rise
above about 1 V, however, because
the base-emitter diode in the tran-
sistor starts to conduct. In this qui-
escent state the transistor is fully
turned on. In the measurement pro-
cedure proper, Timer1.Timer, a new
measurement is carried out ever
500 ms. Initially DTR is turned off
until RI changes state for the first
time. At this point the voltage across
the capacitor is equal to the thresh-
old voltage of the transistor. This
first loop has a timeout condition to
trap errors and runs for at most
300 ms.
The main measurement loop is
executed exactly 255 times, during
which the number of cases where
DTR is low is counted. The measure-
ment always lasts 255 ms and pro-
duces 256 different possible results
from 0 to 255 (
Figure 3
). This gives
the same resolution as an 8-bit A/D
converter.
Testing and calibration
Our first test delivered the following
results:
3/2001
Elektor Electronics
23
BEGINNERS’
COURSE
Listing 2. The modified Timer procedure in AD2.frm
Private Sub Timer1_Timer()
RTS 1
DTR 0
U = 0
REALTIME (True)
TIMEINIT
While (RI() = 0) And (TIMEREAD() < 300)
Wend
TIMEINIT
For n = 1 To 255
If RI() = 1 Then DTR 1 Else DTR 0: U = U + 1
While TIMEREAD() < n
Wend
Next n
REALTIME (False)
U = (U - HScroll1.Value) / HScroll2.Value * 10
U = Int(U * 10) / 10
DTR 1
Label1.Caption = Str$(U) + “ V”
End Sub
Figure 4. A complete voltmeter.
constructed from a simple NPN
transistor is not 0 V, bit rather
about 0.7 V. The exact value
depends on the chosen transistor
and on temperature. A tempera-
ture variation of one degree Celsius
changes the threshold by about
2mV.
– The ratio of the two 27 kΩ resistors
affects the measurement; but if 5 %
tolerance types are used, the con-
tribution will be dominated by the
other sources of error.
– The measurement results do NOT
depend on the exact value of the
capacitor. This is a particular
advantage of this measurement
method. Even if a 100 µF capacitor
is used in place of the 47 µF capac-
itor, the results are not affected.
It is relatively straightforward to
improve on the design of the com-
parator (
Figure 6
). Instead of a sin-
gle transistor, two are used. The pair
of NPN transistors forms a differen-
tial amplifier, similar to the input
stage of an operational amplifier. In
this way the DC base-emitter volt-
age is reduced to a few millivolts.
Temperature variation is no longer a
problem because the two transistors
are affected to the same extent. The
total emitter current through the
4.7 kΩ resistor is about 2 mA. When
the input voltage is zero the current is
Figure 5. Voltage plotter Plotter2.frm.
reliable. Recalibration is therefore often nec-
essary.
Figure 4
shows the program in action.
This simple A/D converter is reasonably
accurate and reliable. The resolution is about
0.1 V, and the measurement range is about
–6 V to +9 V. This can already find practical
application, for example in testing batteries,
and becomes all the more useful when the
input voltage can be plotted (
Listing 3
).
There are many other applications.
Figure 5
shows the measured voltage across a capac-
itor being briefly negatively and positively
charged. The characteristic exponential dis-
charge curves can be clearly seen.
DTR
+10V
RTS
R1
R3
Hardware improvements
DSR
When the possible sources of error in our sim-
ple A/D converter are considered, we can see
that there are practically no aspects that can-
not be improved.
T1
T2
R4
27k
D
C
–10 ...+10V
47µ
GND
– The basic accuracy depends on the voltage
on the serial interface. It would be better to
use a proper voltage reference, although
that would make the circuit rather more
complicated.
– The switching threshold of a comparator
R2
–10V
000074 - 7 - 16
TXD
Figure 6. The improved comparator.
24
Elektor Electronics
3/2001
BEGINNERS’
COURSE
input transistor no longer limits the voltage
across the capacitor during intervals between
measurements, and so this voltage will rise.
For this reason a silicon diode is included to
limit the voltage to 0.6 V. The effect of all of
these changes is that an open-circuit input
gives a reading of zero, and that the mea-
surement range is extended to 10 V with
either polarity.
Figure 7
shows the construc-
tion of the improved converter.
Listing 3. Plotter procedures Plotter2.frm
Dim y1, y2, x1, x2, n
Private Sub Command1_Click()
n = 0
End Sub
Private Sub Timer1_Timer()
RTS 1
DTR 0
U = 0
REALTIME (True)
TIMEINIT
While (RI() = 0) And (TIMEREAD() < 300)
Wend
TIMEINIT
For i = 1 To 255
If RI() = 1 Then DTR 1 Else DTR 0: U = U + 1
While TIMEREAD() < i
Wend
Next i
REALTIME (False)
U = (U - HScroll1.Value) / HScroll2.Value * 10
DTR 1
y2 = 100 - U * 10
If n = 0 Then y1 = y2: Picture1.Cls
x1 = n
n = n + 5
x2 = n
Picture1.Line (x1, y1)-(x2, y2)
y1 = y2
End Sub
Software optimisations
Changes are also needed in the software.
First it must be taken into account that the
DSR input signal is read in the inverted
sense: the input is high when the capacitor
voltage is above the threshold voltage. The
improved characteristics of the measurement
circuit also make it worthwhile to increase
the accuracy of the measurements. The main
loop is now executed 1000 times.
Listing 4
shows the results. With a total input range of
20 V we have a resolution on 0.02 V. As seen
in
Figure 8
, a further decimal place can be
shown on the display.
(000074-7)
K1
000074-1
C
divided equally between the two
transistors. The voltage drop across
the collector resistor of the second
transistor is about 10 V, and so the
collector voltage remains around
zero and close to the switching
threshold of the DSR input.
Unlike in the original circuit, the
GND
10
9
8
7
6
5
4
3
2
1
T2
47
µ
RI
D
R
1
CTS
RTS
DSR
T1
GND
R2
DTR
R3
TXD
RXD
DCD
R4
Listing 4. Measurement routine
with 1000 quantisation steps
000074 - 7 - 17
Figure 7. Construction of the improved
comparator on the prototyping board.
Private Sub Timer1_Timer()
RTS 1
DTR 0
U = 0
REALTIME (True)
TIMEINIT
While (DSR() = 1) And (TIMEREAD() < 300)
Wend
TIMEINIT
For n = 1 To 1000
If DSR() = 0 Then DTR 1 Else DTR 0: U = U + 1
While TIMEREAD() < n
Wend
Next n
REALTIME (False)
U = (U - HScroll1.Value) / HScroll2.Value * 10
U = Int(U * 100) / 100
DTR 1
Label1.Caption = Str$(U) + “ V”
End Sub
End Sub
Figure 8. Result displayed to two decimal
places.
3/2001
Elektor Electronics
25
Plik z chomika:
gasma
Inne pliki z tego folderu:
bge.jpg
(26 KB)
detail1.htm
(5 KB)
detail2.htm
(4 KB)
detail3.htm
(4 KB)
detail4.htm
(6 KB)
Inne foldery tego chomika:
1974
1975
1976
1977
1978
Zgłoś jeśli
naruszono regulamin