0 Introduction
Motor control is widely used in monitoring equipment, medical equipment, electric valves, electric curtains, household appliances, rotating lamps, etc. Therefore, it is very meaningful to design a motor control system with good controllability and high precision. This article introduces the software and hardware design of the motor control system based on the AT89S52 microcontroller. It sets the time under the operation of the key, controls the rotation of the motor, and displays the working status and time.
1 Design Description
The system first sets the forward and reverse (i.e. clockwise and counterclockwise) rotation time of the motor by pressing buttons, and the time is displayed on the LCD in the format of hours: minutes: seconds (different formats can be selected by changing the program). The countdown method is adopted. When the forward time is completed, the reverse rotation time starts immediately. When the reverse time is completed, it automatically returns to the initial setting time.
After the time setting is completed, press the start button, the forward rotation time starts timing, the motor working indicator light flashes, the forward rotation indicator light is on, and the motor rotates forward at the same time; when the forward time is over, the reverse time starts timing, the forward rotation indicator light goes out, the reverse rotation indicator light is on, and the motor rotates in the reverse direction at the same time.
Press the stop button, the time stops counting, the motor stops working, and the working indicator light goes out.
The motor used in the system is a 60TDY-11 reversible permanent magnet motor, which has two sets of windings inside and uses capacitors to achieve directional rotation. By changing the connection method of the capacitor and the motor output leads, the motor directional rotation can be reliably achieved and the rotation direction can be controlled.
2 Hardware Circuit Design
The hardware structure of the whole system is shown in Figure 1.
2.1 Key input and control circuit design
The key input circuit uses 6 keys connected to the P2.0~P2.5 ports of the microcontroller as the input of the control signal. Press the K0 key, the system enters the time setting mode, and continuously press the K0 key to select different time units to set. Use the K1 and K2 keys to add or subtract 1 to the time. Press the K3 key to exit the time setting mode, and the K4 and K5 keys are the start and stop keys respectively.
The control chip of the motor control circuit adopts AT89S52 of ATMEL Company, which has 8 KB FLASH, 256 B RAM, 32-bit I/O port line, watchdog timer, two data pointers, three 16-bit timer/counters, a 6-vector 2-level interrupt structure, full-duplex serial port, on-chip crystal oscillator and clock circuit. It has rich internal resources and high cost performance, which can meet the design requirements.
P0.0~P0.2 are the control signal outputs of the three working indicator lights, which need to be connected to an external pull-up resistor; P1.0~P1.2 are the control signal outputs of the LCD display; P3.0~P3.1 are the control signal outputs for controlling the forward and reverse rotation of the motor respectively.
2.2 LCD display circuit design
The display part uses 12864 LCD, and the controller is ST7920. This controller has Chinese character library, eliminating the trouble of compiling character library. The LCD of this controller also supports drawing mode. This type of LCD supports 68-bit 8-bit and 4-bit parallel port and serial port. The clock SCLK of ST7920 has independent operation timing. When multiple consecutive instructions need to be sent in, the instruction execution time needs to be considered.
A complete serial transmission cycle consists of the following parts: first, the start byte is sent, and five consecutive "1"s are sent to start a cycle. At this time, the transmission count is reset and the serial transmission is synchronized. The next two bits are to determine the transmission direction (RW, to determine whether it is read or write) and the transmission nature (RS, to determine whether it is a command register or a data register), and the last eighth bit is an "O".
In this design, the PSB pin is grounded, the serial port working mode is selected, the CS high level is valid, and data transmission can be completed using only two wires SID and SCLK.
2.3 Motor and drive circuit design
The operating voltage of the 60TDY-11 motor is 220 V AC, and the output high level of the microcontroller is 5 V. Therefore, the motor requires a drive circuit that uses a relay as an "automatic switch" to control a larger current with a smaller current.
The relay used in this design is HUIGANG HRS2H-S-DC-12V, and SN74LS07N is used as the driving circuit of the relay. The low-level input is effective, and the relay also needs a parallel diode circuit, mainly to protect the SN74LS07N. When the current flowing through the relay coil decreases rapidly, the coil will generate a very high self-induced electromotive force to break down the transistor. After the diode is connected in parallel, the self-induced electromotive force of the coil can be clamped at the forward conduction voltage of the diode. When P3.0 is low, the normally closed contact of relay 1 is disconnected, the normally open contact is closed, the forward circuit of the motor is turned on, and it starts to rotate forward. P3.1 is similar, P3.0 and P3.1 cannot be low at the same time.
3 Software Design
3.1 Program Description
The program is designed and developed in KeilμVision 3 IDE, written in C language. KeilμVision 3 integrated development environment is a microprocessor software development platform based on 80C51 core developed by Keil Soltware. It can complete the complete development process from project establishment to management, compilation, linking, target code generation, software simulation, hardware simulation, etc., especially the C compiler tool has reached a high level in terms of accuracy and efficiency of code generation. It supports all Keil 80C51 tool software, including C51 compiler, macro assembler, linker/locator and target file to Hex format converter. In view of this, it is selected as the program development environment.
The system program consists of the main program, interrupt handling subroutine, key handling program and display subroutine. The timer timing interrupt is used to generate time, and the software delay method is not selected, so as not to occupy CPU time. Timer T0 generates a 50 ms timing interrupt. There is a counter in the interrupt service program. Every 20 interrupts, there is a 1-second count. The key scan uses a single key scan, and there is a corresponding key processing subroutine. The program includes key debounce and key post-processing. Debounce uses the delay debounce method. The display subroutine is called in the main program to display the time in real time.
3.2 Main program flow chart
The main program flow chart is shown in Figure 2, which mainly completes the system initialization, key scanning, display program and other subroutine calls.
During initialization, the timing interrupt is turned off, the P0.0~P0.2 ports output a high level, the status indicator light goes out, the P3.0~P3.1 ports output a high level, the motor stops rotating, and the LCD is initialized to display 4 lines of information, 2 lines display time, the format is hour: minute: second, and the other 2 lines are time description text. All initialization functions are written as a subroutine, and the main program only needs to call it to complete the system initialization. After the initialization is completed, scan the keys, and if a key is pressed, call the corresponding processing program. When the time setting key is pressed, the selected time unit will flash continuously, which is different from other time units that have not been set. Use the K1 and K2 keys to change the time, and press the K3 key to exit the time setting. When the start key is pressed, the timing interrupt is turned on, the LCD display time starts to count down, the PO.1 port outputs a low level, the forward rotation indicator light is on, the P3.0 outputs a low level, and the motor starts to rotate forward. In the interrupt service program, the output level of the PO.0 port is controlled to make the normal working indicator flash once every 1 s. When the stop key is pressed, the P3. P0.0~P0.2 output high level, the status indicator light goes out, the timing interrupt is turned off, and the counting stops. When the forward rotation time ends, the reverse rotation countdown starts, P3.0 outputs high level, P3.1 outputs low level, the motor rotates in the reverse direction, P0.1 outputs high level, P0.2 outputs low level, the forward rotation indicator light goes out, and the reverse rotation indicator light turns on. The display program displays the time changes on the LCD in real time.
4 Conclusion
After actual operation, the system can satisfy the requirements of setting time under the operation of function keys, controlling the start, forward and reverse rotation, and stop of the motor, the status indicator light correctly displays the working status, and the LCD displays the time normally.
This system will be applied to an automatic opening and closing device of a valve. The valve opens when it rotates forward and closes when it rotates reversely, thereby controlling the liquid flow. In specific applications, it is also necessary to detect the opening and closing status of the valve.
2010/4/30 20:58:56
Previous article:Design of multi-function counter based on C8051F020 chip
Next article:Design of DIS acquisition system based on ARM embedded system
Recommended ReadingLatest update time:2024-11-16 22:24
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
- Apply for the USB PD power receiving protocol chip CH224 and CH224EVT for free, show your DIY creativity and win Qinheng gifts!
- Industrial control personnel must learn Kingview and Siemens PLC wireless PPI classic communication solution
- Happy National Day to all forum friends!
- 555 classic circuit diagram: dual tone generator circuit diagram
- The two outputs of the voltage comparator LM393 are abnormal
- Just because I rotated a high-speed PCB, the result was completely different...
- BTT6030-2EKA
- Several C language algorithms commonly used in single chip microcomputers
- Mobile Wi-Fi: How wireless routers can help catch thieves
- Sensor detection circuit advice