Design of Control Unit of Mechanical Property Test System of Tai Lake Shield

This paper focuses on the design and implementation of the detection device. This paper discusses that the control unit realizes the stepping drive by the interrupt method, realizes the force acquisition and the Modbus RTU communication by the polling method, designs the main program, the force acquisition subroutine flow, the stepping driver subroutine flow, and the Modbus slave subroutine flow, and realizes it through the Arduino IDE programming. Design the host computer interface, database association and command language programming; At last, the application effect of the test system is verified by the tensile test of water shield stem of taihu lake.


Introduction
The current domestic and foreign water shield research mostly focused on biology, nutritional point of view, for edible, medicinal, processing and application development, production operation direction, and the rare for planting, picking the growth characteristics and biomechanical characteristics of Tai Lake water shield research almost vacant, an urgent need to analysis and study of Tai Lake water shield roots. stems. leaves and other kinds of the mechanical properties of the material data, plant equipment, mechanization picking and processing equipment development provide the basis for reference.
The other Suzhou research the mechanics characteristics of "water" the eight immortal vegetables also is relatively small, a small amount of research literatures mainly in lotus root tuber, Gordon fruit seed, water chestnut and other vegetables. The corresponding literature of Tai Lake water shield has not been found in the database of knowledge network. This paper introduces the automatic test function, improves the mechanical property test system performance, and further summarizes the improvement. The main contents of the paper include: (1) Hardware design and implementation of control unit; (2) Software design and implementation of control unit;

Hardware design and implementation of control unit
Mega2560 is adopted as the main controller in the control unit. Arduino Mega 2560 supports pc-based ICSP and USB SCM programming, and supports JTAG programming, debugging and troubleshooting. In this project, Mega 2560 is mainly used to control motor operation and data acquisition, and communicate with the host computer through the serial port.

Circuit composition design of control unit
The hardware composition of the control unit is shown in Figure 1, including the sensing detection circuit, the drive circuit and the communication circuit. The communication circuit adopts the serial port converter Tmega16U2 USB-to-TTL which comes with Mega2560. The sensor detection circuit includes limit switch, AD converter circuit of output voltage of force sensor. The seven-star insect LY-S0051 limit micro switch is selected and fixed at the limit position on the upper and lower sides of the frame sleeve movement. The controller Mega2560 is used to inquire the limit switch signal to control the operation of the stepper motor and prevent the sleeve movement from exceeding the range. HX711 is selected to realize AD conversion of output voltage of force sensor. HX71 converts the output voltage into a 24-bit digital signal, and the theoretical accuracy can reach 1/2 23 , higher than the test design requirements of 0.1g. HX711 transmits data to Mega250 via its own single bus protocol.
MT530 is selected as the driver of the 42BYGH40-400S82 stepping motor of type 42. Three sets of control signals are input: step pulse signal (PUL+, PUL-), direction level signal (DIR+, DIR-), step enable signal (EN+, EN-), and two sets of output circuits (A+/A-, B+/B-) are connected with the two winding of the stepping motor respectively.

Circuit realization of control unit
HX711 is powered by VCC and GND on Mega2560, and HX7111 pins PD_SCK and DOUT are connected with Mega2560 pins D5 and D6 respectively to realize single-bus communication. Normally open contacts of upper and lower limit switches are connected with Mega2560 pin D3 and D4, respectively. After the touch of the micro slide switch, it is conducted, and a low level appears on the corresponding pin.
The stepping driver adopts common cathode connection: the pin PUL-, DIR-, and connect to the signal ground of Mega2560, the pin EN+ connects to the pin D4 of Mega2560, the pin DIR+ controls EMCEME 2020 IOP Conf. Series: Earth and Environmental Science 692 (2021) 042105 IOP Publishing doi:10.1088/1755-1315/692/4/042105 3 the rotation direction, the high level is positive, the pin D5 of Mega2560, the pin PUL+ controls the pulse, and the pin D6 of Mega2560.
Mega2560's TTL serial port 0 pin D0 (RX). D1(TX), by its own Tmega16U2USB-to-TTL module, complete the serial port TTL and USB conversion, and connect with the USB interface of the upper computer to achieve soft serial port communication.
In actual debugging, Mega2560 should be kept away from the stepping drive to reduce interference, so as not to affect the reliability of its communication with the upper computer.

