I suppose this is for Henrik.
When the ADC read value reaches the Setpoint, should'n the pid_out goto zero instead of staying for ever in a, relatively low, value?
Ioannis
As far as this PID code goes this is by far the most common question I've received over the years....
If you have no integral gain then yes the output should (and will) be zero when the error is (and has been) zero for at least one cycle (depending on the derivative part of the regulator).
But most of the time you're using a PID regulator because you NEED the I and D parts as well so no, the output should NOT (necessarily) go to zero just because the error does.
When the error reaches zero the total output of the regulator will be whatever the I-term has contributed. If you want/need the output to be zero when the error is then you don't want/need the I-term. Lets take the old analogy of a car in cruise control going down the road, the setpoint is 70km/h and the throttle is 15%. The the car aproaches a hill which causes it to slow down (the error increases) so the proportinal term adds "effort" to the output in order to compensat but because the hill is steep it's not enough to drive (no pun inteneded) the error to zero so little by little the I-term adds "effort" to the output which makes the car produce more power to compensate to for the steep climb.
After a short while the car is back at 70km/h despite it being in this steep hill. Now everyone one that has asked me this question expects the output of the regulator to become zero because there is no error. But what do you think happens then?
/Henrik.
Many time I tried the PID include on different projects but never with success.
This time I am determined to make it work.
The new setup has a 3 phase blower that sucks air from a container, a pressure sensor, a 3-phase inverter to control the motor and a PIC to set the setpoint and measure the pressure.
The pressure is getting close but never on target. I managed to make it stable enough but does not reach the setpoint.
The PID setting so far are as:
pid_Kp = $0250
pid_Ki = $f000
pid_Kd = $ff00
pid_Ti = 8 'Update I-term every 8th call to PID
pid_I_Clamp = 100 'Clamp I-term to max ±100
pid_Out_Clamp = 1023
Increasing the Kp term makes the loop unstable.
Seems the system need a gain but that leads to a non stable loop.
Ioannis
You have quite high integral gain I'm surprised the system doesn't become unstable with that.
I'd try setting Ki and Kd to 0, then increase Kp until you're starting to get oscillation then back Kp off a bit. At this point I suspect that you're not quite reaching the setpoint so start increasing Ki. The intergral term will help "catch up" the part that the proportional alone can't do.
How often do you run the loop?
Hi Henrik. Thanks for your attention.
I started as you said, with zero the terms Ki and Kd.
The point of oscillation was a bit higher than the $250. About $0300.
Then I increased Ki but never reached set point, only oscillation point.
The posted values are the maximum that can be obtained. But there is a substantial difference to the set point.
Ioannis
Bookmarks