Searching \ for 'PID algorithms in PIC C' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=PID
Search entire site for: 'PID algorithms in PIC C'.

Truncated match.
PICList Thread
'PID algorithms in PIC C'
1999\05\15@063047 by Darren Logan

picon face
Hi,

My problem:
-------------------
I want to control the thickness of condensation of a sample gas on a metal
surface by controlling the temperature of the surface.
This is a fundamental method of measuring humidity, where the temperature of
the surface which causes the sample gas to begin to condense is directly
proportional to humidity. (Clever hey ? - but no real secret, the method has
been around for donkeys years).

The temperature measurement needs to be precise (within 0.3 degC accuracy)
using a PRT-100 (Platinum Resistance Thermometer).

The method to detect moisture or condensation is by light transmission &
detector. The light is directed onto the surface and the detector measures
the reflected light from it.
When condensation occurs, the reflected light is scattered and the detector
sees this and attempts to control the temperature of the surface at this
point. This temperature is then displayed and is known in the industry as
Dewpoint (the point at which dew forms!) and is of course a derivative unit
of humidity.

The device for cooling and heating the surface is a peltier heat pump.

Anyway...
I want to control the temperature of the surface with a PIC using PID control.
And i want to program the PIC in CCS C, of which i already have some
experience.

Obviously, i would like to be able to easily change the P, I and D settings
in software so I can experiment.

My question is...
Can anyone help me on PID control ?
Has anyone already done PID control with a PIC ? - or have algorithms already
?

Anyone any experience on adaptive tuning or self tuning PID controllers ?

Any help or advice very, very much appreciated.

Darren

1999\05\17@143603 by Lawrence Lile

flavicon
face
Yes, I've done some PID controllers.  There are a few basic questions:

1.  Do you have on-off or proportional control of your Peltier junction?
2. How fast can your system respond - tenths of seconds, seconds, or tens of
seconds?
3. YUou might set your loop time - how often you measure, to be something
less than the amount of time your system can respond, but not too much less.
Way longer ansd the system gyrates wildly, way shorter and you'll be going
100% one way and 100% the other way in no time.

Here's a basic approach to PID:

1.  Measure your input variable (temperature) and decide if it is too hot or
too cold (via the reflection technique)

2. Subtract your measured variable from your desired variable.  Call this
DIFFERENCE

3. P = DIFFERENCE * Pconstant.   Pconstant is the first critical thing
you'll have to tune in.  Start by trying 1/4 to 1/10.

4. I = DIFFERENCE * Iconstant + OLD I     keep a running tab of how far you
are from the setpoint.  Start with a small number, 1/100.

5. D = (NEW DIFFERENCE - OLD DIFFERENCE) * Dconstant.  Once again, Dconstant
should be small.

6.  Check that your output signal is in range.  If not set it at 100%
heating or 100% cooling (to avoid setting it 110% which will wrap around to
some crazy number)

many controllers only use P or P+I or P+D and get fine results.  I have used
P+I very successfully in an oven (see recent discussion.)

The math isn't hard, the hard thing is keeping inside the capabilities of a
PIC with a teeny stack and a tiny memory!




{Original Message removed}

1999\05\18@005346 by Tjaart van der Walt

flavicon
face
Lawrence Lile wrote:
{Quote hidden}

Good advice. I have noticed another thing that can make your
system much more immune to the low-frequency I-oscillations :
Reset the I-value to zero whenever P=0.

--
Friendly Regards          /"\
                         \ /
Tjaart van der Walt        X  ASCII RIBBON CAMPAIGN
spam_OUTtjaartTakeThisOuTspamwasp.co.za  / \ AGAINST HTML MAIL
|--------------------------------------------------|
|             Cellpoint Systems SA                 |
|             http://www.cellpt.com                |
|--------------------------------------------------|
|     http://www.wasp.co.za/~tjaart/index.html     |
|Voice: +27-(0)11-622-8686  Fax: +27-(0)11-622-8973|
|          WGS-84 : 26¡10.52'S 28¡06.19'E          |
|--------------------------------------------------|

1999\05\18@045202 by Stefan Sczekalla-Waldschmidt

flavicon
face
Hi,

Tjaart van der Walt wrote:
>
> Good advice. I have noticed another thing that can make your
> system much more immune to the low-frequency I-oscillations :
> Reset the I-value to zero whenever P=0.


looks like a good Idea - BTW did you try to optimize your PID-paramters
according to Ziegler-Nichols ?

I learned that one can achieve a good performance of the PID control
by looking for the point where Kp has a value ( no I and D at this
moment )
which gives the output a oscilation with a constant amplitude.

This Kp is now called Kpcrit(ical).

