08 TIM output PWM_PID control algorithm

TIM output PWM control motor

PS: For all chip ports, the maximum withstand voltage is 5V to
turn on the PWM wave, and set a waveform as the output of the PWM wave. 300 is set to 100, the speed will be changed from 111 to 30rpm

PID algorithm

Why is there a PID algorithm?

  • The physique of the motor cannot be the same
  • The same pwm is added to multiple motors, how to maintain the same speed
  • External force, load change problem
  • Closed-loop control of motor speed, speed measurement -> error calculation -> pwm adjustment

Disadvantages: There is no clear optimization criterion, and the debugging is basically based on experience.

Proportional (P) control: Strength value
Integral (I) control: Response speed
Differential (D) control: When the target value is reached, the inertia overshoot is suppressed

For example: set the speed to 50 rpm, then use the PID algorithm code as follows:

Dead zone control

Q1 and Q2, or Q3 and Q4 cannot be turned on directly, or they will be burned.
There is a reaction time when the transistor is turned on and off, which causes the motor to not turn over instantaneously.

  • If it is judged that the current speed rpm_cur and the incoming demand speed pwm have opposite signs, it means that a reverse rotation is required.
  • Turn off the pwm wave first
  • Then turn the in1 and in2 pins on the motor drive chip off and then on.
  • The pwm wave has no negative value, so a pwm = -pwm operation is required

 

Guess you like

Origin blog.csdn.net/weixin_44937328/article/details/114443390