What is PID control and how to use control methods over AVR microcontrollers

Submitted by TrickyNekro on December 17, 2009 - 9:24am.

PID is an simple control mechanism that it's been widely used as a control system in many industrial applications. But before getting on the main details let's talk about some basics on control theory. Why we need such control theories???

 

Well, as we know robots are mere slaves that follow our orders but how can a slave without eyes see? Well robots have sensors for feeling the environment and a series of very nice goodies for interfering with the environment. But the robot must also know how much to interfere. Imagine a robot controlling some rockets over Iran sensing world criticism on nuclear weapons. Make it too sensitive and it would be too late for the world. Make it too senseless it would be too late for Iran or itself. I know it's a most far fetched example but such nice examples usually remain on mind. That why we need a control system that isn't based on mere switches ( changes better ). The first principle about this system is that we need some kinda of feedback on what we are doing. This means that if we start to do something we must have sensors to see how wrong we are doing this. If are doing it wrong and not correct then we need to correct ourselves. How much we correct we are gonna see later with PID control. This is called a close loop system or a system with feedback or with a mostly know term "servo". This means basically that the output of the system is monitored by a sensor, compared to an open loop system that the output is never monitored. Then the sensor determines the current state of the machine (or the output). After that the error to the set point is determined ( the difference of the wanted state to the current state and changes are made accordingly ).

 

PID is such a closed loop system that calculates the output of the system based on 3 quantities that are calculated based on the error.

 

 

The P factor (propositional)

 

This is the most basic factor that you are going to meet in a control environment. Many systems are greatly served by this factor only without the need of other factors, but in this tutorial we are seeing all possible out comes. As it's name suggests the output of this factor is proportional to the error.
The is just like this: P = GP(Set_Point - Sensor_Reading)
This factor is calculated later to drive the output to the wanted state. As you can see there is a quantity that I haven't talked before. The GP. This is the proportional gain or simply the gain of the proportional factor. This gain or number better is simply a number, that is calculated based on the system characteristic, but also on the magnitude of the factor on the calculation of the output. Still this is getting too theoretical so we better explain these later with some live fire examples... xexexe

 

 

The I factor (Integral)

 

Before talking about this factor we must talk about timing in systems. Time for microcontrollers is like Mentos. You may see a package as a whole thing but the microcontroller only sees the pills, one by one. We may count time in seconds but what we feel is age. Microcontroller doesn't. The only thing that knows is pills. Each pill may last for x number of time but doesn't matter for the microcontroller, since if power is on, it would be working for an eternity. So what is this all introduction for??? Well, in each pill the microcontroller measures different error, or better it gets a new reading. By now pills are magically transformed into time slots... ;-P It sounds better for a microcontroller. So instead of rejecting the previous error, the microcontroller accumulates the errors. Since the error also accepts negative values this factor would grow infinite don't worry. This factor is useful when dealing with fast changes in the system to the Set_Point and/or the Sensor_Reading but behaves very badly near the Set_Point, and usually if not always in real time conditions in oscillates badly, so it best fits systems that need a quick response but usually the use of another factor is more than a necessity

This tutorial isn't finished....
The user drinks coffee and talk to hotties... see ya later