Software design of control unit
The main controller mainly needs to complete tension data acquisition, stepper motor drive (including limit status query), and communication with the upper computer. The control program is written and debugged in Arduino IDE.

Upper-level data definition of communication
The communication between the controller and the upper computer is realized through the serial port. According to the communication protocol selected by the upper computer state software Kingview7.5, the upper data frames are designed in accordance with the Modbus RTU protocol.
In this project, 5 upper parameter variables are defined to meet the monitoring needs of the upper computer, including tension, deformation (number of stepping pulse), bidirectional limit state, motor running direction and motor speed (frequency of stepping pulse). From the perspective of upper computer, the first three parameters are read only and not written, and the last two parameters can be read and written. The host computer state software periodically sends information frames to the main controller, which responds to the current values of each parameter and executes the operation command.
In order to reduce the calculation of the main controller, improve the speed and precision of the operation. The 24-digit quantity collected from HX711 is used as the tension parameter, and the number of stepping pulses is used as the deformation parameter. It is transparently uploaded to the top machine and converted to the corresponding tensile deformation value and tension value by the program on it. According to the design requirements, the maximum test stroke is 100mm, the bidirectional motion range of the drawing rod is 200mm, and the pulse step distance of the motor set in the detection device is 3.125um, so the bidirectional pulse counting range is from-32000 to 32000.
According to the Arduino programming specification, the length of an int variable is double bytes. In this project, one global variable is defined, and the int array para is used to represent the five parameters. The tension parameter is represented by two array elements. Deformation parameters, using 1 array element can meet the pulse count requirements. Bidirectional limit state, by the upper and lower limit switch of the two-bit state combination into an array element. Motor running direction and motor speed are represented by 1 array element.

Controller main program design
In the main program initialization, each associated pin number and data direction is specified according to the hardware connection. The controller adopts serial port 0 for Modbus slave station communication, and sets the communication baud rate of serial port 0 as 115200.
In the main program, polling calls Modbus slave station communication subroutine to achieve the transmission of upper data; Polling call force acquisition subroutine, detection data acquisition.
In the design, it is necessary to control the pulse cycle of stepping drive according to the speed (stepping pulse frequency) set by the upper computer. The main program polls the upper data para and reads the current driving pulse frequency. If the value changes, the timing interrupt will be turned off first, and the timing interrupt will be turned on again after the interrupt timing time is reset according to the new pulse half-cycle.
The timing interrupt program calls the step driver subroutine, controls the state of the PUL pin to reverse, and realizes the single pulse control of the step motor.

