Design of Intelligent Electromagnetic Flowmeter Based on HART Protocol

Design of Intelligent Electromagnetic Flowmeter Based on HART Protocol

1 Introduction
HART, namely Highway Addressable Remote Transducer, is the abbreviation of Addressable Remote Sensor Highway. It was first developed by Rosemount Company in the United States and supported by more than 80 famous instrument companies. Two-way digital communication is allowed.
The intelligent electromagnetic flowmeter that conforms to the HART protocol can not only realize the detection and local display of various flow rates, but also perform remote setting through the upper meter, change the zero point and range of the flowmeter, and complete functions such as self-diagnosis. It is convenient for the use and maintenance of the flowmeter, so it has strong market competitiveness. This paper discusses the technical problems of the specific implementation of the intelligent electromagnetic flowmeter based on the HART protocol. One is to solve the design problem of the hardware circuit, and the other is to discuss the realization of the HART protocol command set programming and the realization of the host computer software.

2 Introduction to HART Protocol
The HART protocol follows the OSI open system interconnection reference model formulated by ISO, and adopts the first, second and seventh layers of the OSI model, namely the physical layer, the data link layer and the application layer.

2.1 Physical layer specification
The HART protocol adopts the Bell202 frequency shift keying (FSK) standard of the American telephone communication system, which simulates a sine wave of ±0.5mA at 4-20mA, and the baud rate is 1200bps. Because the average value of the superimposed sinusoidal signal is 0, and the phase continuous frequency shift keying technology requires that the phase angle at the boundary of the data bits 1 and 0 with a baud rate of 1200Hz is continuous, so the digital communication signal will not affect the 4~ 20mA analog signal.

2.2 Data Link Layer Specifications
This part of the protocol specifies the format of the HART frame, and realizes the establishment, maintenance, and data link communication functions. The HART protocol uses the error detection mechanism and the automatic repeat request protocol (ARQ) according to the redundant error detection code information to realize the communication data. error transmission.
The data transmission related to the protocol is realized in the form of frames. The frame is the encapsulation of user data by user control and addressing information. It can only be carried out after the byte count in the frame is over and the reception is correct after error checking or the transmission of the physical layer notification signal is terminated (for example, the carrier cannot be detected). Frame identification. The format of the HART frame is shown in Figure 1.

PREAMBLE Preamble signal.
DELIM Delimiter: A unique or most easily recognizable character.
ADDR address byte: contains the source address and destination address, and the highest bit is used to indicate the address of the master device related to the frame.
COM command byte: Indicates the function to be performed by the field instrument.
BYTE CORNT total data length: This value represents the number of bytes from the next byte to the last (excluding check byte) of BYTE CORNT.
DATA Data bytes.
CHK Parity: Vertical parity.
The HART protocol in the data link layer is a “master/slave” protocol. In addition to the acknowledgment command that has been received in the reply message from the slave device, many messages also contain the data queried by the master device. The HART protocol allows two master devices to operate simultaneously in the system, a basic master device and a sub-master device. The slave devices distribute their respective reply command messages to the two master devices according to their different addresses.

2.3 Application Layer Specifications
It specifies 3 types of commands in the HART message package. The first type is a general command, which is applicable to all products that comply with the HART protocol and provides functional descriptions for devices that comply with the HART protocol; the second type is a common operation command, which is suitable for complying with the HART protocol. Most of the products; the third category is the device special command, which is suitable for special products that comply with the HART protocol.
3 Hardware design of intelligent electromagnetic flowmeter based on HART protocol
The hardware system circuit of the intelligent electromagnetic flowmeter with HART communication protocol adopts a modular design, which mainly includes four parts: sensor module, MCU module, HART communication module and human-machine interface module.
The low-frequency excitation current controlled by the single-chip microcomputer is output to the excitation coil of the sensor, and the tiny potential signal from the electromagnetic flow sensor is pre-amplified and sent to the single-chip microcomputer through the AD analog-to-digital conversion circuit. The single-chip microcomputer collects the data of these signals, analyzes and processes them, and sends them to the liquid crystal display screen to display the instantaneous flow and cumulative flow. At the same time, the single-chip microcomputer compensates the obtained flow value through the calculation formula, and realizes the remote communication with the upper computer through the HART communication module after the compensation flow signal.

