In general the ADC embedded in the ST7 microcontroller is enough for most applications.
But, in some cases it is necessary to measure both positive and negative voltages. This
requires an external ADC with this particular capability. Most external ADCs require a dual
supply to be able to do this. However, microcontroller-based applications usually only have a
positive supply available.
This application note describes a technique for implementing an ADC for measuring both
positive and negative input voltages while operating from a single (positive) supply. This
converter is based on a voltage-to-time conversion technique. Like other slope converters,
this ADC also uses an integrating capacitor, but the measured time is inversely proportional
to the input voltage. An additional comparator with a voltage reference is used to improve
conversion accuracy.
As shown in the circuit diagram(Figure 1 on page 6), the converter is implemented using an
integrating capacitor, resistor, external op-amp, comparators and some microcontroller I/O
pins. The ST72F264 microcontroller is used in this application note as an example, but the
implementation is feasible using any ST7 microcontroller. The 16-bit timer of the
microcontroller measures the time using its input capture pins (PB0 and PB2). These pins
are connected to the output of the Comp1 and Comp2 comparators. The I/O pins PB1 and
PB3 are used to switch the M1 and M2 switches on or off. The circuit could also work with a
microcontroller equipped with an 8-bit timer. Only a small modification to the software would
be needed.
is the input voltage. The voltages across resistor R are the reference voltage V1 and the
in
input voltage V
op-amp. Therefore, for a given input voltage, the current flowing through resistor R is
constant. Let this current be I.
Current I charges the capacitor C, and output starts increasing in a positive direction for the
input V
<= V1 (input Vin > V1 charges in the opposite direction).
in
The output is captured at two instants using the two output comparators at voltage
references V
respectively. The final reading of time T
The input voltage is calculated from this difference through the formulae given in the circuit
analysis.
This technique can only be used where the input voltage varies slowly, otherwise the
charging of the capacitor is non-linear.
2.1 Advantage of using two comparators
. Due to the properties of the op-amp, V1 is output on the inverting pin of the
in
and V3. The time corresponding to voltage levels V2 and V3 are T2 and T3
2
is taken as the difference of T3 and T2.
m
The purpose of using the second comparator (comp2) can be understood from the diagram
below (Figure 2), which shows the relationship between the op-amp output (Amp in
Figure 1: Circuit diagram on page 6) and the time for a given input value.
Figure 2.Relationship between V
V
out
V3
V2
V1
and time for a given input
out
Point o f
uncertainty
T2
T
m
T3
Time (t)
The time is measured as the difference of the two timer readings (T3 -T2) for the same
slope. So factors like the residual voltage of the capacitor ( V
(0+)) and any other constant
c
errors (like the effect of output offset voltage) on the output side of the op-amp are
subtracted. So its performance is better than a single-slope converter.
7/37
Timing diagramAN2615
3 Timing diagram
Figure 3 shows the overall operation of the ADC. Initially the capacitor is in the reset state
(M1- on and M2- off), the op-amp output V
comparators, Comp1 and Comp2 is high.
Capacitor charging can be started by switching M1 - off and M2 - on. When the charging
starts, V
rises. When V
out
becomes greater than V2, a falling edge occurs on Comp1. This
out
causes an input capture at pin PB2 and software reads the timer value T
When V
becomes greater than V3, a falling edge occurs on Comp2. Again this causes an
out
input capture at pin PB0 and software reads the timer value T
The capacitor is discharged by switching M1 - on and M2- off. After this, the ADC can be
kept in reset condition by switching M1 - on and M2 - off or we can continue repeating the
same process and make more measurements.
Figure 3.Timing diagram
is at V1 and so, the output of both
out
2
.
3
.
V
out
V3
V2
V1
Comp1
Comp2
M1
M2
Charging
0
T2
time
T
m
Discharg.
time
T3
Settling
time
Time (t)
T
m
8/37
AN2615Circuit analysis
4 Circuit analysis
In this analysis, it is assumed that there is no noise present and the i/p offset voltage of the
op-amp is negligible.
I = (V
– Vin)/R = C * dVc/dt
1
Where, V
Applying the Laplace transform:
or,
Applying the inverse Laplace transform, we get
As shown in Figure 3: Timing diagram on page 8
So,
And,
Equation (2) and equation (3) can both be used as the characteristic equation for this
converter, but factors like Vc(0+) and other constant errors remain present. But if we use
both comparators, then we can remove these factors by subtracting equation (2) and
equation (3).
= V
c
(V
– Vin)/s * R = C * (s Vc(s) – Vc (0+))
1
(V
– Vin)/s2 = (R * C) * ( Vc (s) - Vc(0+)/s)
1
(V
– Vin) * T = (R * C) * ( Vc(t) - Vc(0+) )------------------- (1)
1
At T = T
– V1 and current ‘I’ is constant for a given input.
By using equation(5) we can measure the value of V
- T2 = Tm and we get:
3
m
9/37
------------------- (5)
depending on the value of T3 and T2.
in
V
vs time diagram for different input voltagesAN2615
out
5 V
In Figure 4, we can see the relationship between the V
voltages. From the figure, it is clear that the conversion time for a negative input voltage is
less than the time taken for a positive input voltage.
Figure 4.V
1. T
2. This ADC works for the range Vin <= V1 but if the input voltage is greater than V1 the direction of current I is
3. For negative voltage currents I, that depend on the difference V
vs time diagram for different input voltages
out
and time for different input
out
vs time for different input voltages
out
Effective time Tm = T - T’
< 0Vin =0Vin > 0
V
in
V3
V
out
V2
V1
T1’ T2’ T1 T3’T2
Time (t)
1: for Vin < 0; Tm2: for Vin = 0; and Tm3: for Vin > 0 (where Tin1 < Tin2 < Tin3)
m
inverted and the capacitor starts charging in the opposite direction and conversion never takes place.
- Vin, is high, so the charging time for
negative voltages is less than the positive voltages.
1
T3
10/37
AN2615Characteristics of different slope converters
6 Characteristics of different slope converters
6.1 Single-slope converter
Figure 5.Single-slope converter circuit diagram
C
R
-V
ref
V
INT
V
in
6.1.1 Single-slope converter timing diagram
Here Vin is directly proportional to the time measured.
Figure 6.Single-slope converter timing diagram
V
in
Time
1. Here Vin = K * T
m
The major sources of conversion errors are the correction factor for the R*C product and the
input offset voltage.
A single-slope converter requires a dual supply voltage op-amp to be able to measure the
positive and negative voltages.
11/37
Characteristics of different slope convertersAN2615
6.2 Dual-slope converter
Figure 7.Dual-slope converter circuit diagram
S0
-V
in
V
ref
S1
R
1
out
3
2
gnd
gnd
6.2.1 Dual-slope converter timing diagram
As shown in Figure 8 a dual-slope ADC has a charging phase followed by a fixed rate
discharging phase.
Figure 8.Dual-slope converter timing diagram
Charging phaseFixed-rate discharge
Vin1
V
2
in
-V
ref
-V
ref
clk
Control logic
S1S2
1
out
2
cmp
ctr
enbl
clk
clk
Counter
V
in
V
ref
=
T
charge
T
discharge
The advantage of a dual-slope ADC is that it is not dependent on the correction factor for the
R*C product. However, the input offset voltage problem still persists and this ADC also
requires a dual supply op-amp to be able to measure positive and negative voltages.
12/37
Time
AN2615Characteristics of different slope converters
6.3 Solution presented in this application note
In this application note, a single supply ADC for positive and negative input voltages is
described. It's input voltage is proportional to the inverse of the time measured. We can see
in Figure 9 below that as the input voltage becomes closer to V1, the conversion time also
increases. For an input of V
input voltage range depends on the value of V1 and the maximum delay that the application
can tolerate.
, the conversion time is infinite (1/T
1
= 0 in Figure 9). So the
m
Figure 9.V
1. Vin = V1 - (R * C) * (V3 -V2) /T
versus time in AN2615 solution
IN
V
in
+V
Positive
input
V
1
ref
V0
-V
ref
m
Negative
input
Total input range (+V
1/T
m
ref
to -V
)
ref
The significant advantage of this ADCis its ability to measure positive and negative input
voltages operating from single supply, while other solutions require a dual supply. Also this
converter does not require any negative voltage reference. Again, as in the single slope
converter, the major sources of error are the correction factor for R*C product and the input
offset voltage.
As shown Figure 9, the ADC is capable of measuring the input voltage ranging +V
where the absolute value of V
the value of V
.
1
is mod (V
ref
) < V1 so the input voltage range depends on
ref
ref
to -V
ref,
13/37
Error analysis/constraintsAN2615
7 Error analysis/constraints
ThisADC can be used for measuring any slowly varying input (voltage/current), for example
battery monitoring, and for measuring positive and negative input voltages. But, besides the
need for accurate power supply and voltage references, the following factors also affect the
accuracy of the conversion.
7.1 Input offset voltage
As mentioned previously, the output offset voltage is subtracted from the input, but the input
offset voltage of the op-amp (Amp) still remains present and is directly added to V
measurement purposes, let us refer to the input offset voltage of the op-amp as K
7.2 Correction factor for the product of R*C
As the value of the R and C changes with time and temperature, the factor R * C also
changes. Let the correction factor be K
Then eq(5) becomes,
V
= V1 + K
in
The coefficients K
values. These factors can also be compensated by software calibration techniques (like
using look-up tables or storing some known values). In the present example the first method
is used to calculate these coefficients.
offset
offset
– K
gain
and K
* (R * C) *(V3 -V2)/Tm------------------ (6)
can be calculated by measuring Tm for two known input
gain
gain
.
. For
1
offset
.
7.3 Value of charging resistance R
If the charging resistance ‘R’ is too high then the current ‘I’ is comparable to the input bias
current of the op-amp, which can affect the output. Also if it is too low then the current
flowing through it is significant so the capacitor is charged very fast. This affects the
measurement accuracy of the ADC.
7.4 Charging capacitor C
Up to this point we have assumed that capacitor C discharges completely from the previous
conversion. However, this is not so in actual practice and a few millivolts worth of charge
(which adds to the offset voltage), may remain on the capacitor. This effect is called
capacitor dielectric absorption and varies depending on the capacitor's dielectric material
voltage to which it was charged during the last charge cycle and the amount of time the
capacitor has had to discharge. Also due to this effect, the output of the capacitor may not
be linear over the whole conversion range. So it is very important to choose the right
capacitor for your requirements. While Teflon capacitors exhibit the lowest dielectric
absorption, polystyrene and polyethylene are also excellent. Ceramic, glass and mica are
fair, while tantalum and electrolytic types are poor choices for A/D applications.
Also, as integrating ADC’s are dependent on the integration of the current flowing through
capacitor C, they do the averaging. So, the larger the value of the capacitor, the longer the
14/37
AN2615Error analysis/constraints
conversion time and the better the accuracy. In conclusion, there is always a trade-off
between conversion time and accuracy.
7.5 16-bit timer
A 16-bit timer is used as the counter that measures the conversion time. Overflows are also
taken into account, so we can also use an 8-bit timer. The resolution of the ADC depends on
the operating frequency of the timer.
7.6 Effect of temperature
The value and characteristics of each component varies with temperature. The effect of
temperature can be broadly categorized as ‘offset drift’ and ‘gain drift’. So we need to
compensate the ADC for each significant change in temperature.
7.7 Comparator
The comparators are the cornerstone of the A/D conversion process. The ability of the
comparator to detect small voltage/current changes makes the comparator very important in
the A/D conversion process. Any degradation of the intended behaviour of the comparator,
which is most usually caused by unwanted noise, leads to the degradation of the ADC’s
ability to measure low voltages.
15/37
Voltage referencesAN2615
8 Voltage references
The following circuit is used to produce the different voltage references.
Figure 10. Voltage reference
V
DD
+5V
Gnd
R1
R2
C1
C2
V
ref
16/37
AN2615Hardware setup
9 Hardware setup
Figure 11. Hardware setup
ST72
TD0
RS232 communication
Hyper terminal
RS232
interface
V
in
0134.85 mV
Multimeter
V
DD
External
ADC
Gnd
Comp1
M1
Comp2
M2
V
DD
PB0
PB1
PB2
PB3
Gnd
Application board
The external ADC is interfaced to the ST7 microcontroller The input capture pins PB0 and
PB2 are used for capturing the pulse from the comparators at two instants (when the output
is equal to V
and V3 respectively), while PB1 and PB3 are used for controlling the voltage
2
at the gate of the M1 and M2 switches (on/off the MOSFET). The results of the A/D
conversion are displayed on the Windows hyper terminal application through an RS232-SCI
interface. The general schematics of the board are given in Appendix B: Application board
schematics on page 31.
17/37
AlgorithmAN2615
10 Algorithm
Figure 12. Algorithm flowchart
Start
Initialize I/O,timer and SCI
Calibrate the ADC
Count = 16
1 second delay
Start conversion
Conversion complete?
Ye s
No
Start new conversion
1 second delay
Convert the timer reading in to voltage and send the
result on the PC through SCI-RS232 interface
Decrement count
Count > = 0?
Ye s
Calculate the average and display on the
PC through SCI-RS 232 interface
No
18/37
AN2615Result
11 Result
The result is given for a capacitor value of 100 µF. So the conversion time is long. The
conversion time can be reduced by choosing a capacitor with a lower value but accuracy is
also reduced. Other parameters are as follows:
R = 10 K, V
So:
R * C = (10 K) * (100 µF) = 1 s
= 1.5 V, V2 = 2V and V3 = 3 V
1
The input range is taken as +1V to -1V, where mod (V
The conversion time is in the range 1 to 3 s. The settling time (as shown in Figure 3: Timing
diagram on page 8) is fixed at 1s. The ADC is calibrated by reading two known input
voltages afterwhich K
voltage source.
11.1 Positive input
In Figure 13, an example of the readings measured by the converter, which are sent to the
hyper terminal, are shown. T
value in terms of voltage. The difference of the maximum and minimum value among the 16
values is also shown.
Figure 13. Results for positive input
offset
) (= 1 V) is less than V1.
ref
and K
avg
are calculated. The input voltage Vin is taken from a
gain
is the average of 16 conversions, and V
is the calculated
avg
19/37
ResultAN2615
In Ta bl e 1 , the readings are shown for positive input voltages ranging from 0 to 1 V. V
voltage measured by the multimeter. V
measured
(equal to V
) is the average voltage
avg
is the
in
measured by the converter in a loop of 16. The last column shows the difference in the
maximum and minimum readings of the values measured by the converter in the loop. This
shows the variations recorded in the readings.
Table 1.Results for positive input voltages
Sl no
V
in
(taken from multimeter)
V
measured
(mV)
Difference (mV)
(V
measured
- Vin)
(mV)
18.938.9300.45
218.9418.980.040.25
328.8228.870.050.21
438.7238.780.060.39
549.0749.130.060.46
658.9359.020.090.38
768.8268.920.10.08
879.1279.250.130.39
988.9889.070.090.33
1098.8598.980.130.12
Error in max and min
input measured in the
loop (mV)
11108.75108.90.150.37
12119.05119.190.140.43
13128.95129.130.180.29
14138.57138.760.190.24
15158.75158.960.250.25
16178.97179.180.210.4
17198.68198.910.230.1
18218.83219.10.270.37
19239.08239.350.270.34
20258.55258.830.280.14
21278.8279.110.310.19
22299.02299.340.320.31
23318.68319.090.410.37
24338.93339.290.360.35
25358.38358.780.40.39
26378.62378.980.360.36
27398.85399.250.40.27
28438.84439.230.390.15
29478.64478.930.290.35
20/37
AN2615Result
Table 1.Results for positive input voltages (continued)
Error in max and min
input measured in the
loop (mV)
Sl no
(mV)
V
in
(taken from multimeter)
V
measured
(mV)
Difference (mV)
(V
measured
- Vin)
30498.75499.230.480.09
31519519.410.410.32
32538.69539.10.410.28
33558.91559.30.390.11
34578.63579.030.40.3
35598.65599.010.360.28
36638.6638.990.390.26
37678.93679.30.370.14
38718.6718.930.330.14
39758.61758.930.320.23
40798.53798.830.30.17
41838.7838.940.240.19
42858.49858.680.190.2
43878.55878.720.170.13
44898.76898.920.160.19
45918.53918.610.080.13
46938.46938.550.090.15
47958.68958.720.040.1
48978.4978.38-0.020.14
49998.63998.56-0.070.14
501018.81018.68-0.120.18
21/37
ResultAN2615
Figure 14 shows the relationship between the voltage measured by the ADC V
(average of the 16 readings measured by the converter) and the input voltage V
Figure 14. Measured vs input for positive voltages
measured
.
in
Figure 15 shows the relationship between the error voltage (as given in Ta bl e 1 in the
column ‘difference (V
measured
- Vin’)) and the input voltage Vin.
Figure 15. Error vs input for positive input voltages
Note:It may be seen from the readings in Tab le 1 and Figure 15, that for the positive input
between 0 to 1 V the maximum error is around 500 µV for an average of 16 conversions.
Thus the difference between the maximum and minimum values in a loop of 16 is around
500 µV. This shows that averaging has increased accuracy. The accuracy without averaging
is approx 1mV.
The variations of the 16 values may be due to changes in the input voltage itself, as the time
taken for 16 readings is very long (around 16 s).
22/37
AN2615Result
11.2 Negative input
Similar to the positive input voltages, the readings for negative input voltage are taken in a
loop of 16 as shown in Figure 16.
Figure 16. Results for negative input
23/37
ResultAN2615
Ta bl e 2 shows the readings for negative input voltages ranging from 0 to -1 V with the same
parameter notations as Table 1: Results for positive input voltages on page 20.
Table 2.Results for negative input voltages
Sl
no
(taken from multimeter)
Vin (mV)
V
measured
(mV)
Difference (mV)
(V
measured
- Vin)
Error in max and min input
measured in the loop (mV)
1-9.23-9.170.060.43
2-18.92-18.840.080.14
3-28.96-29.04-0.080.27
4-38.76-38.89-0.130.38
5-49.03-49.14-0.110.37
6-58.88-59-0.120.24
7-68.74-68.9-0.160.8
8-79.03-79.2-0.170.22
9-88.88-89.06-0.180.34
10-98.76-98.96-0.20.4
11-128.87-129.13-0.260.32
12-148.76-149.07-0.310.32
13-178.9-179.21-0.310.39
14-198.6-198.94-0.340.11
15-218.73-219.12-0.390.43
16-248.59-249.04-0.450.2
17-268.81-269.32-0.510.46
18-298.91-299.51-0.60.15
19-318.61-319.25-0.640.38
20-348.67-349.37-0.70.37
21-378.42-379.23-0.810.23
22-398.71-399.57-0.860.48
23-418.45-419.33-0.880.25
24-448.52-449.5-0.980.47
25-478.36-479.41-1.050.26
26-498.56-499.69-1.130.4
27-538.52-539.73-1.210.38
28-578.4-579.8-1.40.47
29-618.63-620.1-1.470.19
30-658.52-660.17-1.650.53
31-698.51-700.28-1.770.26
32-738.65-740.44-1.790.16
24/37
AN2615Result
Table 2.Results for negative input voltages (continued)
Sl
no
(taken from multimeter)
33-778.54-780.59-2.050.37
34-818.25-820.42-2.170.43
35-858.27-860.61-2.340.56
36-898.57-901.07-2.50.2
37-938.31-940.94-2.630.67
38-978.21-981.03-2.820.43
Vin (mV)
V
measured
(mV)
Figure 17 shows the relationship between measured voltages V
readings measured by the converter) and input voltage V
Difference (mV)
(V
measured
- Vin)
(as measured by the multimeter)
in
Error in max and min input
measured in the loop (mV)
measured
(average of the 16
for negative voltages.
Figure 17. Measured vs input for negative voltages
Figure 18. Error vs input for negative input voltages
Figure 18, shows that for negative input voltages varying from 0 to -1 V, the maximum error
is around -2.89 mV for -1 V input. An error of 0.5 mV occurs for an input value of -269 mV
25/37
ResultAN2615
and it increases gradually afterwards. The maximum difference between the maximum and
minimum value in a loop is around 600 µV. So, the accuracy of the average value measured
is around 3 mV. Without averaging, accuracy is around 3.6 mV.
11.3 Effect of the capacitor value
As discussed in Section 7: Error analysis/constraints on page 14, reducing the R*C time
constant by reducing the value of R or C, reduces the accuracy. Readings were taken with a 10 µF capacitor and accuracy of the ADC was found to be reduced. Figure 19 gives an
example of readings with a 10 µF capacitor.
Figure 19. Results for positive input with a 10 µF capacitor
Figure 19 shows that variation in the readings taken in a loop of 16 is around 5 - 6 mV which
is approximately 10 times higher than the readings for the 100 µF. This indicates that there is
always a trade-off between conversion time and the desired accuracy.
26/37
AN2615Conclusion
12 Conclusion
This application note presents a technique for implementing a positive supply ADC, capable
of measuring slowly-varying positive and negative input voltages with high precision.
Accuracy of the converter depends on the different parameters involved. Greater accuracy
can be achieved with careful board design, more precise components and by taking into
consideration all the factors discussed in the document.
27/37
References and bibliographyAN2615
13 References and bibliography
The following articles and reports provide useful information:
1.AN1636, Understanding and minimising ADC conversion errors
2. Comparators and bistable circuits, ECE60L lecture notes, winter 2002
3. Selecting the right buffer operational amplifier for an A/D converter, application report
SLOA050, August 2000, Texas instruments
4. MOSFET device physics and operation by T Ytterdal, Y Cheng and TA Fjeldly,
John Wiley and sons, ISBN: 0-471-49869-6
5. Comparators and offset cancellation techniques by Jieh-Tsorng Wu, 2003, National
Chiao-Tung University Department of Electronics Engineering
6. Reducing noise in data acquisition systems by Fred R Schraff, PE IOtech Inc., adapted
from an article that appeared in the April 1996 edition of SENSORS magazine,
Helmers Publishing
7. How do ADCs work? by Martin Rowe, senior technical editor, 7/1/2002, Test and
Measurement World
The ADC described here can be used for measuring both voltage and current with slight
changes in set-up in each case.
A.1 Case 1: Voltage measurement
There are two ways in which the input voltage appears at the ADC input. The first way is that
input comes directly from a voltage source as shown in Figure 20.
Figure 20. Voltage measurement
O/p
C
V1
R
I
R1
V
IN
Gnd
In Figure 20 above, there are no problems. However, if the input comes from a potential
divider circuit as shown in Figure 21, the effective input voltage V
across R2 due to the current I and current I
.
in
is the result of the drop
in
Figure 21. Potential divider
I
V
IN
R2
R1
I
in
In this case an input buffer has to be used to overcome the problem (see Figure 22: Use of
input buffer for voltage measurement on page 30).
29/37
Input stage conditionsAN2615
Figure 22. Use of input buffer for voltage measurement
O/p
C
V1
V
R
I
V
IN
IN
A.2 Case 2: Current measurement
Figure 23 shows the current measurement circuit.
Figure 23. Current measurement
O/p
C
V1
R
I
V
in
IN
R
sense
sense
I
V
= (Iin + I) * R
in
I = (V
- Vin)/R = V1/(R * (1 + R
1
= Iin * (1 + I/Iin) * R
sense
sense
/R)) ------------ (2)
sense
The following points should be kept in mind while using R
1.R
2. R
should be chosen to correspond with the range of the current to be measured.
sense
affects the effective value of current I. To minimize its effect, it should be
sense
negligible compared to R. Otherwise ADC has to be compensated.
------------ (1)
:
30/37
AN2615Application board schematics
Appendix B Application board schematics
Figure 24. Application board schematics
PB2
1
VDD
VDD
VDD
84
VDD
2
3
V3
C11
C10
100nF
R7
2k2
C8
100nF
R4
3k3
C6
100nF
R2
3k5
100nF
R5
3k3
V2
C9
100nF
R6
2k2
V1
C7
100nF
R3
1k5
VDD
D3
R13
1E
V1
Q2
MOSFET N
23
V2
U4
LM358
PB0
1
8
2
3
C14
1
R10
10K
PB1
U3
LM358
100uF
23
7
4
6
5
J7
V3
Q1
MOSFET N
1
VIN
PB3
SCI_RDI
J6
SCI_TDO
J8
VDD
7
9
13
14
SCI
2
1
2
1
T2OUT
R2OUT
R1OUT
T1OUT
R2IN
T2IN10T1IN
R1IN
U5
8
11
12
SCI1_RDISCI1_TDO
C18
1 2
J5
RTS
SCI_RTS
162738495
C13
16
VCC
C1+1V+
C1-3C2+4C2-5V-
2
C19
1uF 16V
100nF
15
GND
6
1uF 16V
DB9
GND
ST3232
C21
1uF 16V
VDD
C20
1uF 16V
VDD
2
1
J2
U1
D1
DC POWER
100nf
C5
C4
10uf/25v
R1
330E
D2
220uf/25v
220uf/25v
100nf
JACK
LED-Green-3mm
GND
VCC
1
2
J3
5V MAX
VDD
C3
3
Vout
LM7805
GND
2
Vin
1
C2
C1
IN400 7
J1
9~14V DC
100nF
VDD C12
31
30
26
29
32
PA128PA227PA3
PA0
VSS
VDD
ICCSEL
RESET1OSC12OSC2
SS/PB74SCK/PB65MISO/PB56MOSI/PB47NC8NC
U2
3
RESET
1 2
J4
Y1
16MHz
R9
1k
S1
C15
R8
4k7
100pf
24
NC25NC
ST72F264
9
C17
22pf
C16
22pf
PA423PA522PA621PA7
PB3
PB211PB112PB013PC514PC415PC3
10
PB3
PB2
PB1
SCI_TDO
20
19
17
PC0
PC118PC2
16
PB0
PB2
PB0
R11
10k
R12
10k
VDD
31/37
Bill of materialsAN2615
Appendix C Bill of materials
Ta bl e 3 gives the bill of material for each block of the schematics shown in Figure 24.
Table 3.Bill of materials
BlockDesignatorPart type/numberDescription
R131EResistor
R1010 kΩResistor
U3LM358Dual op-amp
ADC
U4LM358Dual op-amp
C14100 µFCapacitor
Q2STB100NF03LN - MOSFET
Q1STB100NF03LN - MOSFET
D3IN4007Diode
C8100 nFCapacitor
C9100 nFCapacitor
Voltage references
SCI
C10100 nFCapacitor
C11100 nFCapacitor
C7100 nFCapacitor
C6100 nFCapacitor
R62.2 kΩResistor
R72.2 kΩResistor
R53.3 kΩResistor
R43.3 kΩResistor
R23.5 kΩResistor
R31.5 kΩResistor
U5ST3232Line driver
C181µF 16 VCapacitor
C191µF 16 VCapacitor
C201µF 16 VCapacitor
C211µF 16 VCapacitor
J5jumperCON-2
J7jumperCON-2
J6jumperCON-2
C13100 nFCapacitor
J8DB99 pin connector
32/37
AN2615Bill of materials
Table 3.Bill of materials (continued)
BlockDesignatorPart type/numberDescription
R1210 kΩResistor
R1110 kΩResistor
Micro setup
Crystal
Reset
U2ST72F264Micro-controller
C12100 nFCapacitor
Y116 MHzCrystal oscillator
C1722 pFCapacitor
C1622 pFCapacitor
R91 kΩResistor
R84.7 kΩResistor
C15100 pF Capacitor
S1Push buttonMicro switch
J4CON-2jumper
C410 µF/25 VCapacitor
C5100 nFCapacitor
C1100 nFCapacitor
DC power
C3220 µF/25 VCapacitor
C2220 µF/25 VCapacitor
R1330EResistor
J1DC - JackDC - Jack
D2LED 3mmLED-green
U1LM7805Voltage regulator
D1IN4007Diode
J2jumperCON-2
J3Power connector2 pin connector
33/37
Software flowAN2615
Appendix D Software flow
The f
chosen is 8 MHz. K
CPU
offset
and K
are calculated by taking a reading for two known
gain
inputs. The flow of software, used to implement the algorithm, is as follows:
1.The I/O pins, timer, SCI (Tx @ 9600 baud rate) and some global variables used in the
ADC are initialized.
2. A string is transmitted to check that the SCI is working well.
3. Settling time is fixed at 1 s for f
= 8 MHz.
CPU
4. Some initial readings are taken and ignored while the ADC stabilizes.
5. The control enters an infinite loop.
6. Inside the infinite loop, there is a loop in which the ADC captures the timer values 17
times. However, the first reading is ignored.
7. The remaining 16 captured values are converted into corresponding voltages (up to 10
µV precision) and then transmitted to a PC for display by the hyper terminal after being
converted into a buffer of ASCII characters.
8. The average of 16 timer readings is taken and sent to the hyper terminal as a time
value and a corresponding voltage in the same manner as described above.
9. The difference between the maximum and minimum captured value is also sent to the
hyper terminal in the same way as in step 8.
10. The software enters an ‘IF’ loop ‘if (mCount == 18)’, where the ADC is reset in order to
measure the next input value. Again, a few readings are ignored while the ADC
stabilizes. The counter and other global variables are also initialized.
11. The software re-enters the loop of 17 conversions and executes step 6 to step 9. This
process continues until the system is reset manually.
34/37
AN2615Software flow
D.1 Code size
The software given is for guidance only. Here the display is done for up to 10 µV precision.
The user can modify and use their own code for display of the data. Tabl e 4 summarizes the
code size. Depending on the compiler and memory placement, these values can change.
The RAM requirements are not provided and the user has the choice to place the variables
as global or local.
.
Table 4.Code size
No.Function nameCode size ( bytes)
ADCSys
1Acquisition128
2Start_Capturing7
3Reset_ADC5
4ADC_InitializeVar29
5IsCaptured13
6Delay_Second44
7IO_Init37
8TimerA_Init47
9Timer_Interrupt_Routine170
Main
10 main1493
11TIMERA_IT_Routine38
12Conversion_TimerReadingToREALInput116
13SCI_Init25
14SCI_SendBuffer30
15SCI_IsTransmissionCompleted8
16Dummy_Capturing26
Note:Some floating point operations are used in this software for display purposes only. It is left to
the user to use the floating point operation or not as per his application requirement.
35/37
Revision historyAN2615
14 Revision history
Table 5.Document revision history
DateRevisionChanges
23-Aug-20071Initial release
36/37
AN2615
Please Read Carefully:
Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the
right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any
time, without notice.
All ST products are sold pursuant to ST’s terms and conditions of sale.
Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no
liability whatsoever relating to the choice, selection or use of the ST products and services described herein.
No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this
document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products
or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such
third party products or services or any intellectual property contained therein.
UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED
WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS
OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.
UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOT
RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING
APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY,
DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE
GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK.
Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void
any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any
liability of ST.
ST and the ST logo are trademarks or registered trademarks of ST in various countries.
Information in this document supersedes and replaces all information previously supplied.
The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.