4.6 Data processing algorithm

This part of the program mainly performs resistance calculation, error correction, digital filtering, code conversion and other processing. Data processing program idea: First, the voltage binary data stored in the data storage RAM is merged into a 12-bit binary number, and then the loop resistance value parameter is calculated, and error correction and arithmetic average filtering are performed. The voltage value obtained by the test and the calculated loop resistance value are converted into BCD code and displayed on the LED. The data processing program is shown in Figure 4.4. In order to further improve the anti-interference ability of the system and ensure the high accuracy of the test, the obtained measured value is digitally filtered. After eight measurements, the maximum and minimum values ​​are removed and the average value is taken. After software and hardware filtering, the system error will be significantly reduced.

Digital filtering part: Use software to reduce or eliminate the measurement error or the useless part of the voltage value. The input signal is the digital quantity after the analog signal is sampled and A/D converted, and the converted digital quantity is calculated. The arithmetic average filtering is performed on the loop contact resistance value calculated multiple times. The arithmetic average filtering is to continuously take n digital values ​​for sampling and then perform average arithmetic. The number of sampled values ​​n depends on the specific situation. When calculating the resistance value, take 8. Use the microcontroller software to correct the system error: detect the standard resistor, and use the measured value of the standard resistor to correct the error of the measured value of the measured resistor to correct the comprehensive gain coefficient including the gain of the 0PI "amplifier and the gain of the ADs78os type A/D converter.

In order to improve the calculation accuracy, floating point calculation or double precision and high precision (2 and 4 bytes respectively) can be used. Because the test current peak is 1 A, the loop resistance test range is 0.01mA-1.9999k., so the contact voltage range is 0-2/105V. When the contact voltage is in liters of UV, it should occupy 3 bytes when stored, but in order to consider the calculation accuracy, when calculating the loop resistance and digital filtering, this system uses 4 bytes for calculation.
A/D conversion subroutine
 

4.7LBD display subroutine

The display driver chip used in this tester is MAX7219. Its display subroutine first initializes the interrupt to make the interrupt work in mode 1, and then reads the data in the display buffer. The display buffer is mainly used to store the data to be displayed. The LED display subroutine flow chart is shown in Figure 4.5. [page] The

glyph code of each number is stored in a fixed area in the memory in order from small to large in hexadecimal, forming a display code table. When a certain resistance value is to be displayed, the starting address of the table is sent to the data pointer register DPTR as the base address, and then the data in the display buffer is sent to the index register A as the offset, and then the table lookup instruction ', MOvCA, @A+DPTR" is executed, and the result obtained in accumulator A is the glyph code of the corresponding number taken out of the table.

Data processing subroutine

4.8CPU Internal Timer/Counter Design

The CPU internal timer/counter design of this system adopts the following method: Timer working mode 1: The timer/counter works as a 16-bit plus 1 counter, which consists of the high 8-bit TH and the low 8-bit TL. Before the timer/counter starts working, the CPU must first load the mode control word for it to set its working mode, then load the timer/counter initial value for it, and start its work through instructions. The

16-bit counter counts as an plus 1 counter. When the count reaches zero, it can automatically send an overflow interrupt request to the CPU, but if it is to count again, the CPU must reload the initial value for it in its interrupt service program. The timing main program includes initializing the internal timer of the microcontroller and setting the initial value of the software counter. Since the timer needs to be timed for 50Ins, it must work in mode 1. The timing initial value of T0 is:

In the above formula, M is the modulus value, the pong number is 12 times the microcontroller clock cycle, and W is the timer initial value 15. The CPU internal timer/counter program flow chart is shown in Figure 4.6.[page]

CPU internal timer/counter program flow chart

4.9 Software Reliability Design

While improving the anti-interference capability of the hardware system, the anti-interference design

of the software should also be carried out. There are usually several methods for software reliability design:

1. Digital filtering

(1) The arithmetic mean method samples the value of a certain point multiple times continuously and takes its arithmetic mean. This method can reduce the impact of random interference of the system on data acquisition;

(2) The comparative selection method samples a certain point of data multiple times continuously to eliminate large deviations;

(3) The median method samples a certain point value multiple times continuously, sorts them in order, and takes the middle value as the sampling result;

(4) First-order recursive digital filtering method

This method uses software to complete the Rc low-pass filter algorithm instead of hardware to implement Rc filtering. This system uses the arithmetic average method for digital filtering, that is, the value of a certain point is sampled multiple times continuously and the maximum and minimum values ​​are eliminated, and then the arithmetic average is taken. The advantage of this method is that the value can be more consistent with the actual resistance value, with a small deviation, which can reduce the impact of random interference on data acquisition and filtering errors.

2. Set software traps

When the system is disturbed, the program counter PC value may change, causing the system program to execute in a different program area instead of in the predetermined order, or causing the PC value to exceed the program area, and the random number in the non-program area to be used as the instruction code, affecting the normal operation of the system.

To this end, this system also uses the method of setting software traps to ensure the software reliability of the system. In this software system, instructions are arranged in the non-program area to force the system to reset. No matter which byte in the non-program area the PC flies to after it loses control, the system can be reset.

3. Apply "watchdog" technology

Setting software traps can solve the problem of some programs running out of control, but when the program enters an abnormal infinite loop, the software trap may not work. This software system also sets a software "watchdog". The application of "watchdog" technology can restore the program from an infinite loop to a normal state. The "watchdog" is a time monitor. The soft clock uses the on-chip timer/counter. The timing time is longer than the time required to execute a normal program loop.

When the program runs normally without interference, the CPu resets the time constant of the soft clock and resets it at regular intervals. The reset time should be shorter than the set timing time so that the system can work normally without being affected. When the program cannot run normally due to interference and falls into an infinite loop, the soft clock runs to the predetermined timing time because the reset pulse cannot be issued in time. The soft clock can generate an interrupt and perform corresponding processing in the interrupt service subroutine.

The software "watchdog" uses an internal timer for timing. At this time, its overflow interrupt should be set as a high-level interrupt.

After starting the software "watchdog", when the system runs normally, the program must reset the time constant of the timer within the timer's set time, so that the timer does not generate an overflow interrupt; when the program falls into an infinite loop, it cannot reset the time constant of the timer within the timer's set time, so that the timer generates an overflow interrupt, and the program exits the infinite loop by executing interrupt processing. In the interrupt processing program, error processing must be performed and the system must be reset by software.

The "watchdog" software is applied in this system to ensure the reliability of software operation. This is also a common method used by many test and measurement instruments to prevent abnormal infinite loops in the system.