--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/brewco/pid.h Wed Nov 25 22:49:35 2015 +0100 @@ -0,0 +1,31 @@ +#ifndef PID_H +#define PID_H + +#define PID_MODE_NONE 0 /* Process control off */ +#define PID_MODE_AUTO 1 /* Process control auto */ +#define PID_MODE_BOO 2 /* Process control Bang On/Off */ + +#define PID_TIMES 60 /* 60 calculations per minute */ +#define PID_WINDUP_GUARD 10.0 /* Error windup guard */ + + +typedef struct _pid_var { + double iMax; /* Maximum allowable integrator state */ + double iGain; /* Integral gain */ + double pGain; /* Proportional gain */ + double dGain; /* Derivative gain */ + + double Input; /* Input value */ + double Err; /* Error, diff between input and set point */ + double ErrLast; /* Error from last pass */ + double iState; /* Error from next last pass */ + double SetP; /* Set point */ + double OutP; /* Output of PID algorithm */ + int Mode; /* Value is 'PID_AUTO' if loop is automatic */ +} pid_var; + + +void InitPID( pid_var *); +void UpdatePID( pid_var *); + +#endif