# PID Controller of servo motor

#### mohamed.amin

Joined Dec 26, 2011
5
Hello....

i have a problem with my controlling code i control a servo motor using an arduino, the thing is that the output of the controller is increasing by large values i can't understand or predict !!! i need the output to be bounded between
25-135!!

Thanks

#### crutschow

Joined Mar 14, 2008
27,017
Need a diagram of what you are trying to control.

25-135 what?

#### mohamed.amin

Joined Dec 26, 2011
5
i am controlling a ball and beam system, i need the output of the pid controller to be bounded between these values , this value represents the angel of the servo motor !!

#### crutschow

Joined Mar 14, 2008
27,017
So you have a program that simulates the PID controller? Does it have proportional, integrator, and differential loops?

We need a lot more info about what you are doing before we can help by other than just guessing.

#### mohamed.amin

Joined Dec 26, 2011
5
sorry i am new at this , the pid controller for me changes the value of the error into an angel which corresponds to a desired motion of the ball , i need the output of the controller to be bounded between between the two values i gave u before.
i am using a simulink for simulation, kp ki kd all= 20 the reference value is 15, the problem for me is when i write the code on the arduino ( which i am using for the control) i monitor the output of the controller and it some times reaches 9 digits , i decreased the value of the gains , and made Ki with very small value , the output of the controller increases slowly but still it can reach a very large value by time , i just need to know how to bound this output
Regards
Mohamed

#### crutschow

Joined Mar 14, 2008
27,017
A simple way is just to do a comparison of the output value with the maximum you want it to be using an If-Then-Else type of statement. When the output tries to exceed this value you just output the maximum allowed value instead.

#### mohamed.amin

Joined Dec 26, 2011
5
yeah. that's what i thought of , i thought there were another method !!