AN2615 Application note

Similar documents
EVAL-RHF310V1. EVAL-RHF310V1 evaluation board. Features. Description

AN2979 Application note

AN1441 Application note

STEVAL-ISQ010V1. High-side current-sense amplifier demonstration board based on the TSC102. Features. Description

AN3134 Application note

STEVAL-ISA005V1. 1.8W buck topology power supply evaluation board with VIPer12AS. Features. Description. ST Components

LF253, LF353. Wide bandwidth dual JFET operational amplifiers. Features. Description

AN3332 Application note

AN2333 Application note

AN4014 Application Note Adjustable LED blinking frequency using a potentiometer and STM8SVLDISCOVERY Application overview

LM723CN. High precision voltage regulator. Features. Description

AN1489 Application note

Part numbers Order codes Packages Temperature range. LM137 LM137K TO-3-55 C to 150 C LM337 LM337K TO-3 0 C to 125 C LM337 LM337SP TO C to 125 C

LF253 LF353. Wide bandwidth dual JFET operational amplifiers. Features. Description

ST619LBDR. DC-DC converter regulated 5 V charge pump. Features. Description

AN1229 Application note

LM2903W. Low-power, dual-voltage comparator. Features. Description

LM323. Three-terminal 3 A adjustable voltage regulators. Features. Description

AN2837 Application note

TSL channel buffers for TFT-LCD panels. Features. Application. Description

Obsolete Product(s) - Obsolete Product(s)

Obsolete Product(s) - Obsolete Product(s)

AN279 Application note

TS522. Precision low noise dual operational amplifier. Features. Description

Obsolete Product(s) - Obsolete Product(s)

AN1642 Application note

STEVAL-CCA011V1. Filter-free stereo 2x2.5 W Class-D audio power amplifier demonstration board based on the TS2012FC. Features.

STEVAL-CCA040V1. 4X10 Watt dual/quad power amplifier demonstration board based on the STA540SAN. Features. Description

Description. Part numbers Order codes Packages Output voltages

AN1258 Application note

Low noise low drop voltage regulator with shutdown function. Part numbers

Obsolete Product(s) - Obsolete Product(s) Obsolete Product(s) - Obsolete Product(s)

Order code Temperature range Package Packaging Marking

AN1954 APPLICATION NOTE

Obsolete Product(s) - Obsolete Product(s)

LM2903H. Low-power dual voltage comparator. Features. Description

Obsolete Product(s) - Obsolete Product(s)

LD1117Axx. Low drop fixed and adjustable positive voltage regulators. Features. Description

KF25B, KF33B KF50B, KF80B

SPV1001T40. Cool bypass switch for photovoltaic application. Features. Application. Description TO-220

R 1 typ. = 15 kω. Order codes Marking Polarity Package Packaging. 2N6036 2N6036 NPN SOT-32 Tube 2N6039 2N6039 PNP SOT-32 Tube

LS1240. Electronic two-tone ringer. Features. Description. Pin connection (top view)

L6932H1.2. High performance 2A ULDO linear regulator. Features. Description. Applications L6932H1.2

LM2901. Low power quad voltage comparator. Features. Description

BD235 BD237. Low voltage NPN power transistors. Features. Applications. Description. Low saturation voltage NPN transistors

Low noise low drop voltage regulator with shutdown function. Part numbers

MC33172 MC Low power dual bipolar operational amplifiers. Features. Description

AN4439 Application note

Obsolete Product(s) - Obsolete Product(s)

ESDALCL6-4P6A. Multi-line low capacitance and low leakage current ESD protection. Features. Applications. Description

AN1756 Application note

LET9060C. RF power transistor from the LdmoST family of n-channel enhancement-mode lateral MOSFETs. Features. Description

Obsolete Product(s) - Obsolete Product(s)

High performance 2A ULDO linear regulator with Soft Start. Description. Order codes Package Packaging

Obsolete Product(s) - Obsolete Product(s)

BD241A BD241C. NPN power transistors. Features. Applications. Description. NPN transistors. Audio, general purpose switching and amplifier transistors

AN440 Application note

TS391. Low-power single voltage comparator. Features. Description

AN2243 Application note

AN3222 Application note

