[an error occurred while processing this directive]
|
Что-то типа этого:
struct Regul
{
unsigned char Auto; //Auto = 1 / Manual = 0
unsigned char Value; //Current value
unsigned char SetPoint; //Set Point
unsigned char Output; //Output of regul
unsigned char Kp; //
unsigned char Ki; //
unsigned char Kd; //
unsigned char Zone; //
unsigned char Timp; //
unsigned char dX; //
unsigned char dY; //
unsigned char Ymin; //
unsigned char Ymax; //
int *Integral; //Integral calculating
int *Err; //Previous Error
};
void RGRout(struct Regul *Reg)
{
int Error;
long tmp;
int Out;
Error = GetVal(Reg->SetPoint) - GetVal(Reg->Value);
if(abs(Error) < GetVal(Reg->Zone)) Error = 0;
if(GetVal(Reg->Auto) == 0) //if Manual mode
{
if(GetVal(Reg->Mode) != 0) *Reg->Integral = *Reg->Err;
else *Reg->Integral = 0;
*Reg->Err = Error;
return; //continue;
}
//PID regulator
{
tmp = (long)Error * (GetVal(Reg->Kd) + 1000);
tmp -= (long)*Reg->Err * ((long)GetVal(Reg->Kd) * 2 - GetVal(Reg->Ki) + 1000);
tmp += (long)*Reg->Integral * GetVal(Reg->Kd);
tmp = (long)tmp / 1000 * GetVal(Reg->Kp) / 1000;
Out = GetVal(Reg->Output) + tmp;
*Reg->Integral = *Reg->Err;
*Reg->Err = Error;
}
if(Out > GetVal(Reg->Ymax)) Out = GetVal(Reg->Ymax);
if(Out < GetVal(Reg->Ymin)) Out = GetVal(Reg->Ymin);
PutVal(Reg->Output, Out);
}
E-mail: info@telesys.ru