Of course this makes sense.
Thanks,
Ioannis
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
Ioannis, What is your loop time period for calling the PID routine? I have been using a routine similar to Henrick's for years in many different projects and I have to admit, Your Integral and Derivative values seem quite high. Do you have a Proportional clamp term? Also is the Integral term being clamped?
Dave Purola,
N8NTA
EN82fn
Hi Dave.
Do you imply that high values make it hard to reach setting point?
The I clamp is in the list of the parameters. It is set to 100. Setting it higher makes oscillation worse to control.
As for the Proportional I do not clamp it.
The loop was tested from 2 to 20ms with no difference in behaviour (besides being a bit slower at the 20ms of course).
Ioannis
I think it's the integral clamp that's the root cause.
When the actual value is getting closer to the target, the output from the proportional term gets smaller and the integral term needs to "build up" in order to to "aproach" the target. But with the integral clamp set to less than 10% of the full output swing there's not much it can do.
Try reducing the integral gain by a factor of 100 or there abouts, then increase the intergral limit to 1000.
If your output is zero and you instantly set it to 100%, how long would you say it takes to reach full pressure?
When the pressure no longer increases, what's the value you read from the sensor that is then used to calculate the error that you send to the PID routine?
At full pressure, how much higher is that number compared to the highest allowed setpoint (how much margin is there)?
Not to complicate stuff further but this souds like a good application for using the feedforward feature. It helps provide a "baseline" output proportional to the setpoint (instead of proportional to the error) which in turn makes the job for actual regulator easier.
/Henrik.
EDIT: I don't think you need the derivative term, try setting that to 0 to start with. And finally, it's important that the time between calls to the PID routine (and the time between reading the feedback) is constant (ie driven by a TMR interrupt for example).
Last edited by HenrikOlsson; - 1st October 2018 at 18:13.
Thank you Henrik for the reply.
Well, for the testing I did not had very precise call to the PID routine. It is based on a tide loop of 2 to 20 ms (Pause 2 etc) without having any other tasks to deviate from the loop time. At least considerably.
In the mean time, I tested the PID profile of the inverter that I drive and after playing with the settings seems very stable. Since I have it running smooth, I will now try to make it work through PIC.
The loop can be stable and it takes about 3-5 seconds to reach the setting point with the inverter.
Will follow your suggestions and try to implement also the feedforward feature and will report the time it takes to respond.
Tricky but very interesting thing that PID filter.
If you wonder why do the PID on the PIC instead of using the ready made solution of the Inverter, the answer is that inverters may change on the system in production or service and I prefer to have it under my circuit control.
Thanks again,
Ioannis
Henrik,
I'm using your great routine in a step/dir servo driver. Everything works fine. But have been wondering about the "pid_Ti" constant
What are your thoughts on the Up-date i-term? I have kept it at 8. My pid update rate is approx 1950hz. So the I term is updating at 1950/8 = 244hz.
Thanks
@Ioannis, this video gives a great visual of all the factors including loop time on the output response
Mark,
It provides some filtering to the input of the integrator and slows down its response some. The integrator does run on every call but the output of it is only added to the total output every n'th call to PID and at that time it's the average of the accumulated error over the last n calls (times the gain) that gets added. So I believe it should/could help with an otherwise "ringing" or "hunting" response where the integrator drives the target above the setpoint, then back below the setpoint and back up etc.
Step and direction servo, cool! That's the exact application for my own use as well :-) Care to share some details?
One thing I've done in my servo is to allow the user to disable the I-term when the commanded velocity is >0. This is because when moving there will always be a following error which will build up I-term which will cause overshoot at the end of the move. If the intergrator is only allowed to accumulate when the commanded velocity is zero it will only work to drive the steady state error at the end of a move away. It will come at a cost of a slightly larger following error but feedforward can help with that.
/Henrik.
Thanks for your reply. I was thinking it replaced the "dt" term found in most pid equations.
Here is my compete project. It's for learning purposes, for safety it would need to be modified to use in a real machine. Like opto inputs, over current protection and a system fault I/O. The Kp and Ki are adjustable with potentiometers. Kd is set to 3, as commented above not really used in this system. It uses a pic18f4431, but can be adapted for,4331,2431 and 2331
Henrik, if you see any that could be improved please comment. I'm working on a automated coil winder, using pid to maintain tension on the magnet wire. The tensionor is working in a mock up. What I want to figure out next is a serial input to update variables from a user interface.
Dear Henrik et al.
I am showing here how I implement PID in my 8bit process controllers. I have deliberately shown it as pseudo code for ease of understanding.
Typical C conventions are used. += is add to, != is not equal to
PB is the proportional band in which you will like PID action to take place. Outside the band, the output is either on or off at all times depending on which side it is of the Setpoint (SV) PV is the present value of the process variable
Integral time and Derivative time are between 0 to 3600 units of time (rate at which PID is run). I run my routine for temperature control every second.
Last edited by Jerson; - 3rd October 2018 at 07:54. Reason: removed signature
Bookmarks