AN1736 Application note VIPower: VIPer22A dual output reference board 90 to 264 VAC input, 10W output Introduction

MC Low noise quad operational amplifier. Features. Description

LD39150xx Ultra low drop BiCMOS voltage regulator Features Description Typical application

MJE182 Low voltage high speed switching NPN transistor Features Applications Description High speed switching NPN device

DB Evaluation board using PD85004 for 900 MHz 2-way radio. Features. Description

ST26025A. PNP power Darlington transistor. Features. Applications. Description

Obsolete Product(s) - Obsolete Product(s)

Obsolete Product(s) - Obsolete Product(s)

ST662AB ST662AC. DC-DC converter from 5 V to 12 V, 0.03 A for Flash memory programming supply. Features. Description

TS3704. Micropower quad CMOS voltage comparators. Features. Description

D44H8 - D44H11 D45H8 - D45H11

STPSC V power Schottky silicon carbide diode. Features. Description

Order codes Marking Polarity Package Packaging. MJD44H11T4 MJD44H11 NPN DPAK Tape and reel MJD45H11T4 MJD45H11 PNP DPAK Tape and reel

TO-220 D²PAK TO-220FP

TDA7233D 1W AUDIO AMPLIFIER WITH MUTE

Order codes. TO-220 D²PAK (tape and reel) TO-220FP TO-3 LM117K LM217T LM217D2T-TR LM217K LM317T LM317D2T-TR LM317P LM317K

AN1449 Application note

1. Drain 2. Gate. Order code Marking Package Packaging. STAC4932F STAC4932F STAC244F Plastic tray. September 2010 Doc ID Rev 3 1/12

L78S00 series. 2A Positive voltage regulators. Feature summary. Description. Schematic diagram

Obsolete Product(s) - Obsolete Product(s)

2STR2215. Low voltage fast-switching PNP power transistor. Features. Applications. Description

ST202EB - ST202EC ST232EB - ST232EC

AN4112 Application note

2STA1943. High power PNP epitaxial planar bipolar transistor. Features. Application. Description

LD1085CXX. 3 A low-drop, adjustable positive voltage regulator. Features. Description

2STC4468. High power NPN epitaxial planar bipolar transistor. Features. Application. Description

AN2961 Application note

AN2679 Application note

STEVAL-ISA110V1. 12 V/12 W wide-range non-isolated flyback based on the VIPER26LN. Features. Description

BD533 BD535 BD537 BD534 BD536

2STA1695. High power PNP epitaxial planar bipolar transistor. Features. Applications. Description

Obsolete Product(s) - Obsolete Product(s)

Obsolete Product(s) - Obsolete Product(s)

LK115XX30 LK115XX33 - LK115XX50

LM139, LM239, LM339. Low-power quad voltage comparators. Features. Description

L4940xx5 L4940V5 L4940D2T5-TR 5 V L4940xx85 L4940V85 L4940P85 L4940D2T85-TR 8.5 V L4940xx10 L4940D2T10-TR 10 V L4940xx12 L4940D2T12-TR 12 V

STEVAL-ISA111V1. Wide-range single-output demonstration board based on the VIPER26HN. Features. Description STEVAL-ISA111V1

L79xxC. Negative voltage regulators. Features. Description

STEVAL-TDR003V1. 2-stage RF power amp: PD PD54008L-E + LPF N-channel enhancement-mode lateral MOSFETs. Feature. Description

Order codes Marking Package Packaging 2STF SOT-89 2STN2550 N2550 SOT-223. November 2008 Rev 1 1/8

Transcription:

Application note A high precision, low cost, single supply ADC for positive and negative input voltages Introduction 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. August 2007 Rev 1 1/37 www.st.com

Contents AN2615 Contents 1 Circuit diagram............................................. 6 2 Theory of operation......................................... 7 2.1 Advantage of using two comparators............................. 7 3 Timing diagram............................................. 8 4 Circuit analysis............................................. 9 5 V out vs time diagram for different input voltages................. 10 6 Characteristics of different slope converters.................... 11 6.1 Single-slope converter....................................... 11 6.1.1 Single-slope converter timing diagram.......................... 11 6.2 Dual-slope converter........................................ 12 6.2.1 Dual-slope converter timing diagram........................... 12 6.3 Solution presented in this application note........................ 13 7 Error analysis/constraints................................... 14 7.1 Input offset voltage.......................................... 14 7.2 Correction factor for the product of R*C.......................... 14 7.3 Value of charging resistance R................................. 14 7.4 Charging capacitor C........................................ 14 7.5 16-bit timer................................................ 15 7.6 Effect of temperature........................................ 15 7.7 Comparator............................................... 15 8 Voltage references......................................... 16 9 Hardware setup............................................ 17 10 Algorithm................................................. 18 11 Result.................................................... 19 2/37

