Simulate A PID Controller For DC Motor
I recently work on a project which requires a customized controller in FPGA to control a DC motor. Since PID controller is a good start point for this type of control function, I decided to refresh my control theory knowledge before I start implementing any design.
I found a webpage that explains PID control in detail. It shows how the DC motor step response changes when the parameters of PID controller change.
Open Loop Response (without Controller)
The webpage pointed out the step response of the DC motor without any control loop as in link. It shows that, if applying 1V voltage to the motor, it will reach 0.1 rad/s in 2 seconds. So what if we want to reach 1 rad/s?
Closed Loop Response (with Controller)
The webpage gave an answer to use proportional control which is a PID controller with “P” parameter only. The step response of the DC motor changes to this.
Furthermore, “I” and “D” parameters are introduced to the controller to get the nearly perfect step response here.
Now I have a question in my mind. Since I am going to design a controller, I would like to know what is the input and output of the PID controller look like in this case. Unfortunately, this webpage does not give any details.
Input and Output of the PID Controller
So I decided to build the same PID control loop in Octave to monitor the input and output of the PID controller as shown in the diagram. The source code used can be found here.
For proportion control loop, the input of the PID controller is the difference(err) between expected motor speed and actual motor speed. The output of the PID controller is the voltage applied to the motor. From the diagram below, we can see that the voltage started from about 100V which is quite high for motors I normally work with. Then gradually decreased to about -10V. At the end, it stabilized at about 10V. However, the motor did not reach its target speed 1 rad/s (Steady-state error). It is not a perfect design but still implementable.
“P” controller step response:
Now we have a look the control loop with a full “PID” controller. After some effort to make it work (details can be found at the end of the post), I got the step response as below. The output of the PID controller reached staggering 10KV! It is way out of normal embedded system voltage range. Although the motor runs very smoothly under this controller. It is very difficult if not impossible to implement this “PID” controller, Never mind to find the DC motor that can take 10KV input.
“PID” controller step response with shocking 10KV output:
From the simulation result, it is clear that, despite of the perfect motor speed control, a FULL PID controller is not always implementable. If we take out the “D”(Differentiator) part of the PID controller, we have a “PI” controller which has step response as below. Here, I limit the “P” parameter to 20. So the voltage output of the controller does not go over 24V which is widely acceptable for DC motors. Comparing to FULL “PID” controller, it takes longer for the motor to reach its target speed.
“PI” controller step response:
The next step for me is to implement a “PI” controller in FPGA.
Why Not Pure Differentiator
During the process of simulating the FULL PID controller, the differentiator has been causing problem for the simulator. Basically, a pure differentiator is not implementable in real world. A blog gives good explanation. A general rule is to add some components in the PID controller to make its transfer function proper. In practice, a low-pass filter will do the job. In my case, I added a LPF with transfer function as below just to keep the simulator happy.
\[\frac{1000}{S+1000}\] \[\frac{10^3}{S+10^3}\]