Publish Time: 2023-10-16 Origin: Site
Now commonly used steering gear control signals mainly PWM signal and serial bus signal two kinds: PWM signal control is relatively simple, but only one function is to control steering gear rotation; Serial bus signal control is more complex, the controller needs to have a serial output function, but can achieve more functions, in addition to control the rotation of the steering gear can also obtain a variety of information of the steering gear and a variety of Settings of the steering gear, the specific need to cooperate with the corresponding protocol file to use.
The following describes how PWM is used
Signal control steering gear:
PWM signal: A continuous level signal with a fixed period pulse width (high level width) variable.
There are two ways to generate PWM signals:
The first kind: output by MCU ordinary GPIO port, low resolution, more complex program, need to use a timer;
The second: by MCU hardware PWM output, high resolution, can reach 1us or smaller, the program is relatively simple, require MCU
With hardware PWM function;
The parameters of PWM signal in steering gear control are generally: period =20ms, pulse width (high level width) range =0.5ms~2.5ms.
The rotation Angle of the steering gear is determined by the pulse width, for example, the total Angle of a steering gear is 180° The PWM pulse width range is 0.5ms~2.5ms, then
When the steering gear receives different pulse width signals, turn to the corresponding position:
Note: The signal pulse width is linearly related to the steering gear Angle.
Signal pulse width | Steering gear Angle |
0.5ms | 0° |
1.0ms | 45° |
1.5ms | 90° |
2.0ms | 135° |
2.5ms | 180° |
Control steering gear rotation effect:
1, steering gear lock rudder:
When the signal remains unchanged, the steering gear will remain in the current position, and the output torque will vary with the load size.
2. Rapid rotation of steering gear:
When the signal changes, such as the signal from 1ms to 2ms, the steering gear will change from 45° Turn to 135° as fast as you can; Position, this speed will be based on the performance of the steering engine itself and the size of the load, generally marked on the specification book with no load when the maximum da speed.
3. Slow rotation of steering gear:
When it is necessary to let the steering gear slowly rotate, such as the steering gear from 45° Go to 135° The position takes three seconds, only need to calculate the change increment of the signal pulse width, from 1ms to 2ms in three seconds, the smaller the increment, the more delicate the rotation effect.
Examples of programs:
1. PWM output by MCU's ordinary GPIO port:
#include 《reg51.h》
#define uchar unsigned char
#define uint unsigned int
sbit p10=P1^0;
uint aa;
void delay (uint z)
{
unsigned int x,a;
for(x=z;x>0;x--)
for(a=250;a>0;a--);
}
void timer0()interrupt 1 //Timer 1 has a period of 0.1ms and outputs a pulse width signal of 1.5ms
{
TH0=(65536-100)/256;
TL0=(65536-100)%256;
aa++;
if(aa>=200)aa=0;
if(aa<=15) //The generation period is 20ms, the high level is 1.5ms,
p10=1;
else
p10=0;
}
void init()
{
aa=0;
a=0;
p10=0;
TMOD=0x11;
TH0=(65536-100)/256;
TL0=(65536-100)%256;
EA=1;
ET0=1;
}
void main()
{
init();
TR0=1;
p10=1;
while(1)
{
}
}
2. PWM signal output by MCU hardware PWM:
Step1 Initialize the PWM function, configure the PWM clock as 1us, the period as 20000, the duty cycle as 0, and the signal level as high.
Step2, when the signal needs to be changed, it is only necessary to write the corresponding parameter in the duty cycle register, such as 0.5ms, 500,2.5 ms, 2500.