Contents 11.1 Positive input.............................................. 19 11.2 Negative input............................................. 23 11.3 Effect of the capacitor value................................... 26 12 Conclusion................................................ 27 13 References and bibliography................................. 28 Appendix A Input stage conditions.................................... 29 A.1 Case 1: Voltage measurement................................. 29 A.2 Case 2: Current measurement................................. 30 Appendix B Application board schematics............................. 31 Appendix C Bill of materials......................................... 32 Appendix D Software flow........................................... 34 D.1 Code size................................................. 35 14 Revision history........................................... 36 3/37

List of tables AN2615 List of tables Table 1. Results for positive input voltages........................................... 20 Table 2. Results for negative input voltages........................................... 24 Table 3. Bill of materials.......................................................... 32 Table 4. Code size.............................................................. 35 Table 5. Document revision history................................................. 36 4/37

List of figures List of figures Figure 1. Circuit diagram........................................................... 6 Figure 2. Relationship between Vout and time for a given input............................. 7 Figure 3. Timing diagram........................................................... 8 Figure 4. V out vs time for different input voltages........................................ 10 Figure 5. Single-slope converter circuit diagram........................................ 11 Figure 6. Single-slope converter timing diagram........................................ 11 Figure 7. Dual-slope converter circuit diagram......................................... 12 Figure 8. Dual-slope converter timing diagram......................................... 12 Figure 9. V IN versus time in AN2615 solution.......................................... 13 Figure 10. Voltage reference........................................................ 16 Figure 11. Hardware setup......................................................... 17 Figure 12. Algorithm flowchart....................................................... 18 Figure 13. Results for positive input................................................... 19 Figure 14. Measured vs input for positive voltages....................................... 22 Figure 15. Error vs input for positive input voltages....................................... 22 Figure 16. Results for negative input.................................................. 23 Figure 17. Measured vs input for negative voltages...................................... 25 Figure 18. Error vs input for negative input voltages...................................... 25 Figure 19. Results for positive input with a 10 µf capacitor................................ 26 Figure 20. Voltage measurement..................................................... 29 Figure 21. Potential divider......................................................... 29 Figure 22. Use of input buffer for voltage measurement................................... 30 Figure 23. Current measurement..................................................... 30 Figure 24. Application board schematics............................................... 31 5/37

Circuit diagram AN2615 1 Circuit diagram Figure 1. Circuit diagram M1 PB1 R S Comp1 I 358 C Amp V out D V3 358 PB0 V1 Comp2 R 358 PB2 PB3 M2 V IN V2 1. V1 < V2 < V3 6/37

Theory of operation 2 Theory of operation V in is the input voltage. The voltages across resistor R are the reference voltage V 1 and the input voltage V in. Due to the properties of the op-amp, V 1 is output on the inverting pin of the 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 in <= V 1 (input V in > V 1 charges in the opposite direction). The output is captured at two instants using the two output comparators at voltage references V 2 and V 3. The time corresponding to voltage levels V 2 and V 3 are T 2 and T 3 respectively. The final reading of time T m is taken as the difference of T 3 and T 2. 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 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 out and time for a given input V out V3 V2 V1 Point of uncertainty T2 T3 Time (t) T m 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 c (0+)) and any other constant 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 diagram AN2615 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 out is at V 1 and so, the output of both comparators, Comp1 and Comp2 is high. Capacitor charging can be started by switching M1 - off and M2 - on. When the charging starts, V out rises. When V out becomes greater than V 2, a falling edge occurs on Comp1. This causes an input capture at pin PB2 and software reads the timer value T 2. When V out becomes greater than V 3, a falling edge occurs on Comp2. Again this causes an input capture at pin PB0 and software reads the timer value T 3. 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 Charging time Discharg. time Settling time V3 V out V2 V1 0 T2 T3 Time (t) Comp1 Comp2 T m T m M1 M2 8/37

