Based on the principle of using a single-chip microcomputer to use PWM mode D/A in the instrument

I. Introduction

In the transmitter and controller instruments made with single chip microcomputer, when it is necessary to output a DC signal of 1-5V or 4-20mA, a dedicated D/A chip is usually used, usually one piece per channel. When the accuracy of the output signal is high, the number of bits of the D/A chip will increase accordingly.

In industrial instrumentation, it is usually increased to 12 digits. The price of 12-bit D/A is currently much higher than that of the single-chip microcomputer, and it takes up a lot of interface lines. Especially when isolation is required, the number of photocouplers required is equivalent to the number of interface lines, which causes a large increase in the number of components and increases the volume and cost. If the D/A output is completed by PWM in an instrument controlled by a single-chip microcomputer, the cost will be reduced to about one-tenth of that of a 12-bit D/A chip. We have adopted this method in the S series flow meters, and the use effect is very ideal. The following describes the composition principle of PWM mode D/A.

Two circuit principle

Generally, the accuracy of 12-bit D/A converter in the manual is ±1/2LSB, and the comprehensive index of temperature drift is 20-50ppm/℃. The above two indexes can meet the requirements in the 0.2-level instrument. The circuit can achieve the above two indicators.

T in Figure 1 is a fixed width, and the width of τ is variable. τ is divided into 5000 parts, each 2us. So the maximum value of τ τmax=2×5000=10000us, this is the width of T. When τ=T, the duty cycle is 1, Vo=5.000V, when τ=0, Vo=0V. The voltage obtained after this pulse voltage is filtered by two stages of RC can be expressed by the following formula:

Based on the principle of using a single-chip microcomputer to use PWM mode D/A in the instrument

VM must be a precision voltage source. Vo is proportional to the duty cycle, and the linearity is good. This method is very mature in theory, but there are still some problems in practical applications. Figure 2 shows the actual circuit. The single-chip microcomputer can be used with two common chips, 8098 or 8031, and the value of VM is 5.000V±2mV. D/A and the single-chip microcomputer must be electrically isolated. Otherwise, the interference generated by the digital pulse current will affect the D/A accuracy. The oscilloscope can see the interference glitch voltage as high as 50mV, so it is necessary to add photoelectric isolation. The isolated pulse drives the analog switch CD4053. CD4053 is a three-group two-contact analog switch. The common contact of the switch is controlled by PWM pulse to make it connect with +5.000V and ground. The VI obtains the PWM waveform consistent with the output of the single-chip microcomputer. After the waveform is filtered by two stages of RC, a voltage follower composed of an operational amplifier outputs Vo. Among them, the time constant of RC is generally RC≥2T, so that the two-stage RC will add up to get a DC voltage with a ripple less than 3mV. In this circuit, RC=220ms. If you want to further reduce the ripple, you can appropriately increase the RC product. But the response speed of the circuit will also slow down.

Based on the principle of using a single-chip microcomputer to use PWM mode D/A in the instrument

It is beneficial to use an op amp to buffer the output of the RC filter. It not only improves the load capacity of the filter circuit, but also improves the linearity. Through experiments, it can be known that the buffering effect of this level of op amp is an important link to ensure the accuracy and linearity of the entire D/A. Although the RC filter has no load and works under very ideal conditions, Vo is not completely proportional to the duty cycle. After testing, Vo has some errors from the ideal value, as shown in Figure 3.

The curve 1 in the figure represents the ideal value, and the curve 2 represents the actual measured value. It can be seen from the figure that the root of curve 2 is not ideal. This is because the capacitor used is not a pure capacitor, which contains a certain amount of inductance. When the duty cycle is extremely small, because the pulse is very narrow, the frequency of the high-order harmonics generated by it is very high, and the inductance of the inductor to the high-order harmonics is relatively large. Therefore, at the position of the pulse edge, although the voltage changes greatly, However, the actual charging of the capacitor is very small. This produces nonlinearity in narrow pulses. When a non-inductive capacitor is used, this nonlinearity is greatly improved, but it still cannot be completely consistent. Since the capacity of the non-inductive capacitor is too small and the price is high, it has no practical meaning in a filter circuit with a large time constant. In actual use, the method to solve this problem is to abandon the non-linear part of the root and only use the linear part. In industrial instruments, the standard signal is generally 1-5V or 4-20mA. The non-linear part of curve 2 is below 0.4V, so when the 1-5V output signal is used, the accuracy is 0.03% and fully meets the 12-bit D/A requirements.

In addition to meeting the accuracy requirements, the temperature characteristics must also meet the requirements. The main reason that affects the temperature characteristics is the temperature characteristics of the 5V precision power supply and the operational amplifier. In order not to make the price too high, choose 2DW232 precision voltage regulator diode, the resistance of the operational amplifier and the filter resistance should be matched and the temperature coefficient is ≤25ppm. Operational amplifiers can be selected with temperature drift ≤ 10uV/℃, and generally inexpensive low-temperature drift operational amplifiers can meet this index. After adopting the above measures, the total temperature drift of D/A is 33ppm/℃.

Three measured data

Since this circuit is used in a 0.2-level precision instrument, linearity and temperature characteristics must meet the requirements. In addition, this data is the error between the 4-20mA power supply value after V/I conversion and the given current value. This error also includes the error of V/I conversion. Therefore, the actual D/A error is smaller than the total error.

It can be seen from the above data that the linearity of the full scale is 0.04%, the temperature drift of the full scale is 0.033%/10℃, the system response time is about 2.2s, and the time used when the output signal differs by 0.1% from the standard value is 11s.

Based on the principle of using a single-chip microcomputer to use PWM mode D/A in the instrument

Four concluding remarks

The D/A circuit described above has a simple structure and easy-to-understand principle. It can be applied to both 8098 and 8031 ​​single-chip microcomputers. The author uses the four-channel high-speed input and output of the 8098 single-chip microcomputer to control four precision D/A outputs at the same time. A V/I conversion circuit is added at the back to form a standard 4-20mA current output. After more than one year of field application, the circuit has a very good effect and is suitable for all the requirements of the current 0.2-level instrument.

2.54mm Pin Header Connector

2.54Mm Pin Header Connector,2.54Mm Vertical Type Connector,2.54Mm Pin Header Vertical Type Connectors,2.54Mm Right Angle Type Connector

Shenzhen CGE Electronics Co.,Ltd , https://www.cgeconnector.com