For the optimized PID control now use Kp = 0.45 * Kpcrit,

There are also values to multiply Ki and Kd with, but I can't recall
them
at the moment - you may look them up in a Control-Handbook ( look
for Ziegler-Nichols )

someone else tryed it this way ?

Kind regards,

       Stefan

1999\05\18@052144 by Tjaart van der Walt

flavicon
face
Stefan Sczekalla-Waldschmidt wrote:
>
> Hi,
>
> Tjaart van der Walt wrote:
> >
> > Good advice. I have noticed another thing that can make your
> > system much more immune to the low-frequency I-oscillations :
> > Reset the I-value to zero whenever P=0.
>
> looks like a good Idea - BTW did you try to optimize your PID-paramters
> according to Ziegler-Nichols ?
<GRIN> I optimised them according to Tjaart-Experiment!

The resetting of I compensates (among other things) for
the digital nature of the calculations. Running 16 bit
PID values in a PIC is not feasible, so I pulled a few
tricks out of the hat. Another, is to only accumulate
the I value every 10-50 (settable) samples. Effectively
this divides the I term which is always much smaller
than the P or D terms.

--
Friendly Regards          /"\
                         \ /
Tjaart van der Walt        X  ASCII RIBBON CAMPAIGN
.....tjaartKILLspamspam@spam@wasp.co.za  / \ AGAINST HTML MAIL
|--------------------------------------------------|
|             Cellpoint Systems SA                 |
|             http://www.cellpt.com                |
|--------------------------------------------------|
|     http://www.wasp.co.za/~tjaart/index.html     |
|Voice: +27-(0)11-622-8686  Fax: +27-(0)11-622-8973|
|          WGS-84 : 26¡10.52'S 28¡06.19'E          |
|--------------------------------------------------|

1999\05\18@053231 by Michael Rigby-Jones

flavicon
face
{Quote hidden}

I used this trick for the PID controler I wrote a few months back.  I don't
understand what you mean when you say running 16 bit values is not feasable.
Most the the variables I used were 16 bit integers.   Admittedly I was using
a 10bit ADC and DAC though.

It seems to me that you can spend all the time in the world with Bode plots
and pages of enormous calculations, but at the end of the day, you can't
beat sitting down and tuning control loops by experimentation.

Regards

Mike Rigby-Jones

1999\05\18@054715 by Tjaart van der Walt

flavicon
face
Michael Rigby-Jones wrote:
>
> > The resetting of I compensates (among other things) for
> > the digital nature of the calculations. Running 16 bit
> > PID values in a PIC is not feasible, so I pulled a few
> > tricks out of the hat. Another, is to only accumulate
> > the I value every 10-50 (settable) samples. Effectively
> > this divides the I term which is always much smaller
> > than the P or D terms.
> >
> >
> I used this trick for the PID controler I wrote a few months back.  I don't
> understand what you mean when you say running 16 bit values is not feasable.
> Most the the variables I used were 16 bit integers.   Admittedly I was using
> a 10bit ADC and DAC though.

Running @ 3.64MHz, it was a pain in the ass to try to do
all the math, PWM, serial comms, LCD, keypad and a partridge
in a pear tree.

That was a long time ago, though. Now I'd go straight SX for
anything fast.

> It seems to me that you can spend all the time in the world with Bode plots
> and pages of enormous calculations, but at the end of the day, you can't
> beat sitting down and tuning control loops by experimentation.
Yes. You have to smell the smoke to appreciate sensible values!
My control handbooks never mentioned that a big linear motor
that oscillates because of the I term, doesn't look so good.

--
Friendly Regards          /"\
                         \ /
Tjaart van der Walt        X  ASCII RIBBON CAMPAIGN
tjaartspamKILLspamwasp.co.za  / \ AGAINST HTML MAIL
|--------------------------------------------------|
|             Cellpoint Systems SA                 |
|             http://www.cellpt.com                |
|--------------------------------------------------|
|     http://www.wasp.co.za/~tjaart/index.html     |
|Voice: +27-(0)11-622-8686  Fax: +27-(0)11-622-8973|
|          WGS-84 : 26¡10.52'S 28¡06.19'E          |
|--------------------------------------------------|

1999\05\18@054921 by Stefan Sczekalla-Waldschmidt

flavicon
face
Hi,

Tjaart van der Walt wrote:
>
> <GRIN> I optimised them according to Tjaart-Experiment!

:-)

>
> The resetting of I compensates (among other things) for
> the digital nature of the calculations. Running 16 bit
> PID values in a PIC is not feasible, so I pulled a few
> tricks out of the hat. Another, is to only accumulate
> the I value every 10-50 (settable) samples. Effectively
> this divides the I term which is always much smaller
> than the P or D terms.