Circuit 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 1 V in )/R = C * dv c /dt Where, V c = V out V 1 and current I is constant for a given input. Applying the Laplace transform: (V 1 V in )/s * R = C * (s V c (s) V c (0+)) or, (V 1 V in )/s 2 = (R * C) * ( V c (s) - V c (0+)/s) Applying the inverse Laplace transform, we get (V 1 V in ) * T = (R * C) * ( V c (t) - V c (0+) ) ------------------- (1) As shown in Figure 3: Timing diagram on page 8 At T = T 2, V c (T 2 ) = V 2 V 1 And, at T =T 3, V c (T 3 )= V 3 V 1 So, (V 1 V in ) * T 2 = (R * C) * (V 2 V 1 - V c (0+)) ------------------- (2) And, (V 1 V in ) * T 3 = (R * C) * (V 3 V 1 - V c (0+)) ------------------- (3) 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). After subtracting equation (2) from equation (1) and rearranging we get: V in = V 1 - (R * C) *( V 3 V 2 )/(T 3 T 2 ) ------------------- (4) Let measured time T 3 - T 2 = T m and we get: V in = V1 - (R * C) * ( V 3 V 2 )/T m ------------------- (5) By using equation (5) we can measure the value of V in depending on the value of T 3 and T 2. 9/37

V out vs time diagram for different input voltages AN2615 5 V out vs time diagram for different input voltages In Figure 4, we can see the relationship between the V out and time for different input 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 out vs time for different input voltages Effective time T m = T - T V3 V in < 0 V in =0 V in > 0 V out V2 V1 T1 T2 T1 T3 T2 T3 Time (t) 1. T m 1: for V in < 0; T m 2: for V in = 0; and T m 3: for V in > 0 (where Tin1 < Tin2 < Tin3) 2. This ADC works for the range V in <= V 1 but if the input voltage is greater than V 1 the direction of current I is inverted and the capacitor starts charging in the opposite direction and conversion never takes place. 3. For negative voltage currents I, that depend on the difference V 1 - V in, is high, so the charging time for negative voltages is less than the positive voltages. 10/37

Characteristics 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 V in is directly proportional to the time measured. Figure 6. Single-slope converter timing diagram V in Time 1. Here V in = 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 converters AN2615 6.2 Dual-slope converter Figure 7. Dual-slope converter circuit diagram S0 -V in V ref S1 R 1 2 gnd out 3 1 2 gnd out cmp S1 clk Control logic S2 ctr enbl clk Counter clk 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 phase Fixed-rate discharge V in 1 -V ref V in = T charge V ref T discharge V in 2 -V ref Time 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

Characteristics 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 1, the conversion time is infinite (1/T m = 0 in Figure 9). So the input voltage range depends on the value of V1 and the maximum delay that the application can tolerate. Figure 9. V IN versus time in AN2615 solution V in V 1 Positive input Negative input +V ref Total input range (+V ref to -V ref ) V0 1/T m -V ref 1. V in = V 1 - (R * C) * (V 3 -V 2 ) /T m The significant advantage of this ADC is 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 ref to -V ref, where the absolute value of V ref is mod (V ref ) < V 1 so the input voltage range depends on the value of V 1. 13/37

Error analysis/constraints AN2615 7 Error analysis/constraints This ADC 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 1. For measurement purposes, let us refer to the input offset voltage of the op-amp as K offset. 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 gain. Then eq(5) becomes, V in = V1 + K offset K gain * (R * C) *(V3 -V2)/Tm ------------------ (6) The coefficients K offset and K gain can be calculated by measuring T m for two known input 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. 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

Error 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 references AN2615 8 Voltage references The following circuit is used to produce the different voltage references. Figure 10. Voltage reference V DD R1 C1 +5V R2 C2 Vref Gnd 16/37

Hardware setup 9 Hardware setup Figure 11. Hardware setup ST72 V DD V DD V in Comp1 External M1 ADC Comp2 M2 Gnd PB0 PB1 PB2 PB3 TD0 RS232 interface Gnd 0134.85 mv Multimeter Application board RS232 communication Hyper terminal 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 2 and V 3 respectively), while PB1 and PB3 are used for controlling the voltage 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

