Hi guys,
I am trying to implement a PI controller in the c2000 launchpad. The code that I am using is as follows:
typedef struct {
float Ref; // Reference
float Fdb; // Feedback
float Err; // Error
float Kp; // Proportional
float Ki_ts; // Integral x Sample time
float OutMax; // Saturation Up
float OutMin; // Saturation Down
float Out; // Output
float integral; // Output integral
float (*compute)();
} PIREG;
typedef PIREG *PIREG_handle;
void pireg_compute(PIREG_handle);
void pireg_compute(PIREG *v){
v->Err = v->Ref - v->Fdb;
v->integral = v->integral + v->Ki_ts*v->Err;
if ( v->integral > v->OutMax){
v->integral = v->OutMax;
} else if (v->integral < v->OutMin){
v->integral = v->OutMin;
}
v->Out = v->integral + v->Kp*v->Err;
if ( v->Out > v->OutMax){
v->Out = v->OutMax;
} else if ( v->Out < v->OutMin){
v->Out = v->OutMin;
}
}
The controller is not working, can anyone spot an error in my code?
Thanks in advance
Nicolas