|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
积分分离pid控制的verilog程序,请帮助修改。
积分分离pid控制的verilog程序
小弟刚接触eda,现在在进行毕业设计,方向是用FPGA控制直流电机,进行点位控制。资料太少。
刚编的pid控制的verilog程序,采用积分分离方式,m是视场切换指令,现在问题多多,请各位高手帮忙修改。
万望各位大侠拉小弟一把 ,切切! 问题1:kp=1.1, ki=0.0286, kd=10.2是小数应该如何处理? 问题2:为何即使将kp、 ki 、kd都改成整数,综合还是不能通过?
module pid(
rst,clk,clk2,m,p_cur, //input
uout,dataout
); //output
input rst,clk,clk2;
input[7:0] m; //m is option
input[11:0] p_cur; //pcur is position
output[11:0] uout;
output[7:0] dataout;
reg[11:0] q0,q1,qa,qb;
reg[11:0] u_0,u_1,u3_1,u;
reg[11:0] e_0,e_1,e_2;
reg[11:0] ke;
reg[23:0] u1,u2,u3;
reg[23:0] b1,b2,b3,b4,b5;
reg[11:0] e_01,e_k;
reg[11:0] uout;
reg[7:0] dataout;
parameter r=400, p1_0=12'b100100000000, p2_0=12'b010000000000, //initial
kp=1.1, ki=0.0286, kd=10.2;
assign p1_1 = ~p1_0+1;
assign p2_1 = ~p2_0+1;
assign pcur_1 = ~p_cur+1;
always@( posedge rst )
if(rst==1'b1)
begin
u_0 <= 0;
u_1 <= 0;
e_0 <= 0;
e_1 <= 0;
e_2 <= 0;
dataout <= 0;
uout <= 0;
end
always@( posedge clk2)
begin
case(m)
1'b0 : begin
e_0 =p1_1-p_cur; //e_0<=p1-p_cur
if (e_0[11]==1)
e_01 = ~e_0+1;
else e_01 = e_0;
end
1'b1 : begin
e_0 <= p2_1-p_cur; //e_0<=p2-p_cur
if (e_0[11]==1)
e_01 = ~e_0+1;
else e_01 = e_0;
end
endcase
end
always@( posedge clk )
begin
if (e_01>r) //pd
begin
e_k = e_01-e_1;
u1 = kp*e_01;
u2 = kd*e_k;
u3 = u1+u2;
u3_1 = u3[15:4];
u = u_1+u3_1;
end
else //pid
begin
ke = ki+kd;
q0 = kp+ke;
qa = (-1)*kp;
qb = (-2)*kd;
q1 = qa+qb;
b1 = kd*e_2;
b2 = q1*e_1;
b3 = b1+b2;
b4 = q0*e_0;
b5 = b3+b4;
u = u_1+b5[15:4];
end
end
always@(posedge clk2)
begin
uout=~u+1; //link to DAC
end
always@(negedge clk2)
begin
u_1 = u;
e_2 = e_1;
e_1 = e_0;
end
endmodule |
|