Algorithm AN2615 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? No Yes 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? No Yes Calculate the average and display on the PC through SCI-RS 232 interface Start new conversion 18/37

Result 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 1 = 1.5 V, V 2 = 2V and V 3 = 3 V So: R * C = (10 K) * (100 µf) = 1 s The input range is taken as +1V to -1V, where mod (V ref ) (= 1 V) is less than V 1. 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 offset and K gain are calculated. The input voltage V in is taken from a 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 avg is the average of 16 conversions, and V avg is the calculated 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 19/37

Result AN2615 In Table 1, the readings are shown for positive input voltages ranging from 0 to 1 V. V in is the voltage measured by the multimeter. V measured (equal to V avg ) is the average voltage 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. Sl no Results for positive input voltages V in (mv) (taken from multimeter) V measured (mv) Difference (mv) (V measured - V in ) Error in max and min input measured in the loop (mv) 1 8.93 8.93 0 0.45 2 18.94 18.98 0.04 0.25 3 28.82 28.87 0.05 0.21 4 38.72 38.78 0.06 0.39 5 49.07 49.13 0.06 0.46 6 58.93 59.02 0.09 0.38 7 68.82 68.92 0.1 0.08 8 79.12 79.25 0.13 0.39 9 88.98 89.07 0.09 0.33 10 98.85 98.98 0.13 0.12 11 108.75 108.9 0.15 0.37 12 119.05 119.19 0.14 0.43 13 128.95 129.13 0.18 0.29 14 138.57 138.76 0.19 0.24 15 158.75 158.96 0.25 0.25 16 178.97 179.18 0.21 0.4 17 198.68 198.91 0.23 0.1 18 218.83 219.1 0.27 0.37 19 239.08 239.35 0.27 0.34 20 258.55 258.83 0.28 0.14 21 278.8 279.11 0.31 0.19 22 299.02 299.34 0.32 0.31 23 318.68 319.09 0.41 0.37 24 338.93 339.29 0.36 0.35 25 358.38 358.78 0.4 0.39 26 378.62 378.98 0.36 0.36 27 398.85 399.25 0.4 0.27 28 438.84 439.23 0.39 0.15 29 478.64 478.93 0.29 0.35 20/37

Result Table 1. Sl no Results for positive input voltages (continued) V in (mv) (taken from multimeter) V measured (mv) Difference (mv) (V measured - V in ) Error in max and min input measured in the loop (mv) 30 498.75 499.23 0.48 0.09 31 519 519.41 0.41 0.32 32 538.69 539.1 0.41 0.28 33 558.91 559.3 0.39 0.11 34 578.63 579.03 0.4 0.3 35 598.65 599.01 0.36 0.28 36 638.6 638.99 0.39 0.26 37 678.93 679.3 0.37 0.14 38 718.6 718.93 0.33 0.14 39 758.61 758.93 0.32 0.23 40 798.53 798.83 0.3 0.17 41 838.7 838.94 0.24 0.19 42 858.49 858.68 0.19 0.2 43 878.55 878.72 0.17 0.13 44 898.76 898.92 0.16 0.19 45 918.53 918.61 0.08 0.13 46 938.46 938.55 0.09 0.15 47 958.68 958.72 0.04 0.1 48 978.4 978.38-0.02 0.14 49 998.63 998.56-0.07 0.14 50 1018.8 1018.68-0.12 0.18 21/37

Result AN2615 Figure 14 shows the relationship between the voltage measured by the ADC V measured (average of the 16 readings measured by the converter) and the input voltage V in. Figure 14. Measured vs input for positive voltages Figure 15 shows the relationship between the error voltage (as given in Table 1 in the column difference (V measured - V in )) and the input voltage V in. Figure 15. Error vs input for positive input voltages Note: It may be seen from the readings in Table 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

Result 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