3.1 HART communication module design
The HT2012 chip is used to realize the demodulation and modulation process of the communication signal in the HART protocol.
The demodulation process of HART signal: after the pulse signal output by the band-pass filter enters the HT2012, the modem demodulates the 1200Hz and 2200Hz in the pulse signal into digital 1 and 0 respectively, and then the digital signal is output from the ORXD port of the HT2012, and the CPU Judge the received data and perform corresponding tasks.

3.2 HT2012 and external interface
The HART digital signal specification is a sinusoidal AC current signal with a peak value of 1mA and an average value of 0mA. This signal is converted into a sinusoidal AC voltage signal through the line impedance. The input and output signals of the HT2012 are square wave signals of 0 to 5V. Therefore, in the HT2012 and the external A filter circuit and a shaping circuit are also required between the HART signals.
The filter composed of TLC27 is a band-pass filter, which is used to reduce the noise interference of the received signal. Filters are also used to smooth out the received signal by removing spikes in the waveform. The digital square wave generation circuit composed of TLC37 converts the sine wave filtered by TLC27 into a corresponding square wave, which is convenient for HT2012 to receive.
The function of the buffer 74HC126 is to flatten the rising and falling edges of the square wave, so that the signal meets the requirements of the rising and falling edges of the signal waveform required by the HART physical layer specification. Crosstalk with other networks can be reduced.
The HT2012 needs to provide a 460.8kHz clock signal externally, and the error of the clock frequency is required to be ±0.1%. If a 460.8kHz crystal oscillator is directly input, it will not only increase the power consumption of the system, but also the crystal oscillator is a non-standard crystal oscillator and needs to be customized. In order to solve this problem, a 1.8432MHz crystal oscillator is used in the system to generate the clock signal, which is then divided into 4 by the frequency divider CD4013, and the frequency division signal of 1.8432MHz/4=460.8kHz can be output for the HT2012.
AD421′s internal voltage regulator and external FET DN25D adjust the voltage input to AD421, which can provide +3.3V as the power supply for other devices. The FSK signal sent by HART is sent to AD421 through a capacitive coupling, and converted into a corresponding ±0.5mA sinusoidal current signal to realize the conversion of voltage signal to current signal. The exchange of information of the HART protocol is realized. The coupling capacitance of this circuit is taken as 0.0033μF.

4 Software implementation of HART communication protocol
4.1 Serial port interruption program of intelligent electromagnetic flowmeter
In the serial port interrupt service routine, first protect the scene, and then judge whether it is a receiving interrupt or a sending interrupt. If it is a receiving interrupt, execute the receiving service subroutine, otherwise execute the sending service subroutine. After the interrupt processing is over, restore the scene and return to the main program of the system. HART communication adopts the method of horizontal and vertical checking. When it is detected that there is an error in the received data, the master device will be notified that the data is received incorrectly after the command frame is sent to the master device. The master device resends the command frame to ensure accurate and reliable communication. The flow chart of the HART serial port interrupt subroutine is shown in Figure 5.

4.2 HART command split subroutine
Before responding to the command frame, the frame must be split, that is, it is first judged whether the preamble of the frame is correct, and the counter is incremented by 1 each time a preamble is received. Then receive the delimiter. If it is a valid delimiter and the preamble counter is greater than 1, it is the start position of the HART frame, and the type of the HART frame is determined according to the delimiter. If it is a response frame or a group mode frame, it will be terminated. Receive the service and wait for the end of the carrier; if it is a request frame, determine the frame format, set the received long frame format or short frame format address count value, the short frame format address receives 1 byte, and the long frame format address receives 5 bytes. Re-receive the command number, the data byte length byte, if there is a parity error in the data byte length byte, terminate the receiving service and wait for the end of the carrier; otherwise, set the data byte length counter, each time a data byte is received, the length counter Subtract 1, and finally receive the horizontal checksum. If the receiving request address matches, XOR the received HART frame with the horizontal checksum, and compare it with the received horizontal checksum, if the same, it means there is no communication error; otherwise, set the horizontal checksum error flag to 1, and end the receiving service And transfer to the HART command to execute the subroutine. The flow of the command frame splitting procedure is shown in Figure 6.

5 Conclusion
The test of the developed intelligent electromagnetic flowmeter shows that the flowmeter has a high degree of integration, strong functions, convenient operation and reliable performance; it has the functions of self-diagnosis, self-calibration and HART data communication; it can measure the flow in both positive and negative directions. It can also measure pulsating flow; it has good anti-electromagnetic interference and temperature performance, and is suitable for on-site measurement and display; the measurement range is large and the accuracy is high.

Post time: 25-05-22