本帖最后由 像风儿一样清 于 2016-11-9 19:36 编辑
下面这段程序在编译的时候总是报错,大家给看看:
#include <msp430f4250.h>
#include <stdlib.h>
#include <math.h>
#include "display.h"
typedef struct
{float setpoint;//设定目标
float presentpoint;//当前温度
float last_error;//e[-1]
float prev_error;//e[-2]
float Iout;//积分输出
float Pout;//比例输出
float Dout;//微分输出
int OUT;//总的输出
float Ek;//误差偏差
float SEk;//误差累计
float DeltEk;//连续两次偏差的偏差
int PWMcycle;//PWM的最大的控制频率
}PIDtypedef;
int pid_calc(volatile unsigned int f)
{
volatile unsigned int f1=0;
float Kp = 300; //比例常数
float Ki = 0.1; //积分时间常数
float Kd = 150; //微分时间常数
int out=0;
int a;
PID.setpoint=15;
PID.PWMcycle=511;
PID.presentpoint=0;
PID.last_error=0;
PID.prev_error=0;
PID.Iout=0;
PID.Pout=0;
PID.Dout=0;
PID.OUT=0;
PID.Ek=0;
PID.SEk=0;
PID.DeltEk=0;
f1=f;
PID.presentpoint=display1(f1);
PID.EK=PID.setpoint-PID.presentpoint;//得到当前的偏差值
PID.Pout=PID.Ek*Kp;//比例输出
PID.SEk+=PID.Ek;
PID.prev_error=PID.last_error;
PID.last_error=PID.Ek,
PID.DeltEk=PID.last_error-PID.prev_error;
PID.Iout=Ki*PID.SEk;
PID.Dout=Kd*PID.DeltEk;
out=PID.Iout+PID.Pout+PID.Dout;
if(out>=PID.PWMcycle)
PID.OUT=511;
else if(out<=0)
PID.OUT=0;
else
PID.OUT=out;
a=PID.OUT;
return (a);
}
|