User Tools

Site Tools


en-us_commands:reference:ipidrun

This is an old revision of the document!


IpidRun()

IpidRun() calculates the PID output from the current value and setpoint.

IpidRun command operation flow

float IpidRun(uint8_t id, float pv, float sv)

Commands

Command Arguments Return Value Operation
IpidRun(id, pv, sv) uint8_t id — PID loop number. Supports 0 ~ 255
float pv — Current value. Present Value
float sv — Setpoint. Set Value
float Calculates the PID output from the current value and setpoint.

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 the sampleMs interval has elapsed. It may be called repeatedly in loop().
  • 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 id for only one control loop.

← Built-in Command List

en-us_commands/reference/ipidrun.1788785567.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki