Privacy statement: Your privacy is very important to Us. Our company promises not to disclose your personal information to any external company with out your explicit permission.
Servo motor, also known as servo motor, is mainly composed of a housing, a circuit board, a motor, a reduction gear, and a potentiometer. The servo is mainly applied to those control systems that require constant change of angle and can be maintained, such as the arms and legs of humanoid robots, the directional control of vehicle models and model airplanes. At present, the mature steering gear industrial products on the market come from Japan, South Korea and Taiwan. In this paper, based on the basic principle of servo work, Atmega8L microcontroller is selected as the servo circuit board control chip, and a series of experiments on servo control are carried out, and good experimental results are obtained.
How does the servo work?The control signal enters the signal modulation chip from the receiver's channel to obtain the DC bias voltage. It has a reference circuit internally, generates a reference signal with a period of 20ms and a width of 1.5ms, and compares the obtained DC bias voltage 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 positive and negative motor rotation. When the motor rotates at a certain speed, the potentiometer is rotated through the cascade reduction gear so that the voltage difference is 0 and the motor stops rotating.
Servo Drive Circuit Schematic Based on AVR Microcontroller1. Servo drive circuit board accepts host computer PWM signal to motor control
The steering angle of the servo is usually 0 to 180 degrees. The steering angle of the steering gear is usually controlled by the pulse width. Generally, the steering gear has three input lines (power supply, ground, and signal lines). The PWM signal is input by the signal line and the upper computer A square wave with a period of about 20 ms is used as an input signal, and the duty ratio of the square wave determines the steering angle of the steering gear. As shown in Figure 1:
Based on the above principles, the following experimental circuit is designed (Figure 2). The basic principle of the servo work is achieved through the connection of the Atmega8L microcontroller and the motor-specific driver chip L298N.
The AVR microcontroller is an 8-bit RISC-structured microcontroller from Atmel Corporation. With In-System Programmable Memory Flash Flash Memory Programmable Memory EEPROM Random Access Memory RAM Analog to Digital A/D Converter, Large Number of I/O Ports, 16/8 Bit Timer, RS-232 Communication Interface UART, Two-wire Serial Interface TWI and many other features of monolithic integrated circuits. This article uses the AVR series of common models of products ATMega8L system clock frequency using external crystal 7.3728Mhz, operating voltage 5V.
L298 is a double H bridge high voltage and high current integrated circuit that can be used to drive relays, coils, DC motors and stepper motors. The schematic diagram is shown in Figure 3. Vss is connected to the logic controlled power supply. Vs is the motor drive power. The IN1-IN4 input pin is a standard TTL logic level signal, and the ENAENB pin is the enable control pin. It is originally used to control the opening and closing of the H-bridge by IN1--IN4 input to realize the positive and negative rotation of the motor. ENA, ENB enable control terminal, used to input PWM signal to realize motor speed regulation. This article uses a set of H-shaped bridge L298N, ENA enable control terminal has been turned on, input IN1, IN2PWM signal to control the motor speed and steering.
2. SCM initialization includes initialization of I/O ports, timers, and A/D conversion
The PWM signal sent by the host computer is read through an I/O port of the Atmega8L. To read the high-level time of the PWM signal, the counting method is used. The T0 count of the Atmega8L is used. T0 is an 8-bit timer. Divided by 8, TCCR0 = 0x02. If read PWM signal of PD0 is high level, T0 begins to count time, the count value T0 of T0 counts from 0 to 255, produce count overflow to cut off, set up an accumulator COUNT in the interrupt service routine, enter interrupt service routine COUNT each time plus 1. When the PWM signal read by the PD0 port is low, T0 stops counting and the entire PWM high time is calculated as: INPUTPWM = (COUNTX 255 + TCNT0) / 921.6 (ms). If the PWM high time read by the PD0 port is less than 1ms, INPUTPWM=lms is processed in the program. If it is higher than 2ms, INPUTPWM=2ms.
During the experiment, in order to avoid that the first timing fails to count from the high level of the PWM signal, the first high level of the PWM signal is ignored and the second high level read from the PD0 port starts timing.
Read the potentiometer voltage and read the voltage value of the current potentiometer (ADC) through A/D conversion. Atmega8L provides the highest resolution A/D conversion accuracy of 10 bits, ie the converted voltage value is from 0 to 1023 based on this Considering that the PWM signal read by PDO is converted to the voltage value target=(INPUTPWM-1)*1023, this design helps to reduce the complex process of converting the PWM signal to a corresponding voltage value.
Using the Atmega8L Tl timer to generate two 16-bit pwm signals, the duty cycle determines the control of the motor speed, the greater the duty cycle, the longer the current duration, the faster the steering gear, and vice versa, the slower. In order to match the maximum value of A/D conversion 1023 and reduce the computational complexity, the T1 timer uses Phase 8 phase and frequency correction PWM mode to make the count maximum ICR1 = 1023 and its comparison value 0CR1 = (ADC-target). In order to control the motor's steering, if (ADC--target). With the rotation of the motor, the voltage value of the collected potentiometer keeps approaching the target value, the value of OCR1 becomes smaller, the duty cycle also becomes smaller, and the servo speed also continues to slow down. In theory, when the ADC is equal to the target, The air ratio is 0, the motor reaches the target position and stops rotating. Motor control flow chart shown in Figure 4.
3, PID adjustment
In theory, when the motor reaches the target position, the motor will stop rotating, and no current flows through the motor at this time. However, the servo is a system that needs to maintain the angle, and the bigger the holding power, the better, that is, the bigger the torque of the servo is, the better . Specifically, when the motor reaches the target position, the motor stops rotating, but at this time, as long as there is a slight external force to rotate the motor, the motor will flow a current in opposition to the external force to maintain the angle, this current is locked current. Therefore, on the one hand, the motor is required to reach the target position and the current is getting smaller and smaller, which is easy to stop. On the other hand, the motor in the small area that deviates from the target position must have a large stall current, and adjustment using PID (Proportional Integral Differential) can be very good. Good solution to this contradiction.
The PID can well control the motor to reach the target quickly without jitter. For the servo, the above-mentioned comparison value 0CR1 of the timer T1 is simply given as the difference between the current motor position and the target position. After the introduction of the PID control, this item is multiplied by a coefficient kp as OCR1. The proportional term; the difference between the motor position in the previous cycle and the motor position in this cycle is multiplied by the coefficient kd as the differential term of OCR1. The function of this item is mainly if the difference between the two positions of the motor is large. The speed of the motor can be speeded up; the average of the difference between the motor position and the target position for each cycle is multiplied by the coefficient ki as the integral term of OCR1. The effect of this item is to damp the motor to reduce the motor jitter. These three items are added together as the OCR1 value as a comparison value of the T1 timer. The formula is as follows:
OCRl=kpX(ADC-target)+kiX((ADC-target)/n)+HkdX(adcvalpre-ADC)
Among them, ADC is the current value of the collected potentiometer, target is the voltage value after the target position conversion, the number of cycles, adcvalpre is the voltage value of the previous cycle, kp, ki, kd are the selected parameters, select the appropriate The parameters can ensure that the motor reaches the position of the month mark quickly and steadily.
4. Servo driver board communicates with the upper computer in TWI mode to control the servo
TWI (Two-wire Serial Interface) is a communication interface of Atmega8L, providing the fastest data transmission rate of 400khz. The IWI protocol allows system designers to interconnect 128 different devices using only two bidirectional transmission lines. One of these two lines is the clock SCL, - is the data SDA. The use of TWI communication is mainly to accurately transmit the designated position to be reached by the servo and to easily adjust the kp, ki, kd coefficients. This article uses two pieces of Atmega8L one-chip computer to carry on TWI communication, PC end adopts RS-232 to communicate with one piece of one-chip computer, the model is shown as in Fig. 5:
The PC side is a serial communication program written with VC6 and a single-chip computer a communication. The single-chip microcomputer a mainly deals with the RS-232 transmission data and re-packages it to the servo control circuit board in TWI mode. In this way, the target position, kp, ki, kd and other parameters can be easily transmitted through the serial port communication program on the PC during the experiment process, which is easy to debug.
In this paper, the mechanical components of the Futaba S3003 servo are selected. Using the servo control circuit of Figure 4, the motor is well controlled to reach the target position, and a large torque is generated. As an experimental product, achieving the expected results, the next step is to seek a better adjustment algorithm to more stably control the motor and generate more torque.
Enviar e-mail para este fornecedor
Privacy statement: Your privacy is very important to Us. Our company promises not to disclose your personal information to any external company with out your explicit permission.
Fill in more information so that we can get in touch with you faster
Privacy statement: Your privacy is very important to Us. Our company promises not to disclose your personal information to any external company with out your explicit permission.