Archive for the ‘Technology’ Category

PID Controller Simplified

This is an attempt to explain PID controller with minimum use of maths.

A simple closed loop control system consisting of a controller and a process (or plant) is shown below.

The input to the system is the ‘setpoint’, ie the desired output. The input to the controller is the error.

Error = Present Output – Setpoint.

The two steps in the design of a control system are –
1. Mathematically model the plant to be controlled.
2. Design the Controller.

The block diagram of a PID controller is shown below –

A PID controller consists of a Proportional element, an Integral element and a Derivative element, all three connected in parallel. All of them take the error as input. Kp, Ki, Kd are the gains of P, I and D elements respectively.

The best way to understand something is by simulating it. So I simulated a PID controller in matlab. The matlab code is provided at the end of this article.

Let me assume a suitable mathematical model for the plant and then go ahead with designing the controller.

Let the transfer function of the plant be 1 / ( s^2 + 20s + 30 ).

The step response of a system is the output of the system when the input to the system is a unit step. The open loop step response of the above plant is –
(Click on the image to get an enlarged picture)

It can be seen that the step response output is close to 0.035. The steady state error = 1-0.035 = 0.965. That’s quite high! Also observe that the settling time is around 3 sec.

Now lets see what is the effect of PID controller on the system response.
Lets see the effect of proportional element on the system output.

Keeping Kp = 10, Ki = 0, Kd = 0 the step response of the system is

The output is now 0.25. Much better than the open loop response! (The curve in red shows the open loop step response of the plant)

Now let me increase the Kp further and observe the response.
Keeping Kp = 100, Ki = 0, Kd = 0 the step response of the system is

The output is now 0.77. So it’s clear now that increasing Kp will reduce the steady state error.

Keeping Kp = 200, Ki = 0, Kd = 0 the step response of the system is

The output is around 0.87. Also observe that the ripples have started appearing in the output. If Kp is increased further it will only lead to increase in ripples or overshoot. The rise time also has decreased. Also observe that there is a small steady state error (1 – 0.87 = 0.13).

Conclusion –
Increasing Kp will reduce the steady state error.
After certain limit, increasing Kp will only increase overshoot.
Kp reduces rise time.


Now lets keep Kp fixed. Lets start varying Ki.

Keeping Kp = 200, Ki = 10, Kd = 0 the step response of the system is

The output is now close to 0.99. That’s very close to the setpoint. But observe that settling time has increased.

Keeping Kp = 200, Ki = 200, Kd = 0 the step response of the system is

Observe that rise time has now reduced and steady state error is very small.

Keeping Kp = 200, Ki = 300, Kd = 0 the step response of the system is

Observe that steady state error is close to 0 now. But increasing Ki has resulted in overshoot.

Further increasing Ki will only increase overshoot.

Conclusion –
Ki eliminates the steady state error.
After certain limit, increasing Ki will only increase overshoot.
Ki reduces rise time.


Now lets Keep Ki fixed and start varying Kd.

Keeping Kp = 200, Ki = 300 and Kd = 10.

Wow! What a response! Where is the overshoot? It has disappeared. There is a reduction in settling time as well.

Increasing Kd further will only result in response getting worsened.

Conclusion –
Kd decreases the overshoot.
Kd reduces settling time.


So the ideal PID values for our plant is Kp = 200, Ki = 300 and Kd = 10.

The above process is known as manual tuning of PID.

Here is the matlab code used to simulate PID –
(The below code is written by me. So please let me know if you find any bugs!)

den=[1 20 30];
Plant = tf(num,den);
hold on;

P_Sys = tf(Kp,1);

den2=[1 0];

num3=[Kd 0];




ClsdLoop = feedback(OpenLoop,[1]);


Flash Memory – The Little Champ !


What’s common between a Pen Drive, SD, Mini SD and Micro SD Cards? All of them hold large amount of data in a tiny space. The advent of flash memory has made it possible to shrink the size of memory chips and has found its place in cell phones, Cameras, PDA’s and other portable devices.

Flash is a non volatile memory meaning the data is retained even when there is no power supply. It’s a particular type of EEPROM (Electrically Erasable Programmable Read Only Memory) that is erased and programmed in large blocks. EEPROMs are realized as arrays of floating gate transistors (MOSFETs to be more precise) and hence occupy lesser space. But there’s one characteristic of Flash that makes it unique and advatageous over the typical EEPROM – the electrical interface of a Flash differs from that of the  typical EEPROM. While Flash is read / erased in large blocks, EEPROMs are read/erased bytewise as it has dedicated circuits for each byte. And this characteristic of Flash makes it more affordable.

Solid State Drives (SSD), which use Flash memory, consume only one tenth of the power as that used by Magnetic hard drives. With no moving parts, they are more reliable, rugged and compact. Apple’s MacBook Air, the thinnest laptop in the world, is the first gadget to sacrifice hard disk and optical disk drives in favour of the Solid State Drives. A MacBook Air with 64 GB Solid State Drive costs around $3000 whereas the one with 80 GB Hard Disk Drive costs $1799. Apparently one would have to pay more for a Solid State Drive but it’s worth the benefits it offers. Unlike a Hard Disk even if your laptop is dropped often, the drive won’t crash.

Samsung has unveiled a Hybrid Drive which has a buffer of 128/256 MB cache consisting of Flash memory. By using this large buffer for data storage, the platters of the hard drive are at rest almost all of the time, instead of constantly spinning, as they are in the current hard drives. The data to be stored is temporarily written into the cache, and once the cache is full the data is written into the disk resulting in decreased power consumption and lesser write times.

In future, as prices continue to fall, the Solid State Drives are likely to replace conventional Magnetic Drives. The future of FLASH looks BRIGHT!