CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PID algorithm questions

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gs



Joined: 22 Aug 2005
Posts: 30
Location: Ioannina - Greece

View user's profile Send private message Visit poster's website

PID algorithm questions
PostPosted: Sat Jul 25, 2009 6:02 am     Reply with quote

Hello I am trying to implement a PID controller to control temperature.

I have a question to make. The integral term is the sum of the past errors. ok but what happens when the error becomes small? (the temperature is about to reach the set value?) The integral term is always bigger and bigger.
I think that the integral term should *somehow* decrease and become zero when the the error becomes zero. What am I missing here?

Best regards from Greece
John
_________________
www.hlektronika.gr
sirius



Joined: 27 Jun 2009
Posts: 16
Location: Bulgaria

View user's profile Send private message

PostPosted: Sat Jul 25, 2009 9:15 am     Reply with quote

Summing the instantaneous error over time (integrating the error):
I = Ki * Sum e(t)dT

where

I: Integral term of output
Ki: Integral gain, a tuning parameter
e: Error = SP − PV
SP: setpoint value
PV: present value
t: Time or instantaneous time (the present)
τ: a dummy integration variable

From the equation is seen,that when the error / e=SP-PV / becomes smaller,Integral term decreases.When SP/set point/ is reached/overshot/, e /error/ = 0 or negative and Sum e(t)dT and I are getting smaller,and after a given time I=0.So,when equilibrium is reached in your system /SP=PV/ ,I=0,and Integral term is eliminated!You've made a mistake somewhere in your algorithm.

Basically,you should do this:
e: error
sum_e: accumulated error over time

1 step: e=SP-PV
2 step: sum_e = sum_e + e
3 step: I = Ki * sum_e
4 step: wait xx time of Integral_cycle
5 step: repeat 1,2,3,4 and so on.

And one more thing - you should limit the accumulated error:
if sum_e>sum_e_limit - sum_e=sum_e_limit

That's because the integral term is responding to accumulated errors from the past and it can cause the present value to overshoot the setpoint value.
ariel.vollmann



Joined: 23 Jul 2009
Posts: 7
Location: Córdoba - Argentina

View user's profile Send private message MSN Messenger

PostPosted: Sat Jul 25, 2009 9:23 am     Reply with quote

Hi John,

Under normal circumstances the integral part of the PID should help the equation to converge to an "zero error" situation when the error is small ("when the tempereture is about to reach the set value").

If the integral part is growing continuously I think that maybe is somehow not taking part of the equation.

Try revising the operations you make with that integral term, maybe the factor you are multiplying to this term to create the complete equation and all the mathematical operations.

Isn't that factor too small? Tunning an PID equation is not always an easy task...

If you can't solve it it would be helpful if you post some of the code.

Greetings from Argentina
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Jul 25, 2009 10:44 am     Reply with quote

Assume a heater controller. During warm-up phase, e is always positive, thus the integral is increasing up to it's allowed limit. Usually, the integration is stopped when the controller output (manipulated value) reaches it's limit, e.g. 100 % power for a temperature controller.

You're asking, how the integrator output can be cut back to near zero in equilibrum?. Typically, a small overshoot of the process value is required to achieve this.
gs



Joined: 22 Aug 2005
Posts: 30
Location: Ioannina - Greece

View user's profile Send private message Visit poster's website

PostPosted: Sat Jul 25, 2009 12:05 pm     Reply with quote

FvM wrote:
...

You're asking, how the integrator output can be cut back to near zero in equilibrum?. Typically, a small overshoot of the process value is required to achieve this.


Yes, I see this in my test program. I read a pot with ADC to emulate the feedback. If I set the pot over the threshold (overshoot) for a while, the I term decreases, but I don't want overshoot in my design.

I will do some more research and then I will post my code for further discussion.
_________________
www.hlektronika.gr
sirius



Joined: 27 Jun 2009
Posts: 16
Location: Bulgaria

View user's profile Send private message

PostPosted: Sat Jul 25, 2009 12:46 pm     Reply with quote

Quote:
Usually, the integration is stopped when the controller output (manipulated value) reaches it's limit, e.g. 100 % power for a temperature controller.

I think this is what you need,or put a limit of the accumulated error,as I previously mentioned.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sat Jul 25, 2009 12:58 pm     Reply with quote

PID loops are usually set for "critical damping" which gives the smallest absolute error * time integral, but this inherently gives some overshoot. If you can not have any overshoot you need an over-damped solution, which will be slow, or use something smarter than a PID algorythm.

In fact with no overshoot the integral term will never decrease. Try just using P & D.
_________________
The search for better is endless. Instead simply find very good and get the job done.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Jul 26, 2009 11:56 am     Reply with quote

Quote:
In fact with no overshoot the integral term will never decrease. Try just using P & D.
A PD controller implies a static temperature error, which is most likely worse than some overshoot. Basically, a different controller type, e.g. a dead beat controller should be used for optimal control without overshoot.
jma_1



Joined: 08 Feb 2005
Posts: 147
Location: Wisconsin

View user's profile Send private message

PostPosted: Sun Jul 26, 2009 1:49 pm     Reply with quote

Greetings,

Adding extra logic to your control might assist in your application.

Suggestions:
Temperatures change very slowly (relatively slow compared to a uProc). Updating your PID algorithm at a different rate may help your application.

The classic PID problem is integrator windup. Searching the internet for possible suggestions is warranted. In a slow moving system such as temperature control, integrator windup might be an issue.

How about adding logic if the application is closing on the target, don't do anything else. This would prevent having to remove the integrator term contribution and perhaps help limit your overshoot. More logic would be required, but this might get you going in the direction.


Cheers,
JMA
sirius



Joined: 27 Jun 2009
Posts: 16
Location: Bulgaria

View user's profile Send private message

PostPosted: Sun Jul 26, 2009 5:04 pm     Reply with quote

How about using Fuzzy Logic?
Facu__
Guest







PostPosted: Mon Jul 27, 2009 6:19 pm     Reply with quote

It looks for in the forum todopic, there there is a control example PID with anti-windup with PIC.

Greetings
s_mack



Joined: 04 Jun 2009
Posts: 107

View user's profile Send private message

PostPosted: Sat Sep 05, 2009 3:43 pm     Reply with quote

can someone translate that last post for me Smile It sounds like he's trying to say there is sample code somewhere showing an example PID with anti-windup. I searched... no find.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Sep 05, 2009 4:49 pm     Reply with quote

Google for this, and select the translate page option to view each link:
Quote:
site:todopic.com.ar/foros/ PID anti-windup
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group