|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
module controller (start,clk, Z, clear, plsr_load, add_sub_S1, add_sub_S2, latch_result);
input start;
input clk;
input Z;
output clear;
reg clear;
output plsr_load;
reg plsr_load;
output add_sub_S1;
reg add_sub_S1;
output add_sub_S2;
reg add_sub_S2;
output latch_result;
reg latch_result;
parameter[1:0] S0=0 ;
parameter[1:0] S1=1 ;
parameter[1:0] S2=2 ;
parameter[1:0] S3=3 ;
reg[1:0] present_state;
reg[1:0] next_state;
always @(present_state or start or Z)
begin : nextstate_logic
case (present_state)
S0 :
begin
clear <= 1'b0 ;
plsr_load <= 1'b1 ;
add_sub_S1 <= 1'b0 ;
latch_result <= 1'b0 ;
add_sub_S2 <= 1'b0 ;
if (start == 1'b1)
begin
next_state <= S1 ;
end
else
begin
next_state <= S0 ;
end
end
S1 :
begin
clear <= 1'b0 ;
plsr_load <= 1'b0 ;
add_sub_S1 <= 1'b0 ;
latch_result <= 1'b0 ;
add_sub_S2 <= 1'b1 ;
next_state <= S2 ;
end
S2 :
begin
clear <= 1'b1 ;
plsr_load <= 1'b1 ;
add_sub_S1 <= 1'b0 ;
latch_result <= 1'b0 ;
add_sub_S2 <= 1'b0 ;
if (Z == 1'b1)
begin
next_state <= S3 ;
end
else
begin
next_state <= S2 ;
end
end
S3 :
begin
clear <= 1'b1 ;
plsr_load <= 1'b1 ;
add_sub_S1 <= 1'b1 ;
latch_result <= 1'b1 ;
add_sub_S2 <= 1'b0 ;
next_state <= S1 ;
end
endcase
end
always @(clk)
begin : state_register
if (clk == 1'b1)
begin
present_state <= next_state ;
end
end
endmodule |
|