Academic Journal of Science and Technology ISSN: 2771-3032 | Vol. 7, No. 2, 2023 4 Design of Portable High Precision Scale Hardness Tester Based on STM32 Xiaoyu Lu*, Xiaozhe Li, Feng Qiu Chengdu University of Technology, Chengdu 610000, China * Corresponding author Abstract: Hardness measurement is a very important index in the process of production and quality inspection. In the past, the precision of portable hardness tester is low, and the stability is poor. Combined with the internal high-speed ADC of the STM32 hardness tester can achieve a more demanding test accuracy requirements. Low power consumption, high accuracy and reliability of data acquisition is realized. And designed with the stemwin library can do more perfect function, human-computer interaction interface is more friendly. Keywords: Portable hardness tester, STM32, High-precision. 1. Introduction The hardness tester is a measuring device that has developed rapidly in China and even internationally, which means that the hardness testing link is becoming more and more important in the experimental process and production process. The hardness parameters of different materials reflect the mechanical properties and internal structure characteristics of different materials [1]. For different materials and different test environments, it can be divided into the following hardness test methods: Brinell hardness, Leeb hardness, Vickers hardness, Rockwell hardness, Shore hardness [2]. In the field of portable hardness testers at home and abroad, the measurement method is basically Richter measurement [3]. The principle of Leeb hardness measurement is to use kinetic energy loss to detect the hardness of materials such as metals [4]. However, due to the influence of power consumption, cost, accuracy stability of ADC and signal conditioning, the accuracy of the data obtained by the commonly used portable hardness tester is generally 1%-5%, which does not have high reference [5]. The portable Leeb hardness tester designed based on the STM32F4 series can effectively improve the accuracy of data acquisition to 0.5% without increasing power consumption, cost and development difficulty. 2. System Design and Analysis 2.1. Analysis of the working principle of the Leeb hardness tester Figure 1 shows the measurement principle of the hammerhead of the Leeb hardness tester, and the calculation method is as follows: HL=1000× (VB/VA). where HL stands for the Leeb hardness value; VB stands for impactor rebound velocity; VA stands for Impact Body Impact Velocity. It can be seen that as long as the controller obtains VB and VA, the result can be calculated [6]. Figure 1. Schematic diagram of the output signal of the impact device 2.2. System architecture of hardness tester Figure 2 is a functional overview diagram, in which the round frame is the hardware module, the square frame is the software module, and the STM32f407VGT6 is the core of the system. In the figure, sensor data acquisition, battery voltage acquisition and sensor type identification are input to the chip with analog signals; The LCD display is connected to the chip via the FSMC bus; The print head interacts with the chip data through the serial port USART; The EEPROM and chip thatrecord historical data are connected via the IIC bus. Figure 2. Function overview 3. Hardware Implementation The STM32f407VET6 is a 32-bit controller manufactured 5 by ST using an ARM® 32-bit Cortex-M4® CPU with FPU. Its core operates with clock cycles up to 180Mhz, abundant on-chip resources, 1Mbyte on-chip flash and 192K on-chip RAM, 3 12-bit, 2.4MSPS AD converters, 3 IIC controllers and SPI controllers, 16-bit FSMC interface, can be connected to external RAM, FLASH, or screen with LCD controller. In summary, this chip is enough to complete the function of a portable hardness tester. And the accuracy is high and the stability is good. In the sensor data acquisition module, the second wire (analog input) of the sensor hammer is directly connected to the corresponding pin of ADC1 of the STM32, according to the actual measurement, The reference voltage between VA and VB in Figure 1 is 1.2V, so the voltage of the first wire (excitation voltage) of the sensor hammerhead needs to be adjusted to 1.2V, and when the sensor hammerhead with voltage excitation is used to hit the test block with a nominal hardness of 960HL, the peak voltage reaches 2.4V, so 2.5V is chosen as the reference voltage for the ADC. From this, the voltage output of the ADC is calculated as follows: voltageV (MV) = ( X * 2500 )/ 4095 w X represents the return value of the STM32 on-chip ADC read library function, which needs to be divided by 4095 because the ADC is configured to be 12 bits. Figure 3 shows the different types of probes used in the Leeb hardness tester, depending on the material and weight of the impact block inside the probe. In the sensor type identification module, the identification of DC, DL, C, G, D+15 and E-type probes is carried out by the internal resistance of the different probes. Therefore, the third wire of the sensor hammerhead is connected to ADC2, and different probe types are judged according to the different voltage values collected by the chip. Figure 3. Different types of probes for Leeb hardness t esters The power supply uses lithium battery, the voltage is 7.4V, before providing the working voltage, the voltage needs to be reduced to 3.3V and 5V, 3.3V for the normal operation of the chip, etc., 5V to provide the print head of the thermal printer to work. Before collecting the supply voltage, because the reference voltage is 2.5V, it is necessary to decay the voltage in the fully charged state (7.4V) to 2.5V and then connect it to the ADC3 pin of the STM32. In the printer module, USART communication is used, and the print controller connected to the thermal print head selects ZLG's ZY-TP01 micro thermal printer driver chip, and only needs to configure the serial port of STM32 when using, and then transmit the information that needs to be printed to the printer chip. The power consumption of the thermal print head is large, the voltage during normal use is 5V, and more than 2A of current needs to be provided, so LM7805 is used for power supply. The last hardware module is the button and the display module, which are the two modules used by users the most, and first need to consider real-time and aesthetics and convenience. Due to the large architecture of the overall software and the large number of business layers, most of the keys are processed in the interrupt mode. In addition to the ordinary key, there are two special keys, one is the printer test key, this key is directly connected to ZY-TP01, under the premise of normal work, the use of this key will make the printer print the standard test words. Another special key is the switch button, which is directly connected to the PA0 pin of the STM32, which is the only pin of the STM32 chip that can respond to the wake-up signal in standby mode. Figure 4 shows the distribution of keys. . Figure 4. Key bitmap The above keys are connected to the seven interrupt lines of EXTI0, EXTI1, EXTI2, EXTI3, EXTI4, EXTI5-9, and EXTI10-15. Among them, 0-4 are 5 independent interrupt lines, connected to 5 buttons, and the remaining keys are queried after entering the interrupt to determine the specific key. In the display module, an LCD screen with an ILI9342 controller with a resolution of 320x240 and a size of 3.5 inches is used. ILI9342 controller has GRAM and other components inside, so when using ILI9342 to drive LCD, the way is similar to operating external RAM, in STM32, the controller that operates external RAM and FLASH is called FSMC bus, here FSMC is connected to ILI9342 to operate in 16bit mode. In order to display a more beautiful human- computer interface, ST's customized stemwin graphical interface library is ported to the project. Figure 5 shows the interface ported to stemwin and written through this graphics library. Figure 5. Port the stemwin library and write the effect of the interface 6 4. Software Implementation In the process of data acquisition, there are four points that affect the accuracy of the entire instrument: the first is the accuracy of the sensor probe; The second is noise and distortion during analog signal conditioning; The third is the stability, number of bits, and speed of AD; The fourth is the algorithm of data processing and calculation after the signal is collected by AD. We can optimize the latter three cases. In the design of portable hardness testers at home and abroad, most ADCs use a sampling rate of about 10k and the number of bits is 8 bits. After testing, the sampling cycle of a sensor is about 2ms, as shown in Figure 6, the sampling rate AD of 10k can only collect 20 points in a sampling cycle, which is not conducive to later data processing. Moreover, the resolution of an 8-bit ADC can only reach 1mV in the case of a 2.5V reference voltage, while in the case of a 12-bit ADC with a sampling rate of 2.4Msps, about 48,000 samples can be collected in 2ms, and the resolution can reach 0.0625mV, reducing quantization error and random error [7]. Figure 6. Analog signal acquisition before entering the ADC Looking at Figure 5 again, according to the formula of Figure 1, the values required to calculate the hardness value are a maximum and minimum value during the sampling period, that is, according to the reference voltage of 1.2V, the rms VA and VB minus the maximum or minimum value minus the reference voltage can be obtained [8]. Table 1 shows the first 10 actual data of the ADC sampling output, when the minimum voltage is 0.8V, it can be seen that the first two data collected by the internal ADC of each STM32 are invalid data, starting from the third data, the average of 10 numbers is used as the minimum value in succession, and then the data of the entire sampling period is sorted, the average of the largest 15 data is used as the maximum, and then the sensor directivity operation is performed [9]. Table 1. ADC sampling output data 0 828 1309 1307 1307 1307 1310 1309 1310 1310 Here is the sample code: for(i = 0; i < 42000; i++) { HLA[i] = MSS_GetHL(); } for (j = 0; j < 42000; j++) { for (i = 0; i < 42000 - j; i++) { if (HLA[i] > HLA[i + 1]) { t = HLA[i]; HLA[i] = HLA[i + 1]; HLA[i + 1] = t; } } } for(i=0;i<15;i++) { sum +=HLA[i+41985]; } avgvota = (sum/15); sum = 0 ; for(i=0;i<15;i++) { sum +=HLA[i+2]; } avgvotalow = (sum/15); Bavglow = 2000 - avgvotalow; In addition, in the signal conditioning of analog signal input, the input signal is a volt-level signal, so the amplification required is small, and the low-amplification low-noise linear amplifier OPA2227 is selected. After coordinated processing of software and hardware, the accuracy of the measurement can reach ±0.3%. Considering that if the sensor hammer head is used for too long, it will cause deformation, wear and other problems, and it is necessary to design a calibration module, so when calculating the VB parameter, a G value is added as a small correction value, and the calculation formula is as follows: HL=1000×[(VB+G)/ VA ] So the code for calculating the hardness value with directionality is as follows: switch (DIRECTION){ // 0 represents downward direction, 1 represents 45° down, 2 represents horizontal, 3 represents 45° obliquely up, and 4 represents direction up case 0: Bavg=avgvota-2000+G1; HL_float = ((float)(Bavg)/(float)Bavglow)*1000; HL = (uint16_t)HL_float ; break ; 7 case 1: // Bavg=avgvota+G2-2000; HL_float = ((float)(Bavg)/(float)Bavglow)*1000; HL = (uint16_t)HL_float ; break ; case 2: // Bavg=avgvota-G3-2000; HL_float = ((float)(Bavg)/(float)Bavglow)*1000; HL = (uint16_t)HL_float ; break ; case 3: // Bavg=avgvota+G4-2000; HL_float = ((float)(Bavg)/(float)Bavglow)*1000; HL = (uint16_t)HL_float ; break ; case 4: // Bavg=avgvota-2000+G5; HL_float = ((float)(Bavg)/(float)Bavglow)*1000; HL = (uint16_t)HL_float } Calibration and measurement is a reverse process, during the calibration process, a standard test block is required, and when VA, VB, and HL are known, G values in different directions can be tested [10]. Save the G value in EEPROM for easy recall the next time you use it. In the remaining EEPROM space, 50 sets of test data and related information can also be stored to form historical reports. 5. System Testing and Result Analysis After the whole system is integrated, the comparison table with the standard hardness test block with a nominal value of 779 measured by the ordinary domestic Leeb hardness tester with an accuracy of 3% is shown in Table 2: Table 2. Comparison of standard test blocks with a nominal value of 779 Test piece Measured value This system collects data 780 779 775 776 779 778 779 776 778 776 3% accuracy Leeb hardness tester 770 765 762 773 768 771 771 768 770 771 Table 3. Comparison of standard test blocks with a nominal value of 500 Test piece Measured value This system collects data 52 0 499 499 500 499 500 501 500 500 499 3% accuracy Leeb hardness tester 49 2 490 495 495 488 493 490 492 492 492 It can be calculated from Table 2 and Table 3 that the test accuracy of the whole system reaches 0.5%, which is higher than the hardness tester with an accuracy of 3% [10]. 6. Conclusion The high-precision portable hardness tester solves the problem of low accuracy and accuracy of the previous portable hardness tester from the three aspects of analog input signal conditioning, ADC data acquisition and algorithm, and after testing, the accuracy is improved to 0.5% in the hardness standard test block with hardness values of 779 and 500. References [1] SUN Qingjun, ZHOU Xiaojiang, PAN Ying. Error analysis of Brinell hardness and Rockwell hardness measured by Leeb hardness tester[J]. Metrology and Testing Technology. 2014 (11): 50-51. [2] CAI Xiaoyan, YE Liming. Discussion on the verification and influence verification analysis of Leeb hardness tester [J]. Science and Technology Information, 2020, 18(12): 53+55 [3] WANG, Ningxi, LUOXin, GAO Jianzhuo, et al. Traceability analysis of Leeb hardness measurement benchmark based on sequence quantity [J]. Metrology Science and Technology, 2022, 66 (11): 37-40. [4] XU Yong, YE Gang, BIAN Qingqing, JIANG Liangzhong. Data acquisition application based on A/D conversion least squares method [J]. Microcomputer information. 2009 (11): 280-282. [5] CHEN Yun,WEI Tianhuan. Research on undersampling and oversampling technology [J]. Information and communication. 2015 (04): 18-19. [6] LI Li,GAO Li. Accurate measurement of temperature by oversampling and averaging [J]. New technology and new process. 2005(03): 25-26. [7] ZHANG Fenglin. Advances in portable hardness tester testing technology[J]. Physical and chemical testing-physical volume, 2022, 58(10): 5-12.