Force acquisition subroutine design
HX711 is A 24-bit AD converter chip for high-precision weight sensor, with dual-channel (channel A and channel B) measurement function. The internal integrated stabilized voltage power supply, inchip clock oscillation circuit. The on-chip stabilized power supply is available for external sensors and on-chip AD converters. The programmable gain of channel A is 128 or 64, and the amplitude of the corresponding full-limit differential input signal is ±20mV or ±40mV, respectively. In this project, channel A is adopted to measure, and the gain is 128. According to the manual of HX711, the timing of output data is shown in figure 2. Where T 1 >0.1us, T 2 <0.1us, T 3 >0.2us, T 4 >0.2us, the output IO port connected with pin PD_SCK, began to send square wave (clock), each square wave read 1 bit of data, data total 24 bits.1234At least 25 pulses are sent by the controller, the first 24 are used to read the data of this AD conversion, and the last one is used to select the channel and gain of the next conversion.
The data conversion frequency of HX711 can be divided into 10Hz and 80Hz, and the general chip is 10Hz, 10 times of conversion within 1s. In this project, the data acquisition cycle of the upper computer is designed to be 100ms, and 10Hz conversion is selected to meet the use requirements.
The serial port communication line consists of pin PD_SCK and DOUT to output data, select input channel and gain. When the data output pin changes from high level to low level, 25 clock pulses are output to PD_SCK by the pin D5 of Mega2560. The measured 24-bit data is read out in order from MSB to LSB, and the state of the next data collection is maintained.
The data reading subroutine flow is shown in figure 3. If the data output pin DOUT of HX711 is high, it indicates that its AD converter is not ready to output data. At this time, the serial port clock input pin PD_SCK should be low, that is, the lead D5 of Arduino is low. When the lead D6 of Arduino detects that DOUT is low, the lead D5 outputs 24 clock pulse (counted by CNT of char). At the stage of each clock pulse, the bit state output from the DOUT pin of HX711 is read from the pin D6 to form the 24-bit measurement data, which is recorded by the long variable MTR. When the 24 pulses are finished, the 25th pulse is sent from pin D5, indicating that the next data acquisition is still channel A and the gain is 128.
The 24 data output of HX711 adopts the complement format, with the highest bit representing the direction of force. After obtaining the 24-bit measurement data, the main controller performs an x or operation with 0X800000 to obtain the original code value, and converts the value into two int variables, which are respectively assigned to para [0] and para [5] as the high 8-bit and low 16-bit values of tension parameters.

Step motor drive subroutine design
The driver subroutine of the stepping motor is called by the interrupt program after each timing period. Its control flow is shown in figure 3. According to this, the high and low level of the pin DIR+ in the driver is controlled to determine the steering. The pin EN+ is set to the high level to step enable, and the pin PUL+ level is reversed to generate the drive pulse. Para [1] represents the step distance between the running distance of the stepping motor and the zero point. After the communication and After the motor runs for one step, it is necessary to read the state of pin D2 and D3, collect the current upper and lower limit switch trigger, and form the lower two bits of para [2], which are used for the upper computer to communicate and read, and then the upper program determines the running state of the motor. According to the provisions of Kingview7.5 as the Modbus master station and the communication between the slave station and the Modbus master station, the master controller as the slave station in this project involves two kinds of communication functions. One is to read multiple registers with function codes of 03H, which are used for the upper computer to read all 5 parameters defined. The second is to write a single register, the function code is 06H, used for the upper computer to rewrite the motor running direction or speed in 5 parameters.
This project involved in the read operation message format as shown in Table 1 and Table 2, downlink message data fields including read starting address register (0000 H) and quantity (0006 H), each have two bytes, reads the correct return message data fields including returns number of bytes (0CH), five parameters of data, a total of 12 bytes, and message before 16 bytes of CRC code. The format of the write operation message is shown in Table 3 and Table 4. The data domain of the downstream message includes the start address of the write register (0003H or 0004H) and the quantity (0001H), each occupying two and two bytes, and the data to be written, occupying two bytes, as well as the CRC check code of the first six bytes of the message. So, the maximum frame length involved in this project is 18 Bytes. In order to reduce the code redundancy, the general checking function of Modbus after receiving information frames from the station is removed, and the information frame exceeding condition that will not occur in the project is removed, such as the processing of reading and writing data address exceeding range, reading and writing data quantity exceeding range and so on.

Conclusions
This paper mainly states the design of control unit of mechanical property test system of Tai Lake shield. And the main innovation points of the paper are as follows: (1) Design a general basic stretching mechanism, use a stepping motor to drive the lead screw to achieve basic stretching, design a special extension module, after loading to achieve the corresponding test function, increase the flexibility and applicability of the test device.
(2) According to different real-time control requirements, the main controller adopts polling and interrupt modes to realize the communication of the upper computer and the control of the driver of the lower computer.
(3) Using the configuration software to develop the test interface and data recording task of the test project, and project, and using the Modbus RTU protocol communication to realize the manual automatic control function of the test.