About sg90 steering gear, you must know! pay attention!

The steering of this type of steering gear is related to frequency and duty cycle, both of which are indispensable!

1. At a specific frequency, a specific duty cycle makes the rudder turn to an angle. If the duty cycle remains unchanged, the angle will not change. Therefore, if you want the rudder to maneuver, it must be kept at the specified frequency. Change the duty cycle.

2. When the frequency changes, the ratio of the duty cycle will also change, and the duty cycle of the first point is different. Then what is the value of frequency and duty cycle, not only depends on the documentation (theory) of the servo, but also the output of the user signal source

Give the frequency and duty cycle to the servo (actual), find the appropriate frequency value and duty cycle value under the steering angle/position of the servo.

3. The following is the single-chip microcomputer program for the two steering gears to turn 90° when their corresponding signals come. The analog steering is not accurate, it is mainly able to express that when the frequency is constant, a duty cycle value corresponds to a steering gear angle/position.

  #include <reg52.h>

sbit duoji_1 = P2^7;
sbit duoji_2 = P2^0;

sbit xinhao_1 = P3^4;
sbit xinhao_2 = P3^5;

void aa(unsigned char i) //延时i个ms
{
  unsigned char j,k;
  for(;i>0;i--) 
    for(j=2;j>0;j--) 
      for(k=245;k>0;k--);
}

void main(void)
{
while(1)
{
 if(!xinhao_1) 
{
duoji_1 = 0;
aa(19);
duoji_1 = 1;
aa(2);
duoji_1 = 0;
aa(19);
duoji_1 = 1;
aa(2);
}
else
{
duoji_1 = 0;
aa(19);
duoji_1 = 1;
aa(1);
duoji_1 = 0;
aa(19);
duoji_1 = 1;
aa(1);
}
if(!xinhao_2) 
{
duoji_2 = 0;
aa(19);
duoji_2 = 1;
aa(2);
duoji_2 = 0;
aa(19);
duoji_2 = 1;
aa(2);
}
else
{
duoji_2 = 0;
aa(19);
duoji_2 = 1;
aa(1);
duoji_2 = 0;
aa(19);
duoji_2 = 1;
aa(1);
}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324673239&siteId=291194637