en-us_commands:reference:ipidset
This is an old revision of the document!
Table of Contents
IpidSet()
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)
Commands
| 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. |
Example
void setup() { IpidSet(1, 5.0, 0.5, 1.0, 100, 0, 65535); } void loop() { float pv = ntcRead(4) / 10.0; float sv = 50.0; uint16_t output = (uint16_t)IpidRun(1, pv, sv); PWM(12, output, true); }
Precautions
- PID output can directly affect field equipment. Begin testing with a low output range and small gains.
IpidRun()retains the previous output until thesampleMsinterval has elapsed. It may be called repeatedly inloop().- The integral term is automatically constrained by the output limits to reduce windup. Use
IpidItermLimit()if additional limits are needed. - The derivative term is calculated from the PV change to reduce abrupt jumps caused by setpoint changes.
IpidReset()resets the integral term, previous PV and previous output value.- Use the same
idfor only one control loop.
en-us_commands/reference/ipidset.1788785567.txt.gz · Last modified: by 127.0.0.1
