1. The necessity of using PC to realize single chip microcomputer optimization control
At present, the control of single-chip microcomputer is very extensive. However, for complex field control, most of the control programs of single-chip microcomputer are written in a single assembly language.
Its disadvantages are:
1. Due to the limitation of assembly language function, it is impossible to form a friendly control interface and cannot well reflect the real-time changes of the control site.
2. Different single-chip CPU chips require different assembly languages, which have poor portability and increase the difficulty of programming.
3. When the process conditions of the controlled object change, it is difficult for the microcontroller to follow the changes. Unless the program is reprogrammed and solidified again, it will be difficult to operate.
The author adopts the combination of PC high-level language programming and MCU assembly language programming to solve the above shortcomings.
2. Implementation process
The PC sends various preset signals to the single-chip control system through the serial port, and then the single-chip system generates actual analog signals through D/A conversion and sends them to the site; the preset values can be displayed on the software window of the PC. At the same time, the signal measured by the sensor on site is sent to the single-chip microcomputer for analysis and processing through A/D conversion, and the error data is obtained by comparing it with the preset value. The error data is sent to the control site for precision adjustment, thus forming a closed-loop control system. At the same time, the single-chip microcomputer sends the measured accurate data to the PC through the serial port and displays it on the software window for the operator to view, record and adjust the control. The key is that if the process conditions of the control object change, you only need to change the preset data to the required data on the PC. In the following system example, the author uses a temperature control system developed by himself.
1. Microcontroller assembly language part
After designing the control circuit, the initialization part of the microcontroller control is completed using traditional assembly language. The initialization includes the serial port receiving and sending data, A/D, D/A and other functions. The rest is completed by the PC. Most readers are familiar with this part, so I will not go into details here. For details, please see the example demonstration part below. It should be noted that the program interface and implementation process of serial communication should be left in the initialization program.
(II) PC high-level language part
In the PC high-level language programming, the author uses VISUAL BASIC high-level language. VISUAL BASIC (VB) is an object-oriented high-level programming language launched by MICROSOFT. It is popular among programmers for its simple programming, rich ActiveX controls, good portability and powerful functions. Therefore, VB is used in the high-level language programming of this system.
1. Completion of the control interface
This system is explained using the temperature control system as an example.
Using high-level language programming, a very friendly and intuitive human-machine control interface can be compiled on the PC. The original direct human control is changed to indirect control by mouse and keyboard; and the control can be easily realized through the intuitive control interface, and the control situation on site is clear at a glance, which increases the operator's visual sense and sense of security and simplifies the operation.
The control interface includes: on-site data display, preset data input, upper and lower limits of on-site data, alarm prompts, data recording, time and date, data printing, password for use of this program, etc.
2. PC external communication
This part is an important part of this system. The data of the PC can be set, but sending the data of the PC to the serial port and how to receive the data from the serial port are the key parts in PC programming.
Among the numerous controls in VB, there is a MSCOmm control, which is specially used to realize the transmission and reception of serial port data, providing serial communication function for the application, and is a standard 10-bit serial port communication. This design uses this control. The following is an introduction to the use of this control.
Control properties:
commport
Set and return the communication port number. The syntax is:
object.comport[=value]
value is an integer value indicating the port number used
Note: During design, value can be set to any number from 1 to 16, and the port number must be set before opening the port.
settings
Set and return parameters such as baud rate, parity, data bits, stop bits, etc.
The syntax is: object.settings[=value]
value is a string expression that indicates the setting value of the port. It consists of four setting values in the following format:
"BBBB, P, D, S"
Among them, BBBB is the baud rate; P is the parity check; D is the data bit; S is the stop bit number. It is worth noting that the setting value here must be consistent with the serial port baud rate setting value of the microcontroller system.
portooen
Set and return the status of the communication port;
The syntax is: object.portopen[=value]
value is a Boolean expression indicating the status of the communication port;
value=true: port is open; value=false: port is closed
It should be noted that if the DTREnable or RtsENable property is set to true before the port is opened, these two properties must be set to false when the port is closed.
Input
Returns and deletes the data stream in the receive buffer
The syntax is: object.input
Description: The inputlen attribute determines the number of characters read by the input attribute. If inputlen is set to 0, the input attribute reads the entire contents of the buffer. The inputmode attribute determines the type of data read by input. If inputmode=cominputmodetext, the input attribute returns text data through a variant; if inputmode=cominputmodebinary is set, the input attribute returns an array of binary data through a variant.
output
Write data stream to the transfer buffer
The syntax is: object.output[=value]
value is a string to be written to the transmit buffer.
Description: The output attribute can transmit text data or binary data
commevent
Returns the most recent communication event or error. Use this property to handle abnormal events during data transmission.
handshaking
Set and return the hardware handshake protocol
The syntax is: object.handshaking[=value]
value is an integer value
value=0 no handshake
value=1 (xon/xoff) handshake
value=2 (rts/cts) handshake
value=3 (both xon/xoff and rts/cts are acceptable) handshake
Description: Handshaking refers to the internal communication protocol through which data is transferred from the hardware port to the receive buffer. The handshake protocol ensures that data is not lost when the buffer is overloaded.
Control events:
oncomm
The oncomm event is generated whenever the value of the commevent property changes. It indicates that a communication event or an error has occurred. The commevent property contains the actual error or the code that generated the oncomm event. However, when the rthreshold or sthreshold property is set to 0, the comevreceive and comevsend events are invalid respectively.
3. Serial communication between MCU and PC
After this process, the single-chip microcomputer and the PC are connected for communication control, and the advanced programming of the PC to control the single-chip microcomputer is truly realized. In the communication, I use serial communication. The advantages of using serial communication are simplicity, strong anti-interference, and long transmission distance. The interface is RS232C interface. However, since RS232C or other serial communication interfaces cannot meet the transmission requirements of TTL level, a level conversion device must be added to this interface. The Max232 level conversion chip used here is Max's Max232.
The upper computer of the system is composed of a (PC586) microcomputer, and the high-level language is VISUAL BASIC. Through VB programming design, it is easy to make a very intuitive interface. On the interface, there is a "thermometer" to display the current temperature of the control site, and there is also a "digital" to display the temperature; the preset button on the interface can set the control temperature value of the site; for safety, the upper and lower limit temperature control devices are made on the control interface. If it exceeds the specified range, prompts and alarms will be issued, and the system will automatically adjust the furnace temperature to a safe range. If the problem cannot be solved within 1 minute, the system will automatically shut down. Moreover, if the temperature of the furnace needs to be changed, it can be achieved by presetting the computer data without changing the curing program of the single-chip microcomputer. Therefore, when the process conditions of the control object change, under the action of the PC, it is easy to meet the control conditions, thereby realizing the optimization of control.
The CPU of this system uses ATMel89C51 chip. 89C51 comes with 2K flash memory, which is very convenient to use. 89C51 is compatible with all 51 systems, has good performance and is relatively cheap. 89C51 uses its own serial port to receive the preset serial data from the PC, and then outputs it from the parallel port to the data latch 74LS373. Finally, the latched data is sent to the D/A conversion interface chip DAC0832, converted into an analog signal, and sent to the temperature control system. The temperature control system receives the analog signal from the D/A and converts it into a pulse to trigger the bidirectional thyristor. By changing the size of the conduction angle of the bidirectional thyristor, the size of the current in the heating device is changed. According to Q=I2Rt, it can be seen that changing the heat also changes the temperature. At the same time, through the role of the temperature sensor, the temperature of the site is collected from the site, and after sampling and holding, data latching, and D/A conversion, it is sent to 89C51, and compared and analyzed with the preset data to obtain error data. The error data is used to adjust the output of 89C51. After a series of transformations, the temperature on site is changed to improve the control accuracy. In addition, the single-chip microcomputer system sends the temperature data on site to the PC through the serial port and displays it on the control interface.
3.1 PC part
The VB communication control design software is as follows:
Global comm._time as integer; define global variables
Global data(1000) As Integer
Global Receive(1000) As Integer; serial data receiving and sending
Private Sub Form_load( )
Comm1.Comport=1
Comm1.Settings=”9600,N,8,1”
Comm1.Inputlen=0
Comm1.Inbuffersize=256
Comm1.Outbuffersize=256
Comm1.Portopen=true
Comm1.Sthreshold=1
Comm1.Rthreshold=1
End Sub
Public Sub send-data(); (data sending program)
For i=0 to n
Comm1.output=Chr(data(i))
Next I
End Sub
Public Sub Comm1_oncomm(); (receiving procedure)
Select Case Comm1.CommEvent
Case comEvreceive
Receive(comm._time)=Asc(Comm1.Input)
Comm_time=Comm_time+1
End Select
End Sub
(There are many more programs, but due to space limitations, the list of other programs is omitted)
3. Conclusion
After the successful development of this system, the use effect is good. If there are multiple control objects, it can form a distributed control system. Of course, due to the limited level, there are definitely many shortcomings, and readers are welcome to correct them.
References
[1] Wu Chengbin, ed. VB50 Practical Programming Guide. University of Electronic Science and Technology Press. March 1998.
[2] Li Hua, ed. Practical Interface Technology of MCS-51 Series Microcontrollers. Beijing University of Aeronautics and Astronautics Press (third printing). August 1997.
Previous article:Use highly integrated clock system chip to replace traditional separate clock design
Next article:Design of high-precision electronic balance based on MSP430F4250
Recommended ReadingLatest update time:2024-11-16 17:32
- Popular Resources
- Popular amplifiers
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Virtualization Technology Practice Guide - High-efficiency and low-cost solutions for small and medium-sized enterprises (Wang Chunhai)
- 2024 DigiKey Innovation Contest
- MCU C language programming and Proteus simulation technology (Xu Aijun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- STEVAL-IDB010V1 BlueNRG-LP evaluation board data
- Revealing the secret! How can 100 MHz power decoupling hold Gbps high-speed signals?
- Please tell me how to protect the gas meter using Hall device from strong magnetism, and whether it has one or two Hall devices.
- I don't know how many days I have been learning HFSS
- [STM32F769Discovery development board trial] USB-HS HID simple transmission and reception evaluation
- There is a problem with testing multimedia
- Use chips that support the BLE 4.2 specification to implement application system design
- TMS320F2812 advice
- EEWORLD University Hall----Parallel Computing
- CPU temperature exceeds the limit