Result AN2615 Table 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. Sl no Results for negative input voltages V in (mv) (taken from multimeter) V measured (mv) Difference (mv) (V measured - V in ) Error in max and min input measured in the loop (mv) 1-9.23-9.17 0.06 0.43 2-18.92-18.84 0.08 0.14 3-28.96-29.04-0.08 0.27 4-38.76-38.89-0.13 0.38 5-49.03-49.14-0.11 0.37 6-58.88-59 -0.12 0.24 7-68.74-68.9-0.16 0.8 8-79.03-79.2-0.17 0.22 9-88.88-89.06-0.18 0.34 10-98.76-98.96-0.2 0.4 11-128.87-129.13-0.26 0.32 12-148.76-149.07-0.31 0.32 13-178.9-179.21-0.31 0.39 14-198.6-198.94-0.34 0.11 15-218.73-219.12-0.39 0.43 16-248.59-249.04-0.45 0.2 17-268.81-269.32-0.51 0.46 18-298.91-299.51-0.6 0.15 19-318.61-319.25-0.64 0.38 20-348.67-349.37-0.7 0.37 21-378.42-379.23-0.81 0.23 22-398.71-399.57-0.86 0.48 23-418.45-419.33-0.88 0.25 24-448.52-449.5-0.98 0.47 25-478.36-479.41-1.05 0.26 26-498.56-499.69-1.13 0.4 27-538.52-539.73-1.21 0.38 28-578.4-579.8-1.4 0.47 29-618.63-620.1-1.47 0.19 30-658.52-660.17-1.65 0.53 31-698.51-700.28-1.77 0.26 32-738.65-740.44-1.79 0.16 24/37

Result Table 2. Sl no Results for negative input voltages (continued) V in (mv) (taken from multimeter) V measured (mv) Difference (mv) (V measured - V in ) Error in max and min input measured in the loop (mv) 33-778.54-780.59-2.05 0.37 34-818.25-820.42-2.17 0.43 35-858.27-860.61-2.34 0.56 36-898.57-901.07-2.5 0.2 37-938.31-940.94-2.63 0.67 38-978.21-981.03-2.82 0.43 Figure 17 shows the relationship between measured voltages V measured (average of the 16 readings measured by the converter) and input voltage V in (as measured by the multimeter) 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

Result AN2615 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

Conclusion 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 bibliography AN2615 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, 2003, 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 28/37

Input stage conditions Appendix A Input stage conditions 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 V IN R1 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 in is the result of the drop across R2 due to the current I and current I in. Gnd Figure 21. Potential divider I V IN R1 I in R2 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 conditions AN2615 Figure 22. Use of input buffer for voltage measurement O/p C V1 R V IN I V IN A.2 Case 2: Current measurement Figure 23 shows the current measurement circuit. Figure 23. Current measurement O/p C V1 R I I in V IN R sense V in = (I in + I) * R sense = I in * (1 + I/I in ) * R sense ------------ (1) I = (V 1 - V in )/R = V 1 /(R * (1 + R sense /R)) ------------ (2) The following points should be kept in mind while using R sense : 1. R sense should be chosen to correspond with the range of the current to be measured. 2. R sense affects the effective value of current I. To minimize its effect, it should be negligible compared to R. Otherwise ADC has to be compensated. 30/37

Appendix B Application board schematics Application board schematics Figure 24. Application board schematics 2 GND 9~14V DC J1 JACK J3 2 1 5V MAX VDD R8 4k7 C15 100pf DC POWER D1 IN4007 C1 100nf GND VCC R9 1k S1 U1 1 Vin C2 220uf/25v J4 1 2 RESET Vout 3 LM7805 C3 220uf/25v R1 330E C4 10uf/25v D2 LED-Green-3mm VDD C5 100nf 2 3 1 8 8 V1 Q2 MOSFET N VDD 1 2 3 6 5 U3 LM358 1 7 LM358 4U4 4 3 2 3 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 U2 RESET VDD 32 OSC1 VSS 31 OSC2 ICCSEL 30 SS/PB7 PA0 29 SCK/PB6 PA1 28 MISO/PB5 PA2 27 MOSI/PB4 PA3 26 NC NC 25 ST72F264 NC NC 24 PB3 PA4 23 PB2 PA5 22 PB1 PA6 21 PB0 PA7 20 PC5 PC0 19 PC4 PC1 18 PC3 PC2 17 PB1 PB3 1 VIN VDD VDD VDD R2 3k5 C6 100nF R4 3k3 C8 100nF R7 2k2 C10 100nF V1 V2 V3 R3 1k5 C7 100nF R6 2k2 C9 100nF R5 3k3 C11 100nF R13 1E D3 R10 10K Q1 MOSFET N C14 100uF V3 PB0 V2 J6 SCI_TDO J7 SCI_RDI SCI SCI1_TDO J5 SCI_RTS 1 2 RTS C18 1uF 16V C19 1uF 16V SCI1_RDI C20 1uF 16V 12 8 1 3 4 5 2 6 U5 R1IN R2IN 11 T1IN 10 T1IN T2IN C21 1uF 16V C1+ C1- C2+ C2- V+ V- R1OUT 13 R2OUT 9 T1OUT 14 T2OUT 7 VCC 16 GND 15 VDD C13 100nF ST3232 GND VDD VDD J8 5 9 4 8 3 7 2 6 1 DB9 PB2 1 2 1 2 VDD C16 22pf R11 10k R12 10k PB2 PB0 Y1 16MHz C17 22pf PB3 PB2 PB1 PB0 J2 VDD C12 100nF SCI_TDO 1 2 31/37

