A servo, also known as a servo motor, is an electromechanical structure with a closed-loop control system. A servo is mainly composed of a housing, a circuit board, a coreless motor, gears, and a position detector. Its working principle is that the controller sends a PWM (pulse width modulation) signal to the servo, which is processed by the IC on the circuit board to calculate the direction of rotation, and then drives the coreless motor to rotate, and transmits the power to the swing arm through the reduction gear. At the same time, the position detector (potentiometer) returns a position signal to determine whether it has reached the set position. Generally, the servo can only rotate 180 degrees. The servo has 3 wires, brown for ground, red for positive power, and orange for signal line, but the colors of the wires of different brands of servos may be different, so you need to pay attention.
The rotation position of the servo is achieved by controlling the duty cycle of the PWM (pulse width modulation) signal. The period of the standard PWM (pulse width modulation) signal is fixed at 20ms. The positive pulse width of the duty cycle of 0.5~2.5ms corresponds to the rotation angle of the servo -90°~90° (i.e. 0~180 degrees). Note that due to different brands of servos, the pulse width parsed by their controllers is also different, so for the same signal, the rotation angles of servos of different brands are also different. The principle is: it has a reference circuit inside, which generates a reference signal with a period of 20ms and a width of 1.5ms. The control signal enters the signal modulation chip through the channel of the receiver to obtain a DC bias voltage. The DC bias voltage obtained is compared with the voltage of the potentiometer to obtain a voltage difference output. Finally, the positive and negative outputs of the voltage difference are 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.
0.5ms------------0 degrees;
1.0ms------------45 degrees;
1.5ms------------90 degrees;
2.0ms-----------135 degrees;
2.5ms-----------180 degrees;
The procedure of using 11.0592MHZ 51 single chip microcomputer to drive the servo is as follows:
//Automatically rotate on power on
#include
unsigned char count; //0.5ms times mark
sbit pwm =P1^0 ; //PWM signal output
sbit jia =P2^4; // Angle increase button detection IO port
sbit jian =P2^5; // Angle reduction key detection IO port
unsigned char jd; //angle identifier
sbit pwm1 =P0^0 ; //PWM signal output to oscilloscope, used to detect PWM wave
void delay(unsigned char i)//delay
{
unsigned char j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void Time0_Init() //Timer 0 initialization
{
//After checking the initial value of timer 0 with an oscilloscope, the 11.0592MHZ crystal oscillator enters the interrupt with a timing of 0.5ms and the initial value is as follows
TH0 = (65536-445)/256;
TL0 = (65536-445)%256;
TMOD = 0x01; //Timer 0 works in mode 1
IE = 0x82; //IE=0x82=1000 0010 is equivalent to EA=1, open the general interrupt ET0=1, open the timer 0 interrupt
TR0=1; //Start timer 0
}
void Time0_Int() interrupt 1 //interrupt program
{
//Reinstall initial value
TH0 = (65536-445)/256;
TL0 = (65536-445)%256;
if(count< jd)
{
pwm=1; //It is indeed less than, PWM output high level
pwm1=pwm; //Connect to the io port of the oscilloscope to observe the PWM waveform } //Judge whether the 0.5ms times are less than the angle mark
//pwm=1; //It is indeed less than, PWM output high level
else
{
pwm=0; //It is indeed less than, PWM output high level
pwm1=pwm; //Connect to the io port of the oscilloscope to observe the PWM waveform}
// pwm=0; // if greater than 0, the output is low level
count=(count+1); //0.5ms times plus 1
count=count%40; //The number of times is always kept at 40, that is, the cycle is kept at 20ms
}
//This canceled part is the program that controls the rotation of the servo through the buttons. Its function is to control the forward rotation through the jia button.
//Control the reversal by pressing the jian key
/*void keyscan() //key scan
{
if(jia==0) //Is the angle increase button pressed?
{
delay(10); //press delay to eliminate jitter
if(jia==0) //actually pressed
{
jd++; //angle mark plus 1
count=0; //When the button is pressed, the 20ms cycle starts again
if(jd==6)
jd=5; //It is already 180 degrees, keep
while(jia==0); //Wait for the button to be released
}
}
if(jian==0) //Is the angle reduction button pressed?
{
delay(10);
if(jian==0)
{
jd--; //angle mark minus 1
count=0;
if(jd==0)
jd=1; //It is already 0 degrees, keep
while(jan==0);
}
}
}*/
void main()
{
//Power on, the servo will automatically reverse
//It should be noted that each step is the setting of the delay function delay parameter. The setting of the delay function parameter here is not ideal
while(1)
{
for(jd=1;jd<6;jd++)
{
count=0;
Time0_Init();
delay(50000000);
}
delay(50000000);
for(jd=6;jd>0;jd--)
{
count=0;
Time0_Init();
delay(50000000);
}
}
}
Previous article:Detailed explanation of 51 single chip microcomputer PWM dual servo control
Next article:Detailed explanation of 51 single chip microcomputer PWM program
- Popular Resources
- Popular amplifiers
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
- How to measure BLE power consumption
- I would like to ask how to connect the ground on the PCB board of the monitoring equipment and the board ground?
- Overvoltage, overcurrent and overtemperature detection circuit
- Recruitment: Assistant Optical Engineer, Assistant Electronic Engineer, Assistant CAE Engineer, Assistant Structural Engineer
- Multi-core DSP products in the SoC era
- Detailed explanation of Altera series FPGA chip IP core
- SinlinxA33 Modify the configuration file to change the output serial port
- 【Home treasure】 esp32s2 lvgl running lcd io configuration
- Balanced Amplifier
- micropython update: 2020.9