Source code for PID

I am looking a good origin for PID C source code. It would be nice if it also includes software which will help tuning the PID loop. I may also consider self tuning algorithm.

I consider to include it in our RTU (remote terminal unit)

Thanks, Martin Roth Motorola Israel

Reply to
Martin Roth
Loading thread data ...

It's really not that hard - if you understand what PID is.

There are some wrinkes (e.g. look into integral wind-up, parallel/serial PID, etc) and think carefully about the range/precision (and where necessary, limiting) of your variables. Also consider your input filtering very carefully - input noise will translate into D-term activity...

Steve

formatting link

Reply to
Steve at fivetrees

There was an article in Embedded Systems Programming magazine a while back entitled "PID without a PHD" which is probably Google-able.

Bob

Reply to
Bob Stephens

e PID

A good book on the PID theory and practice:

"Advances in PID Control" TK Jiong, W. Quing-Guo, HC Chieh and TJ H=E4gglund

As for the PID implementation in C, it is very trivial and=20 straightforward. It is just a few lines of code once you know how to do i= t.

Vladimir Vassilevsky

DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

There's a very complete article in the new Embedded Systems magazine. I just got it today, and it's at work, so I don't have any more info than that. It covered speed control of a DC motor, including simulation and tuning.

GS

Reply to
Gob Stopper

Article:

formatting link

Code: ftp://ftp.embedded.com/pub/2006/01rosales/PIcontrollerESD.asm

Jon

Reply to
Jonathan Kirwan

Are you SURE you really want a PID controller? There are many other control technologies (bang-bang, SPC, etc.) -- each has characteristics suitd to different types of control problems.

And, even if you *think* you want a PID controller, are you sure ou need all three terms (i.e. P and PI controllers are far more commonplace).

You'll also need to learn the basics about PID controllers if you ever expect to deploy anything non-trivial. I.e., tuning can be a real chore. And, there are many ways the controller can "fail" (to perform adequately) if not designed well (e.g., bumpless transfer, anti-windup, etc.)

Do yourself -- and your project -- a favor and research control theory before trying to *apply* that theory... :-/

HTH,

--don

Reply to
Don

Hi, Martin,

[apologies to cae if this is a duplicate post...: I am looking a good origin for PID C source code.

Are you SURE you really want a PID controller? There are many other control technologies (bang-bang, SPC, etc.) -- each has characteristics suitd to different types of control problems.

And, even if you *think* you want a PID controller, are you sure ou need all three terms (i.e. P and PI controllers are far more commonplace).

You'll also need to learn the basics about PID controllers if you ever expect to deploy anything non-trivial. I.e., tuning can be a real chore. And, there are many ways the controller can "fail" (to perform adequately) if not designed well (e.g., bumpless transfer, anti-windup, etc.)

Do yourself -- and your project -- a favor and research control theory before trying to *apply* that theory... :-/

HTH,

--don

Reply to
Don

I respectfully disagree, sorta.

I disagree because I have seen or heard about a great number of successful control loops that are closed by people without much control theory background, or that are closed by people who took the classes but don't use the knowledge. When they work it's because the performance that's required from the loop is well below the performance that the hardware is capable of, in which case a casual PID tuning will suffice.

I only sort of disagree because if you don't have the control theory (or if you don't use it) then you won't really know if your solution is correct until after you've built your product and tested it. Since well-behaved control loops often depend on the hardware that they're built of as much as they depend on the control rules in software this can be a bad time for such discoveries.

At any rate there is some code for implementing PID controllers in

formatting link
There are also a few guidelines for choosing sampling rates and data path depths in there.

--
Tim Wescott
Wescott Design Services
 Click to see the full signature
Reply to
Tim Wescott

formatting link

--
Tim Wescott
Wescott Design Services
 Click to see the full signature
Reply to
Tim Wescott

It's easy to get a loop running well "near steady-state". And, with any sort of an "I" term, the error term *will* be driven to "0".

The problem lies in how you handle the *dynamics* of the loop. Classic PID theory is, in my experience, *rarely* implemented directly in software -- because it has too many inherent flaws; too many "missing features" which can be fixed in a software implementation (e.g., how/when to reset the integrator, how/when to disable the "D" term, etc.). Poorly designed control loops fail when the controlled process is NOT behaving well -- or, when setpoint changes are made. And, poorly *tuned* loops often make the controlled process respond poorly (severely overdamped responses are common -- because the tuning has been done on the "safe" side; or, underdamped responses if tuned to casually).

You can drive a car without knowing how it works. You can even drive a HIGH PERFORMANCE car without knowing how it works! But, the car's driver is the equivalent of the *tuned* control loop's USER -- not the mechanic/engineer that

*designed* the car! On the race course (or highway) is a really BAD time to find out that the engine mounts can't handle the torque of a jackrabbit start...

--don

Reply to
Don

Yes Very Trivial. When I first wrote one > wade through may Math filled articles. Followed by many with fully optimized poorly commented code. Then I found a few comments on implementation. And learned how easy it was. The Moral: Easy when you know how. Then there is tuning..................

Reply to
Neil

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.