Smart test
Design of Angle Measuring Instrument Based on AT89S51 Single Chip Computer
This paper analyzes the hardware composition and circuit design principles of angle measurement based on single-chip microcomputer. The workflow and source code of the main function are given. The design prototype has passed a variety of environmental tests.
is a key component of the aiming device in a certain control system. In the previous control systems, most of the equipment operators only use the eyes of the equipment operator to aim at the designated target, and then make the corresponding control, which brings a series of problems, such as the experience of the operator and the empty return of the aiming device turntable may be serious. It will affect the degree of aiming at the target, thereby seriously affecting the accuracy of the control system. In order to improve the aiming accuracy of the control system, components are added to the aiming device of the control system. The angle value of the operator after aiming at the target can be quantitatively displayed on the operation panel to help the operator aim at the target more accurately. Therefore, it greatly improves The degree of control of the control system.
Using a photoelectric encoder to read the angle value, using a single-chip microcomputer to realize the angle value digital display and the light-emitting diode indication function of the angle value deviation range (there are three indicator lights, respectively indicating: high, low, moderate). Regardless of the complexity of the operation or the accuracy of the measurement, it is incomparable to the traditional eye sighting method, scale measurement and marking method.
As an important technical improvement of the aiming device of a certain control system, the application of this instrument has greatly improved the accuracy of the aiming of the control system, increased the readability of the aiming deviation range, and eliminated the traditional method of measuring and marking the angle with the scale, making the control The overall performance of the system has been significantly improved. In addition, the angle measuring instrument can be widely used in other industrial control systems with slight modifications.
1 Basic principles of hardware
First, the angle measuring instrument uses a single-chip microcomputer to read the angle value measured by the photoelectric encoder, and then converts the angle value into a density value and displays it on the digital screen (Note: The density (mil) is an angle unit, and the density is 100 = Angle 6°). The single-chip microcomputer judges the deviation range of the current angle value, and gives a control signal to light up the corresponding light-emitting diode indicator. In addition, the angle measuring instrument can also be controlled by the switch on the control panel to realize the scope lighting and the automatic defrosting function of the scope under low temperature environment. The main function of the single chip microcomputer is to realize the angle value digital tube display and the light emitting diode indication of the angle value range. The difficulty of this system is to ensure the conversion accuracy of the angle value into the density value and the reliability of the system in a very warm environment.
The hardware is divided into the following modules: control panel, single-chip microcomputer, photoelectric encoder, power supply, digital display, LED matching indicating device, peripheral mirror and direct sight mirror lighting and defrosting, as shown in Figure 1.
1.1 Selection of Single Chip Microcomputer
First of all, according to the demand analysis of the project, it can be known that the main function of the single-chip microcomputer is: after reading the angle value from the photoelectric encoder (data bus width is 15 bits), the angle value is compared with the preset angle value of the system to judge The angle value range of aiming, light up the corresponding indicator. Then the angle value read from the photoelectric encoder is converted into a dense position value and sent to the serial LED display driver MAX7219, which is displayed on the LED display.
From the above analysis, it can be known that the MCU suitable for this requirement should have at least 3 8-bit parallel I/O ports (the photoelectric encoder occupies 2 ports, and the others occupies 1 port), in order to work effectively. As we all know, the quality of products is usually divided into three levels: military grade, industrial grade and commercial grade, among which, military grade and commercial grade. Since this industrial control equipment is usually operated outdoors and the working environment is relatively harsh, the quality level of the single-chip microcomputer is also an important factor that needs to be considered.
At present, MCS-51 series single-chip microcomputer technology is mature, there are many textbooks and technical materials used for development, complete development tools, rich product types on the market, high cost performance, easy purchase, and simple development language (you can use assembly or C51). Therefore, This series of products are widely used and enduring for a long time.
After comprehensive consideration, the single-chip microcomputer adopts the chip produced by ATMEL (the industrial grade product of the MCS-51 series single-chip microcomputer), compatible with the MCS51 microcontroller, and the 4K byte FLASH memory supports 1000 erasing and writing cycles in system programming (ISP). 128 bytes on-chip RAM, working voltage 4.0 V to 5.5 V, fully static clock 0 Hz to 33 MHz, three-level program encryption, 4 8-bit programmable I/O ports, 2/ 3 16 Bit timer/counter, 6/8 interrupt sources, full-duplex UART, low power consumption supports Idle and Power down modes, Powerdown mode supports interrupt wake-up, dual data pointers, and power-on reset flags. The 89 series single-chip microcomputers produced by ATMEL have extremely wide applications in the fields of industry, transportation, instrumentation, automatic production process, aviation, transportation, automobiles, home appliances and so on. The selected model is AT89S51-24PI of ATMEL Company, industrial grade. Can adapt to working environment-45 ℃~ + 80 ℃.
The I/O port resource allocation of the single chip microcomputer is: P0 and P2 ports are allocated to the photoelectric encoder, P1 port is allocated to the display drive and matching indicator light-emitting diode control and MAX813.
1.2 The design of the main peripheral circuit of the single-chip microcomputer
Monitoring circuit: In order to improve the reliability of the single-chip microcomputer in harsh environments, a μP monitoring circuit must be used to increase the stability and anti-interference ability of the single-chip microcomputer. The hardware monitoring circuit has the following functions: (1) Power-on reset: to ensure that the system can be started correctly when the system is powered on. (2) Power-down reset: When the power fails or the voltage drops below a certain voltage value, a reset signal is generated to reset the system. (3) Watchdog timer: When the processor encounters interference and the program runs chaotically and causes "deadlock", reset the system. The military-grade chip MAX813LMJA from MAXIM is used here.
Display drive circuit: In order to save the I/O port resources of the single-chip microcomputer and reduce the calculation amount of the single-chip microcomputer, the serial LED display driver MAX7219 is selected. It can control the 8-bit common cathode LED digital tube, with 16 levels of brightness control and flexible decoding , The light-emitting diodes are completely turned off when the power is on, and only three single-chip I/O ports are occupied.
The principle of the microcontroller and the main peripheral circuits is shown in Figure 2.
1.3 Data communication between single chip microcomputer and peripheral devices
Single-chip microcomputer and photoelectric encoder: because the speed at which the photoelectric encoder obtains the angle value is much faster than the working speed of the single-chip microcomputer, the single-chip microcomputer can think that the data on the photoelectric encoder is always in a "ready" state, and the single-chip microcomputer can read valid data at any time. The 16-bit angle value is divided into the upper 8 bits and the lower 8 bits to read twice, and the data between them is unconditionally transmitted in parallel.
MCU and MAX7219: Judging from the operating speed of the MCU and MAX7219, the time interval for the CPU to send data to the MAX7219 twice is enough to ensure that when the MCU accesses the MAX7219, the MAX7219 is always in the "ready" state. And the MAX7219 is a serial LED display driver, therefore, the data transmission between the microcontroller and the MAX7219 is serial unconditional transmission.
MCU and MAX813: Because when the MCU sends data to the MAX813, the MAX813 only waits to receive the initialization data of the MCU without any other work. Its working speed is fast enough, and it can be considered that the MAX813 is always in a "ready" state. Therefore, the data transmission between the MCU and MAX813 is also serial unconditional transmission.
2 Principles of Software Design
After the angle measuring instrument is started, the working process of the single-chip microcomputer is: after the system is started, the external watchdog is initialized, the display driver chip MAX7219 is initialized, the watchdog counter is assigned the initial value, and the angle value obtained by the photoelectric encoder is read. When the deviation value is in a certain range, the single-chip microcomputer sends a control signal to light up the indicator corresponding to the range, converts the current angle value into a dense value and displays it on the digital screen, and then re-assigns the initial value to the watchdog counter , Enter the next work cycle. The workflow of the main function is shown in Figure 3.
Please note that in the flowchart, a rectangular box with a double-line border indicates that this part is a function. In the software design of this subject, the C51 programming language is used, because programming with C51 is not only efficient, but also highly readable.
The source code of the main function is given below.
Void main (void)
{
WDI = 0; / / Initialize the watchdog
InitMax7219 (); / / Function to initialize MAX7219
While (1) {
WDI = 1; //"Feed the dog"
WDI = 0; //"Feed the dog"
GetAngle (); / / Function to read the angle value
MachView(); / / The indicator matches the displayed function
GetMil (); / / The function to calculate the secret value
DisplayMil (); / / The function of displaying the secret position
}
}
Among the several functions called by the main function, the function of InitMax7219() is to initialize the L ED display driver MAX7219, and the single-chip microcomputer sends the anti-shading control, brightness, scanning range, and decoding mode information to the MAX7219.
The function of GetAngle () is to read the angle value from the photoelectric encoder, first read the high 8 bits, then read the low 8 bits, then combine the high 8 bits and the low 8 bits, and discard the bits (the effective data of the photoelectric encoder is 15 bits ).
The function of MachView() is to match and display the angle deviation indicator, compare the angle value with the preset angle value of the system, and judge whether the aiming angle value is high, low or moderate. If the angle value is too high, the microcontroller will issue a control command to make the high indicator light, if it is low, the low indicator light will be on, otherwise the moderate indicator light will be on.
It is worth noting that the coding of the function GetMil() for calculating the density value should consider the conversion accuracy of the angle. In this subject, the long variable in C51 is used to store the integer and decimal parts of the density respectively, and Enlarge the decimal part of the angle one hundred thousand times and participate in the calculation to ensure the conversion accuracy.
DisplayMil( )'s function is to drive MAX7219 to display the secret position. First display the secret position, and judge whether the angle enters the preset area, if it is, turn off the symbol light, and the digits will display "0"; if not, judge whether the angle value is negative, if it is, display a negative sign, if it is positive, do not display negative And then display the angle value on the LED display.
3 Concluding remarks
In order to enable the angle measuring instrument to work normally under various possible harsh environments (such as high temperature, low temperature, vibration, etc.), in the entire design process, the issues to be considered are the reliability of the hardware and the reliability of the software. The precautions during design are as follows: (1) The power supply chip's rated power selection should leave a margin. (2) Select industrial-grade or military-grade products for components. (3) The hardware watchdog scheme is adopted to prevent the microcontroller program from locking up. The prototype designed in this topic is already in the testing stage, and has passed the tests of room temperature and various environmental tests.