I think I'm missing something on the PID theory.

I have a motor rotating at X rpm, controlled by a pwm output (range 1 - 1000). Let's say it rotates at 20 rpm when pwm is halfway (500).

I need to control the PWM to keep the motor rotating at a set speed.

How should I setup the PID?

Please tell me where I'm wrong (assuming the motor rotates at 18 rpm instead of 20):

error = setpoint - current_value = 20 - 18 = 2

Only by considering the proportinal part, for sake of simplicity, in this case the output should be:

out = Kp * error = Kp * 2

in order to even move the motor, I should use a Kp of about 250... In my understanding the K values should be very little ones..


  • 1
    \$\begingroup\$ one of the mistakes is that output is summation .. it does (increase or decrease) based on the error * kp ... but you consider it here as (output = error * kp) directly \$\endgroup\$ Oct 21, 2020 at 11:43
  • \$\begingroup\$ "in order to even move the motor, I should use a Kp of about 250" Does this mean getting the motor to start from standstill? That leads to a Kp that is far too large once the motor is running. You probably need a much smaller Kp in operation, and increase it when the motor stops : a classic problem controlling a nonlinear "plant" with a linear controller. With the best value of Kp there will still be some finite error; that's what the I term is for. \$\endgroup\$ Oct 21, 2020 at 12:01
  • \$\begingroup\$ @Hasanalattar now I get it. thank you, really useful. \$\endgroup\$
    – Val
    Oct 21, 2020 at 12:06
  • \$\begingroup\$ @BrianDrummond you are right, but I don't go from 0 to set speed. I first have a linear ramp up, then the PID kicks in \$\endgroup\$
    – Val
    Oct 21, 2020 at 12:07


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.