PID Windup on the way down
- ContinenteCNC
-
Topic Author
- Offline
- Premium Member
-
Less
More
- Posts: 97
- Thank you received: 43
29 Dec 2025 21:47 - 01 Jan 2026 21:30 #340682
by ContinenteCNC
PID Windup on the way down was created by ContinenteCNC
Hi folks!
The current PID hal module has a maxoutput pin to avoid integrator windup, but wasn't it supposed to have also a minoutput pin?
I am currently setting up a basic spindle control for a lathe and I am experiencing windup when I have to go from a higher spindle speed to a lower speed. On the way up it works just fine (well tuned)
Then I noticed that the PID output goes negative for a while during the ramp down, so the integrator is winding up to the negative side. This doesn't make sense from the DAC/VFD point of view, once the lower voltage they can handle is 0V. (I am using 0-10v analog control)
What I've just wrote make sense? Or am I just shaming myself publicly again?
The current PID hal module has a maxoutput pin to avoid integrator windup, but wasn't it supposed to have also a minoutput pin?
I am currently setting up a basic spindle control for a lathe and I am experiencing windup when I have to go from a higher spindle speed to a lower speed. On the way up it works just fine (well tuned)
Then I noticed that the PID output goes negative for a while during the ramp down, so the integrator is winding up to the negative side. This doesn't make sense from the DAC/VFD point of view, once the lower voltage they can handle is 0V. (I am using 0-10v analog control)
What I've just wrote make sense? Or am I just shaming myself publicly again?
Last edit: 01 Jan 2026 21:30 by ContinenteCNC.
The following user(s) said Thank You: NWE
Please Log in or Create an account to join the conversation.
- NWE
- Offline
- Senior Member
-
Less
More
- Posts: 72
- Thank you received: 20
30 Dec 2025 04:47 #340697
by NWE
Replied by NWE on topic PID Windup question/suggestions
Pid maxoutput limits in the positive and negative direction. So, you can set maxoutput to 1.0 and it will limit the output in the range of 1.0 to -1.0
I'm not sure what it would take to prevent windup below 0.
For what its worth, one thing that has bit me in the past in trying to tune PID and lots of troubles with windup: slow vfd accel/decel. If the PID is tuned to respond faster than the ramp time of the VFD, that'll wind it up.
Also, a hal limit1 component might be in order to prevent sending a negative voltage to the vfd analog input, some kinds smoke when they get negative signals.
I'm not sure what it would take to prevent windup below 0.
For what its worth, one thing that has bit me in the past in trying to tune PID and lots of troubles with windup: slow vfd accel/decel. If the PID is tuned to respond faster than the ramp time of the VFD, that'll wind it up.
Also, a hal limit1 component might be in order to prevent sending a negative voltage to the vfd analog input, some kinds smoke when they get negative signals.
The following user(s) said Thank You: ContinenteCNC
Please Log in or Create an account to join the conversation.
- ContinenteCNC
-
Topic Author
- Offline
- Premium Member
-
Less
More
- Posts: 97
- Thank you received: 43
30 Dec 2025 20:10 - 01 Jan 2026 21:30 #340736
by ContinenteCNC
Replied by ContinenteCNC on topic PID Windup on the way down
In my case, there is no need to limit the output at zero. I am using pwmgen to generate the 0–10 V signal in type=0, so any negative PID output is clamped to zero.
The PID behaves correctly during ramp-up, since the output is limited to the maximum possible pwmgen value. The derivative gain provides enough damping to prevent overshoot in that direction. However, during ramp-down, there is a small amount of overshoot. It is minimal and perfectly acceptable for my application.
I was just wondering whether it would be useful to have a minoutput pin, allowing the lower limit to be set to zero instead of -maxoutput.
The PID behaves correctly during ramp-up, since the output is limited to the maximum possible pwmgen value. The derivative gain provides enough damping to prevent overshoot in that direction. However, during ramp-down, there is a small amount of overshoot. It is minimal and perfectly acceptable for my application.
I was just wondering whether it would be useful to have a minoutput pin, allowing the lower limit to be set to zero instead of -maxoutput.
Last edit: 01 Jan 2026 21:30 by ContinenteCNC.
Please Log in or Create an account to join the conversation.
- ContinenteCNC
-
Topic Author
- Offline
- Premium Member
-
Less
More
- Posts: 97
- Thank you received: 43
01 Jan 2026 20:40 - 01 Jan 2026 21:35 #340854
by ContinenteCNC
Replied by ContinenteCNC on topic PID Windup on the way down
I have edited the original pid.c to include a minoutput pin, and now it works like a charm. There is no windup and zero overshoot on the way down, just like on the way up.
To install it, open a terminal in the folder containing the modified pid.c and run:
Then set the minoutput pin to the minimum ADC value your setup can handle. In my case, this value is zero, since I am using a software pwmgen to generate a 0–10 V signal:
This is the piece of code I have customized:
To install it, open a terminal in the folder containing the modified pid.c and run:
sudo halcompile --install pid.cThen set the minoutput pin to the minimum ADC value your setup can handle. In my case, this value is zero, since I am using a software pwmgen to generate a 0–10 V signal:
setp pid.0.minoutput 0.0This is the piece of code I have customized:
/* apply output limits */
if (*(pid->maxoutput) != 0.0) {
if (tmp1 > *(pid->maxoutput)) {
tmp1 = *(pid->maxoutput);
pid->limit_state = 1.0;
} else if (tmp1 < *(pid->minoutput)) {
tmp1 = *(pid->minoutput);
pid->limit_state = -1.0;
} else { pid->limit_state = 0.0;
}
Last edit: 01 Jan 2026 21:35 by ContinenteCNC.
The following user(s) said Thank You: tommylight
Please Log in or Create an account to join the conversation.
Time to create page: 0.102 seconds