I read once about this method, maybe you've already told
about it some time ago.

Also the number of samples/s and how often Y is recaluclated
is still a big issue - had some nice effects due to my PID
running faster then the inertia of the motor could follow.

Kind regards,

       Stefan

1999\05\18@055921 by Stefan Sczekalla-Waldschmidt

flavicon
face
Hi,

Michael Rigby-Jones wrote:
>
> I used this trick for the PID controler I wrote a few months back.  I don't
> understand what you mean when you say running 16 bit values is not feasable.
> Most the the variables I used were 16 bit integers.   Admittedly I was using
> a 10bit ADC and DAC though.

Can you possibly post your code ? I use a rewrite of a MChip AN but
there may be a more elegant way ...

>
> It seems to me that you can spend all the time in the world with Bode plots
> and pages of enormous calculations, but at the end of the day, you can't
> beat sitting down and tuning control loops by experimentation.

Had this feling too ;-)

This is caused imho that you cant catch all possible delays in your
control
loop and many problems dont behave linear so you've to find a value that
fits
the most cases.

Kind regards,

       Stefan Sczekalla-Waldschmidt
       .....sswKILLspamspam.....oikossw.de

1999\05\18@102623 by Lawrence Lile

flavicon
face
In my oven, when it is too hot I turn the output to the heaters off, and
also set the I term to zero.  The controller can't GO any lower than off, so
I term doesn't accomplish anything, and I don't want positive values of I
stacking up and canceling the negative values of I which will be seen after
the oven cools below the setpoint.  I think you need to dump the I term
every once in a while.  When P=0 would work great if you have proportional
control of your output.



{Original Message removed}

1999\05\18@104932 by Gerhard Fiedler

picon face
At 11:35 05/18/99 +0200, Tjaart van der Walt wrote:
>Stefan Sczekalla-Waldschmidt wrote:
>> Tjaart van der Walt wrote:
>> > Good advice. I have noticed another thing that can make your
>> > system much more immune to the low-frequency I-oscillations :
>> > Reset the I-value to zero whenever P=0.
>>
>> looks like a good Idea - BTW did you try to optimize your PID-paramters
>> according to Ziegler-Nichols ?
><GRIN> I optimised them according to Tjaart-Experiment!
>
>The resetting of I compensates (among other things) for
>the digital nature of the calculations. Running 16 bit
>PID values in a PIC is not feasible, so I pulled a few
>tricks out of the hat. Another, is to only accumulate
>the I value every 10-50 (settable) samples. Effectively
>this divides the I term which is always much smaller
>than the P or D terms.

actually, there are two more possibilities to handle the i part, especially
for slow (eg. temperature) processes where it is for long intervals of
ramping (like heating or cooling) far away from the setpoint: you can limit
it and/or you can reset it to 0 whenever the difference is too big (ie.
you're positive that you're not in a deviation, but in a ramp).

if the i part is already all the way to the max when the system actually
starts regulating after spending a long time in a ramp approaching the
setpoint, that's an almost sure recipe for oscillations.

ge

1999\05\18@114213 by Lawrence Lile

flavicon
face
-----Original Message-----
From: Michael Rigby-Jones <EraseMEmrjonesspam_OUTspamTakeThisOuTnortelnetworks.com>
To: 'Lawrence Lile' <lilelspamspam_OUTtoastmaster.com>
Date: Tuesday, May 18, 1999 9:48 AM
Subject: RE: PID algorithms in PIC C


>OTOH, the oven can't be any more on than on, so how does I help when the
>oven is too cold?
>


s'easy - when the oven is on, it is on with a duty cycle between 0% and 100%
which achieves proportional control.  Howver, unlike a motor that can turn
both ways, a heating element can heat but it cannot cool.  So when we want
the oven cooler we just have to wait, whereas if we want it hotter we can
duty cycle a measured, precise amount of heat.  The I-term can help achieve
a setpoint with minimum error but only in one direction.

In the other PID application floating around the List today, using the
peltier junction, which can both heat and cool, you'd probably only toss the
I-term, if at all, when P=0, like Tjaart suggested.  Maybe never.

>
>
>> In my oven, when it is too hot I turn the output to the heaters off, and
>> also set the I term to zero.  The controller can't GO any lower than off,
>> so
>> I term doesn't accomplish anything, and I don't want positive values of I
>> stacking up and canceling the negative values of I which will be seen
>> after
>> the oven cools below the setpoint.  I think you need to dump the I term
>> every once in a while.  When P=0 would work great if you have
proportional
{Quote hidden}

1999\05\19@203519 by Steve Sexton

flavicon
face
Arnie,

Can you send me a copy of the PID source?

Steve Sexton.

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...