IpidSet() sets PID coefficients, calculation interval and output range.
bool IpidSet(uint8_t id, float kp, float ki, float kd, unsigned long sampleMs, float outMin, float outMax)
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
IpidSet(id, kp, ki, kd, sampleMs, outMin, outMax) | uint8_t id — PID loop number. Supports 0 ~ 255float kp — Proportional gain. Negative inputs are treated as 0float ki — Integral gain. Integration based on secondsfloat kd — Derivative gain. Differentiation based on secondsunsigned long sampleMs — PID calculation interval in ms. 0 is not allowedfloat outMinfloat outMax | bool | Sets PID coefficients, calculation interval and output range. |
void setup() { IpidSet(2, 4.0, 0.2, 0.0, 100, 0, 255); // Set PID coefficients, calculation interval and output range. IpidReverse(2, true); // Select direct or reverse PID action. } void loop() { float pv = ntcRead(4) / 10.0; // Return the NTC 3950 10kΩ sensor temperature as an integer in 0.1°C units. float sv = 25.0; int output = (int)IpidRun(2, pv, sv); // Calculate the PID output from the current value and setpoint. analogWrite(11, output); }
IpidRun() retains the previous output until the sampleMs interval has elapsed. It may be called repeatedly in loop().IpidItermLimit() if additional limits are needed.IpidReset() resets the integral term, previous PV and previous output value.id for only one control loop.