|
楼主 |
发表于 2013-5-30 19:18:06
|
显示全部楼层
always @ (posedge clk or negedge rst_n)
begin
if(~rst_n)
begin
buf_order <= 1023'd0;
order_cnt <= 10'd0;
order_ok <= 1'b0;
order_state <= 0;
next <= 0;
end
else
begin
case (order_state)
0:
begin
buf_order <= 1023'd0;
order_cnt <= 0;
order_ok <= 1'b0;
if(order_en & ~en_dly & ~next)
order_state <= 1;
end
1:
begin
next <= 1;
buf_order <= 1023'd0;
// order_cnt <= offs_value;
order_cnt <= 578;
order_ok <= 1'b0;
order_state <= 2;
end
2:
begin
if(order_cnt > 999)
begin
buf_order <= {fsk_data[22:0],fsk_data[1022:23]};
order_cnt <= order_cnt - 10'd1000;
end
else if(order_cnt > 899)
begin
buf_order <= {fsk_data[122:0],fsk_data[1022:123]};
order_cnt <= order_cnt - 10'd900;
end
else if(order_cnt > 799)
begin
buf_order <= {fsk_data[222:0],fsk_data[1022:223]};
order_cnt <= order_cnt - 10'd800;
end
else if(order_cnt > 699)
begin
buf_order <= {fsk_data[322:0],fsk_data[1022:323]};
order_cnt <= order_cnt - 10'd700;
end
else if(order_cnt > 599)
begin
buf_order <= {fsk_data[422:0],fsk_data[1022:423]};
order_cnt <= order_cnt - 10'd600;
end
else if(order_cnt > 499)
begin
buf_order <= {fsk_data[522:0],fsk_data[1022:523]};
order_cnt <= order_cnt - 10'd500;
end
else if(order_cnt > 399)
begin
buf_order <= {fsk_data[622:0],fsk_data[1022:623]};
order_cnt <= order_cnt - 10'd400;
end
else if(order_cnt > 299)
begin
buf_order <= {fsk_data[722:0],fsk_data[1022:723]};
order_cnt <= order_cnt - 10'd300;
end
else if(order_cnt > 199)
begin
buf_order <= {fsk_data[822:0],fsk_data[1022:823]};
order_cnt <= order_cnt - 10'd200;
end
else if(order_cnt > 99)
begin
buf_order <= {fsk_data[922:0],fsk_data[1022:923]};
order_cnt <= order_cnt - 10'd100;
end
else if(order_cnt > 89)
begin
buf_order <= {fsk_data[932:0],fsk_data[1022:933]};
order_cnt <= order_cnt - 10'd90;
end
else if(order_cnt > 79)
begin
buf_order <= {fsk_data[942:0],fsk_data[1022:943]};
order_cnt <= order_cnt - 10'd80;
end
else if(order_cnt > 69)
begin
buf_order <= {fsk_data[952:0],fsk_data[1022:953]};
order_cnt <= order_cnt - 10'd70;
end
else if(order_cnt > 59)
begin
buf_order <= {fsk_data[962:0],fsk_data[1022:963]};
order_cnt <= order_cnt - 10'd60;
end
else if(order_cnt > 49)
begin
buf_order <= {fsk_data[972:0],fsk_data[1022:973]};
order_cnt <= order_cnt - 10'd50;
end
else if(order_cnt > 39)
begin
buf_order <= {fsk_data[982:0],fsk_data[1022:983]};
order_cnt <= order_cnt - 10'd40;
end
else if(order_cnt > 29)
begin
buf_order <= {fsk_data[992:0],fsk_data[1022:993]};
order_cnt <= order_cnt - 10'd30;
end
else if(order_cnt > 19)
begin
buf_order <= {fsk_data[1002:0],fsk_data[1022:1003]};
order_cnt <= order_cnt - 10'd20;
end
else if(order_cnt > 9)
begin
buf_order <= {fsk_data[1012:0],fsk_data[1022:1013]};
order_cnt <= order_cnt - 10'd10;
end
else if(order_cnt > 8)
begin
buf_order <= {fsk_data[1013:0],fsk_data[1022:1014]};
order_cnt <= order_cnt - 10'd9;
end
else if(order_cnt > 7)
begin
buf_order <= {fsk_data[1014:0],fsk_data[1022:1015]};
order_cnt <= order_cnt - 10'd8;
end
else if(order_cnt > 6)
begin
buf_order <= {fsk_data[1015:0],fsk_data[1022:1016]};
order_cnt <= order_cnt - 10'd7;
end
else if(order_cnt > 5)
begin
buf_order <= {fsk_data[1016:0],fsk_data[1022:1017]};
order_cnt <= order_cnt - 10'd5;
end
else if(order_cnt > 4)
begin
buf_order <= {fsk_data[1017:0],fsk_data[1022:1018]};
order_cnt <= order_cnt - 10'd5;
end
else if(order_cnt > 3)
begin
buf_order <= {fsk_data[1018:0],fsk_data[1022:1019]};
order_cnt <= order_cnt - 10'd4;
end
else if(order_cnt > 2)
begin
buf_order <= {fsk_data[1019:0],fsk_data[1022:1020]};
order_cnt <= order_cnt - 10'd3;
end
else if(order_cnt > 1)
begin
buf_order <= {fsk_data[1020:0],fsk_data[1022:1021]};
order_cnt <= order_cnt - 10'd2;
end
else if(order_cnt > 0)
begin
buf_order <= {fsk_data[1021:0],fsk_data[1022:1022]};
order_cnt <= order_cnt - 10'd1;
end
else //为什么执行不到这里?
begin
next <= 0;
buf_order <= fsk_data[1022:0];
order_cnt <= order_cnt - 10'd0;
order_ok <= 1;
order_state <= 0;
end
end
defaultrder_state <= 0;
endcase
end
end
重新改了改代码,给order_cnt赋了个初值,结果倒是跳出了状态2,但做的减法不对,波形如图所示 |
-
-
|