Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision Next revisionBoth sides next revision | ||
ezeio2:scriptref:pid_new [2020-08-14 23:20] – created andreh | ezeio2:scriptref:pid_new [2022-03-30 23:25] – andreh | ||
---|---|---|---|
Line 9: | Line 9: | ||
< | < | ||
< | < | ||
- | < | + | < |
< | < | ||
Line 44: | Line 44: | ||
// Set the tuning parameters | // Set the tuning parameters | ||
PID_tune(p, 0.2, 0.04, 0.01); | PID_tune(p, 0.2, 0.04, 0.01); | ||
+ | | ||
+ | // Set setpoint (target pressure) | ||
+ | PID_set(p, 40.0); | ||
| | ||
// Set update speed to 100ms | // Set update speed to 100ms | ||
Line 55: | Line 58: | ||
| | ||
// Read and scale a sensor input (0-100psi from 4-20mA sensor) | // Read and scale a sensor input (0-100psi from 4-20mA sensor) | ||
- | psi = 100.0 * ((GetInputValue(1)-4000)/ | + | psi = 100.0 * ((GetInputValue(1, INVAL_RAW)-4000)/ |
| | ||
// Update the PID with the feedback value | // Update the PID with the feedback value | ||
Line 66: | Line 69: | ||
</ | </ | ||
- | NOTE: The values used in the above example are not takes from a real world setup. Please make sure you understand how PID works and how to correctly tune them if you use any of the PID functions. | + | NOTE: The values used in the above example are not from a real world setup. Please make sure you understand how PID works and how to correctly tune the variables |