# PID simple code ??

Discussion in 'The Projects Forum' started by eric_s88, May 31, 2014.

1. ### eric_s88 Thread Starter Member

Apr 20, 2011
157
1
Hi everyone..

May someone help me in PID simple code ?

I know this : I have to calculate the error = desirevalue - actualvalue , and then do some other calculation on this " error "..

any help ?

2. ### tshuck Well-Known Member

Oct 18, 2012
3,527
679
You seem to have some uncertainty in your understanding.

PID uses the error to determine what value should be applied to the controlled device(plant) to make the input minus the feedback quantity equal to zero (indicating the controlled parameter is at the commanded input).

A PID controller uses the error (current error, rate of change of the error[derivative], and accumulated error[integral]) multiplied by some constant values($k_p$, $k_i$, & $k_d$) to determine the output parameter. In tuning a PID, one selects the $k_p$, $k_i$, & $k_d$ & to accomplish the controller requirements (e.g. rise time, overshoot, response type, etc.)

In digital systems, the derivative is no more than the difference between the current error and the previous error, where the integral is the current error added to previous errors.

Last edited: May 31, 2014
eric_s88 likes this.
3. ### crutschow Expert

Mar 14, 2008
20,279
5,739
You might consider a type of control loop that doesn't require calculation of the integral or differential of the signal as PID does which is Fuzzy Logic. It basically consists of a series of If-Then-Else loops to control the system. This can be more intuitive to write in computer code than a PID loop and can be more tolerant of system non-linearities.

Last edited: May 31, 2014
eric_s88 likes this.
4. ### THE_RB AAC Fanatic!

Feb 11, 2008
5,432
1,312
Why not start closer to the solution?

WHAT do you need to control?

eric_s88 likes this.
5. ### eric_s88 Thread Starter Member

Apr 20, 2011
157
1
thank you "tshuck"..
I understand from your answer that at first we have to calculate the error!
and what about calculation of ($k_p$, $k_i$, & $k_d$) ? I read somewhere that for tuning this items we need zigler nicols method ?

6. ### eric_s88 Thread Starter Member

Apr 20, 2011
157
1
thank you " crutschow " . this is my project definition that I have to use PID control method , by the way I'm interested in FUZZY control too.. do you have any inrtoduction file ?

7. ### eric_s88 Thread Starter Member

Apr 20, 2011
157
1
thank you " THE_RB " ..

I have to control the Temp. of a furnace which is warm up by TEC plates!

8. ### crutschow Expert

Mar 14, 2008
20,279
5,739
Click on Fuzzy Logic in my original post. Also Google Fuzzy Logic.

Last edited: Jun 1, 2014
9. ### THE_RB AAC Fanatic!

Feb 11, 2008
5,432
1,312
Do you have the time constant of the furnace? ie; how many seconds it takes, for the temperature to rise 1 degree C?

Most furnaces are so slow you can use setpooint control and regulate temperature to better than 1'C. The most important thing is the thermal design, ie where the heaters are and where the sensor is, and how well the heat propagates within the space.

May 6, 2014
6
0