Small DC motor position controller, steady state error problem


Thread Starter


Student project, requesting suggestions: DC motor position controller, has unacceptable (i guess) steady state errors.

Well, i use the following setup:
-Microchip PIC18f2431

-24V DC motor(1/8 inch shaft, model type I think) bought from,

-quad encoder: Avago HEDS-5500

-H Bridge: LMD18200T.

The project's target is a position motor controller. After tuning a PID using Ziegler-Nichols method(since i don't have numbers for a precise math model), I ended up with a random steady-state error of 0-100 encoder counts, in 1000CPR mode. During that state, there is a minimal voltage supplied to the motor, which I guess isn't high enough to keep the motor turning, thus the error. My questions are:
Am I overseeing something here? If I'm not, is there any way to make the system more precise, without changing the motor?Maybe amplify the PID output, when it gets too small to affect the motor?

Finally, please excuse any terminology mistakes of mine and thank you in advance for reading this :)
At first, check encoder's mounting to motor shaft.

At second, how looks steady-state error (vibration, un stability or random really)? - Maybe you have possibility to monitor position error?
I'm sorry, I should define this at my first post. There is no vibration, the motor just stands still at another position than the commanded. For example, if the commanded position is 0, the steady state will be something random between -100 to 100. Even if I move the shaft somewhere else between these values by hand, it will stay where I left it, just like there is no current flowing on it.
I noticed that the error can be reduced to +-50, if I lower the pwm frequency to an annoying audible frequency(say, 1KHz instead of 18KHz which is my original choice). But, I don't think this is a valid solution because I still have a serious error!

One more piece of info:
Let's say that the commanded position is 0 and motor shaft is moved to position -58. This means that the shaft will stay there, without coming back at 0. If Voltage across the motor is measured, a voltage of 0.3 volts will be measured. This is proportional to the position, with a maximum of(-)0.4 volts at (-)100encoder counts and 0.00 volts at the exact commanded position(0).

Thank you for answering and paying attention to this... :)
It sounds like the integral gain either isn't working or isn't doing very much. Another possibility is there is a fairly large position dead band. If there is a steady state error, the integral gain should be accumulating and the voltage increasing until the motor moves. That's what the integral component is for.

Check your parameters. Check your code (if you wrote it). Check the math implementation.

William Sturm

It sounds like you have no integral gain. The I term will integrate error over time and increase the output until the error is near zero. What you describe is typical in a loop with only proportional gain.

Bill Sturm
Thank you all for your answers. I do have an integral gain and yes, i have written the code by myself. But, there is a limit in my integral error accumulation, which is 1000, arbitrary chosen :)

I have to wake up early tomorrow morning (it's 4:34am right now), so I'll test it and let you know the results. Thank you again, and I hope I can be useful to you at some point in the future :)
One thing this could be is lack of integral. You need to add integral gain term if you don't have one, or to increase your integral gain. Some controllers allow you to have different values of integral when the servo is nearing in-position.

The integral gain accumulates error signal over time so that it builds up torque while the motor is out of position. The fact that you have very little torque on the motor [indefinitely] is indicative of a very low or zero integral gain term.

OK, last update, FIY. Sorry for this delay, had a personal matter this weekend (female). Well, it actually was lack of I term, due to a silly programming error. Thank you all, once again! :)
OK, another question, if you are not tired yet.

I intend to make a positioning system, as I already mentioned. But, assuming that a speed limit is required until we reach the desired position, what is the best way to control that limit? I mean, is it an acceptable solution to simply limit the output of the PID, using a threshold?

PS: If this is off-topic, forgive me. I just don't intend to fill the forum with useless discussions about a student project...

William Sturm

You may want to control the velocity as well as the position.  Then you can create a velocity profile over time to execute until you arrive at your target position.  Ideally, the velocity profile and final position correspond...

Bill Sturm