Using microcontroller PWM signal for steering gear control

Publisher:未来架构师Latest update time:2007-03-09 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The steering gear control method based on single-chip microcomputer has the characteristics of simplicity, high precision, low cost, small size, and can be flexibly applied according to the number of different steering gears. In the robot electromechanical control system, the steering gear control effect is an important factor affecting performance. The steering gear can be used as the basic output actuator in micro-electromechanical systems and aircraft models. Its simple control and output make the microcontroller system very easy to interface with. The steering gear is a position servo driver, suitable for control systems that require angles to continuously change and be maintained. Its working principle is: the control signal enters the signal modulation chip from the receiver channel to obtain the DC bias voltage. There is a reference circuit inside it, which generates a reference signal with a period of 20ms and a width of 1.5ms. The obtained DC bias voltage is compared with the voltage of the potentiometer to obtain a voltage difference output. Finally, the positive and negative voltage difference is output to the motor driver chip to determine the forward and reverse rotation of the motor. When the motor speed is constant, the potentiometer is driven to rotate through the cascade reduction gear, so that the voltage difference is 0 and the motor stops rotating. Figure 1 The control of the steering gear requires that the control signal of the steering gear is a PWM signal, and the position of the steering gear is changed by changing the duty cycle. The control requirements of general steering gear are shown in Figure 1. To achieve steering gear angle control using a microcontroller, FPGA, analog circuits, and microcontrollers can be used to generate steering gear control signals, but FPGAs are expensive and have complex circuits. For the pulse width conversion of pulse width modulation signals, a commonly used method is to use the modulation signal to obtain the actively filtered DC voltage, but a 50Hz (period is 20ms) signal is required, which has higher requirements on the selection of op amp devices. , it is not easy to adopt considering the circuit volume and power consumption. Changes in the control voltage above 5mV will cause the servo to jitter. For airborne measurement and control systems, the signal noise of the power supply and other devices is much greater than 5mV, so the accuracy of the filter circuit is difficult to meet the control accuracy requirements of the servo. A microcontroller can also be used as the control unit of the steering gear to change the pulse width of the PWM signal at the microsecond level, thereby improving the steering angle accuracy. The microcontroller completes the control algorithm, and then converts the calculation results into PWM signals and outputs them to the steering gear. Since the microcontroller system is a digital system, the changes in its control signals completely rely on hardware counting, so it is less affected by external interference and the entire system works reliably. To control the steering gear output angle, the single-chip microcomputer system must first complete two tasks: the first is to generate a basic PWM periodic signal. This design is to generate a 20ms periodic signal; the second is to adjust the pulse width, that is, the output of the single-chip computer simulates the PWM signal. , and adjust the duty cycle. When the system only needs to control one servo, the control method adopted is to change the initial value of a timer interrupt of the microcontroller, and divide 20ms into two interrupt executions, a short timed interrupt and a long timed interrupt. This not only saves hardware circuits, but also reduces software overhead, and the control system efficiency and control accuracy are both very high. Specific design process: For example, if you want the servo to turn to the left extreme angle, its positive pulse is 2ms, and the negative pulse is 20ms-2ms=18ms, so initially send a high level to the control port, and then set the timer to 2ms After the interrupt occurs, change the control port to low level in the interrupt program, and change the interrupt time to 18ms. After 18ms, enter the next scheduled interrupt, then change the control port to high level, and The initial value of the timer is changed to 2ms, waiting for the next interrupt to arrive, and so on to realize the PWM signal output to the servo. The pulse signal is cleverly formed by modifying the initial value of the timer interrupt, and the servo can move flexibly by adjusting the width of the time period. In order to ensure that the software collects other signals in the scheduled interrupt, and that the program that generates the PWM signal does not affect the operation of the interrupt program (if these programs take too long, it is possible that the next interrupt will come before the interrupt program ends. Consequences), so the function of collecting signals needs to be executed in the long scheduled interrupt process, that is to say, these programs are executed every two interrupts, and the execution cycle is still 20ms. The software process is shown in Figure 2. As shown in Figure 2, the software process for generating PWM signals. If the system needs to control the accurate rotation of several servos, a microcontroller and counter can be used to count pulses to generate PWM signals. Pulse counting can be implemented using the internal counter of the 51 microcontroller. However, from the perspective of the stability of the software system and the rationality of the program structure, it is appropriate to use an external counter, which can also improve the efficiency of the CPU. After the experiment, considering the accuracy, for the FUTABA series receiver, when using an external crystal oscillator of 1MHz, the change in the control voltage amplitude is 0.6mV, and there will be no error accumulation, which can meet the requirements of controlling the steering gear. Finally, considering the discrete error of the digital system, it is estimated that the error range is within 0.3%, so the PWM signal generation circuit using a microcontroller and counter chips such as 8253 and 8254 is reliable. Figure 3 is a hardware connection diagram. Figure 3 PWA signal counting and output circuit The program to generate PWM signals based on 8253 mainly includes three aspects: first, defining the address of the 8253 register, second, writing the control word, and third, writing data. The software process is shown in Figure 4, and the specific code is as follows. //Key programs and comments: //Timer T0 interrupt, send control word and data to 8253 void T0Int() interrupt 1 { TH0 = 0xB1; TL0 = 0xE0; //20ms clock base //Write the control word first, Then write the count value SERVO0 = 0x30; //Select counter 0 and write the control word PWM0 = BUF0L; //Write low first, then write high PWM0 = BUF0H; SERVO1 = 0x70; //Select counter 1 and write the control word PWM1 = BUF1L; PWM1 = BUF1H; SERVO2 = 0xB0; //Select counter 2 and write the control word PWM2 = BUF2L; PWM2 = BUF2H; } Figure 4 Software process for generating PWA signals based on 8253. When the main task of the system is to control the work of multiple servos, and the working cycles of the servos used are all 20ms, the period of the multiple PWM waves generated by the hardware is required to be the same. The internal timer of the 51 microcontroller is used to generate pulse counting. Generally, the working positive pulse width is less than 1/8 of the cycle. In this way, the rising edge of each PWM wave can be started in one cycle, and then the timer interrupt T0 is used to determine each channel. The output width of the PWM wave, the timer interrupt T1 controls the base time of 20ms. The first timer interrupt T0 sets the initial value according to 1/8 of 20ms, and sets the output I/O port. After the first T0 timer interrupt is responded to, the pin output corresponding to the current output I/O port is set to high level. , set the positive pulse width of the output, and start the second timer interrupt, and the output I/O port points to the next output port. After the second timer time expires, set the current output pin to low level and set the interrupt period to 1/8 of 20ms minus the positive pulse time. This PWM signal is output in this period and is output reciprocally. . In the 16th (2% 26; External counters can also be used to control multiple servos, but because the common 8253 and 8254 chips only have 3 counters, when the system needs to generate multiple PWM signals, the above method can be used to reduce circuits and costs, or Achieve higher accuracy. When debugging, I noticed that since the pulse width in the program is adjusted by adjusting the initial value of the timer, the interrupt program is also divided into 8 status cycles, and requires a strict period cycle, and the time to run other interrupt program codes needs to be strictly controlled. In practical applications, the 51 microcontroller is used to simply and conveniently realize the PWM signal required for steering gear control. The test of the robot steering gear control shows that the steering gear control system works stably, with PWM duty cycle (positive pulse width of 0.5~2.5ms) and steering gear angle (-90%26;#176;~90%26;# 176;) The linearity is better. References 1 Hu Hancai. Single-chip microcomputer principle and interface technology. Tsinghua University Press. 1996 2 Wang Shisheng, Jiang Jianping. Using single-chip microcomputer to realize PWM D/A conversion technology. Electronic Quality. 2004 3 Liu Gequn. Lu Jingchao. Yan Jianguo. Xue Yaoshun. Using single-chip microcomputer to generate 7-channel Method for steering gear to control PWM wave. Mechanical and Electronics. 2004
Reference address:Using microcontroller PWM signal for steering gear control

Previous article:Application of μPSD32xx microcontroller in tax controller
Next article:Design of AT88RF256 radio frequency card reader

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号