| ControlSim The PID controller and process simulator based on MS Excel spread sheets. $45.00 | Click here to get more details, buy, and download |
Buy and download my eBook: The
PID Control Algorithm: How It Works, How To Tune It, and How to Use It. 2nd ed.
62pp |
Get more details, buy, and download |
PID Algorithm Code | ||||||||||||||||||||||||||||||||||
|
There are many ways to implement the PID algorithm digitally. Two are discussed here. In each case, there will be a section of code (in structured Basic, easily convertible to any other language) that will be executed by the processor every second. (some other scan rate may be used, change the constant 60 to the number of times per minute it is executed.) In each code sample there is an IF statement to execute most of the code if the loop is in the auto mode. If the loop is in manual mode only a few lines are executed in order to allow for bumpless transfer to auto. Also, while the control loop is in manual, the output (variable OutP) will be operator adjustable using the operator interface software. The code shown here and on the next page can be translated into any computer language. For information about process control programming in Visual Basic and C#, some very good information can be found at HT Services site HERE >>> Simple PID code.One method of handling the integration and bumpless transfer to automatic mode is an algorithm that calculates the change in output from one pass to the next using the derivative of the PID algorithm, or: dOut/dt = gain x (dError/dt + ResetRate x Error + Derivative x d2Error/dt2 derivative of output = gain x (derivative of error + reset rate x error + second derivative of error) . This program is run every second. If the control loop is in manual, the output is adjusted by the operator through the operator interface software. If the control loop is in Automatic, the output is computed by the PID algorithm.
Each pass the output is changed by adding the change in output to the previous pass output. That change is the sum of: This simple version of the PID controller work well in most cases, and can be tuned by the standard PID tuning methods (some of which are discussed later). It has �Parallel� rather than �Series� reset and derivative, and derivative is applied to the error rather than the input only. Variables:
The PID emulation code: 2. Err=SetP- Input Error based on reverse action 3. IF Action = �DIRECT� THEN 4. Err=0 Err Change sign of error for direct action 5. ENDIF 6. OutP=OutP+Gain*(Err-ErrLast+Reset*Err+Deriv*(Err-ErrLast*2+ErrLastLast)) Calculate the change in output using the derivative of the PID algorithm, then add to the previous output. 7. ErrLastLast=ErrLast 8. ErrLast=Err 9. ELSE 10. ErrLastLast=Err 11. ErrLast=Err 12. ENDIF 13. IF OutP > 100 THEN OutP=100 Limit output to between 14. IF OutP < 0 THEN OutP=0 0 and 100 percent The only serious problem with this form of the algorithm occurs when the output has reached an upper or lower limit. When it does, a change in the measurement can unexpectantly pull the output away from the limit. Next: A Better Implementation |
|||||||||||||||||||||||||||||||||
| ControlSim The PID controller and process simulator based on MS Excel spread sheets. $45.00 | Click here to get more details, buy, and download |
Buy and download my eBook: The
PID Control Algorithm: How It Works, How To Tune It, and How to Use It. 2nd ed.
62pp |
Get more details, buy, and download |
Thousand Acre Swamp Hike Schedule
A schedule of the 2006 public hikes at Thousand Acre Swamp in Penfield, NY