I've set up a PID controller to control the shaft position of a brushed DC motor that I control via PWM and an optical encoder. I'm basically reconstructing an RC servo.

Now that I think I've found the correct tuning parameters (all three parameters non-zero), I'm facing with another problem: the shaft arrives at the desired angle with some approximation (look at the black stick at https://www.instagram.com/p/BTg25HngIDo/), then stops moving further. I hear a "buzzing crescendo" from the motor, that ends after some seconds with it moving a little further, but now too much. So there's another buzzing crescendo, and so on. It almost never reaches the target angle exactly.

By looking at the output/error output, I see that during the buzzing the controller is sending small PWM values, too small to start the motor (as I could experiment by myself, see https://www.instagram.com/p/BQYBZsShq9x/). I guess this is some kind of non-linearity, while a PID can only work with linear processes. Because the motor is stopped at a nearby position, the error accumulates in the I branch and so does the output, until a threshold is reached.

What is the usual approach to solve this issue? I'm thinking about linearizing the output as suggested in this answer (i.e. implementing a "dead zone" function so that the motor never receives small PWM values), but I'm worried that the linearizer will add more independent variables in the system.

  • \$\begingroup\$ do you have one control loop? a position loop? \$\endgroup\$
    – user16222
    Commented Apr 30, 2017 at 16:31
  • \$\begingroup\$ Yes, one position control loop. \$\endgroup\$ Commented Apr 30, 2017 at 16:34
  • \$\begingroup\$ Your PID values are underdamped: cnc4pc.com/Tech_Docs/PID_tuning_eng.pdf You need to be critically damped. \$\endgroup\$ Commented Apr 30, 2017 at 16:57
  • \$\begingroup\$ Position control of a brushed motor is tricky. \$\endgroup\$
    – Trevor_G
    Commented Apr 30, 2017 at 17:37
  • \$\begingroup\$ @Trevor. Depends on whether you have a gearbox or not. \$\endgroup\$ Commented Apr 30, 2017 at 17:42

1 Answer 1


You have backlash in the gear train which is like electrical hysteresis. That is causing "hunting". You can minimize the backlash by preloading as in anti-backlash gears. You can adopt a simpler control scheme such as P (perhaps with some control deadband) or P+D. The integral term, if present, will integrate any remaining error until motion occurs (unless the I term has deliberate or accidental deadband itself - say due to low ADC resolution).

You might want to read this paper by Tim Wescott. Tim does a lot of work with precision electromechanical systems used in military and similar applications.

  • 1
    \$\begingroup\$ A very nice paper. \$\endgroup\$ Commented Apr 30, 2017 at 20:22
  • \$\begingroup\$ Thanks for the paper, it deserves to be read carefully (especially the PWM part, which I'm already using but might need improvement). I'd slightly disagree about the backlash, because the encoder is attached to the motor shaft before the gears; on the other hand, the motor seems to have six windings while the optical encoder makes 8 pulses per revolution, which IMHO makes some positions more difficult to reach than others, and that may explain the hunting. \$\endgroup\$ Commented May 5, 2017 at 15:49
  • \$\begingroup\$ The encoder creates a deadband in that case. A higher resolution encoder might help a lot. \$\endgroup\$ Commented May 5, 2017 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.