Bill of materials AN2615 Appendix C Bill of materials Table 3 gives the bill of material for each block of the schematics shown in Figure 24. Table 3. Bill of materials Block Designator Part type/number Description R13 1E Resistor R10 10 kω Resistor U3 LM358 Dual op-amp ADC Voltage references SCI U4 LM358 Dual op-amp C14 100 µf Capacitor Q2 STB100NF03L N - MOSFET Q1 STB100NF03L N - MOSFET D3 IN4007 Diode C8 100 nf Capacitor C9 100 nf Capacitor C10 100 nf Capacitor C11 100 nf Capacitor C7 100 nf Capacitor C6 100 nf Capacitor R6 2.2 kω Resistor R7 2.2 kω Resistor R5 3.3 kω Resistor R4 3.3 kω Resistor R2 3.5 kω Resistor R3 1.5 kω Resistor U5 ST3232 Line driver C18 1µF 16 V Capacitor C19 1µF 16 V Capacitor C20 1µF 16 V Capacitor C21 1µF 16 V Capacitor J5 jumper CON-2 J7 jumper CON-2 J6 jumper CON-2 C13 100 nf Capacitor J8 DB9 9 pin connector 32/37

Bill of materials Table 3. Bill of materials (continued) Block Designator Part type/number Description R12 10 kω Resistor R11 10 kω Resistor Micro setup Crystal Reset DC power U2 ST72F264 Micro-controller C12 100 nf Capacitor Y1 16 MHz Crystal oscillator C17 22 pf Capacitor C16 22 pf Capacitor R9 1 kω Resistor R8 4.7 kω Resistor C15 100 pf Capacitor S1 Push button Micro switch J4 CON-2 jumper C4 10 µf/25 V Capacitor C5 100 nf Capacitor C1 100 nf Capacitor C3 220 µf/25 V Capacitor C2 220 µf/25 V Capacitor R1 330E Resistor J1 DC - Jack DC - Jack D2 LED 3mm LED-green U1 LM7805 Voltage regulator D1 IN4007 Diode J2 jumper CON-2 J3 Power connector 2 pin connector 33/37

Software flow AN2615 Appendix D Software flow The f CPU chosen is 8 MHz. K offset and K gain are calculated by taking a reading for two known 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 CPU = 8 MHz. 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

Software 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. Table 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 name Code size ( bytes) ADCSys 1 Acquisition 128 2 Start_Capturing 7 3 Reset_ADC 5 4 ADC_InitializeVar 29 5 IsCaptured 13 6 Delay_Second 44 7 IO_Init 37 8 TimerA_Init 47 9 Timer_Interrupt_Routine 170 Main 10 main 1493 11 TIMERA_IT_Routine 38 12 Conversion_TimerReadingToREALInput 116 13 SCI_Init 25 14 SCI_SendBuffer 30 15 SCI_IsTransmissionCompleted 8 16 Dummy_Capturing 26 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 history AN2615 14 Revision history Table 5. Document revision history Date Revision Changes 23-Aug-2007 1 Initial release 36/37

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. 2007 STMicroelectronics - All rights reserved STMicroelectronics group of companies Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com 37/37