i'd use arduino pid library controls, need synchronize manually.
what have continually monitored analog input i'm manually averaging, , upon digital input change, locks average input pid, , i'd @ point, , @ point calculate pid output based on error.
basically, since need synchronize updates output, i'm worried automatic running pid end going haywire derivative , integral gain when thinks winding output doing nothing input, resulting in railing.
what expect i'll have pid controller has "setsampletime" ignored , instead sequential datapoints stored in controller manually added. happen?
so like:
what have continually monitored analog input i'm manually averaging, , upon digital input change, locks average input pid, , i'd @ point, , @ point calculate pid output based on error.
basically, since need synchronize updates output, i'm worried automatic running pid end going haywire derivative , integral gain when thinks winding output doing nothing input, resulting in railing.
what expect i'll have pid controller has "setsampletime" ignored , instead sequential datapoints stored in controller manually added. happen?
so like:
code: [select]
#include <pid_v1.h>
double input, output, setpoint, inputavg;
pid mypid(&input, &output, &setpoint, 1.0, 0.05, 0.25, direct);
float timeconstant 0.01;
void setup() {
// give setpoint target input of 100.
setpoint = 100;
// set "manual" (whatever means).
mypid.setmode(manual);
}
void loop() {
// running average of analog input a0.
inputavg = inputavg*(1-timeconstant) + analogread(a0)*timeconstant;
// if digital pin goes high, , update pid output.
// let's pretend magical input goes high 1 loop,
// in practice i'll doing interrupt setting flag on positive edge.
if (digitalread(0) == high) {
// double buffered average put input.
input = inputavg;
// pid calculates error , determines new output.
mypid.compute();
// manually send out new output. pretend function works.
analogwrite((unsigned int)output);
}
}
pid supposed monitor input , compare setpoint, , automatically make adjustments. not sound want. so, forget pid.
Arduino Forum > Using Arduino > Programming Questions > Arduino PID in Manual Mode?
arduino
Comments
Post a Comment