VL22 根据状态转移图实现时序电路

 

和上一题的第一段完全相同,第二段只是根据状态转移有部分改变,本体使用三段式状态机来写,第三段写法和上一题不一样。

`timescale 1ns/1ns

module seq_circuit(
   input                C   ,
   input                clk ,
   input                rst_n,
 
   output   wire        Y  
);
reg [1:0] current_state;
reg [1:0] next_state;

always @(posedge clk,negedge rst_n)begin
if(!rst_n)begin
    current_state<=2'b00;
    next_state<=2'b00;
end
else
current_state<=next_state;
end
always @(*)begin
case(current_state)
    2'b00 : next_state =(C==1'b1) ? 2'b01: 2'b00;
    2'b01 : next_state =(C==1'b1) ? 2'b01: 2'b11;
    2'b10 : next_state =(C==1'b1) ? 2'b10: 2'b00;
    2'b11 : next_state =(C==1'b1) ? 2'b10: 2'b11;
    default:next_state =2'b00;
endcase
end
//assign Y=(current_state==2'b11) |(next_state == 2'b10);
reg r_Y;
always @(*)begin
    case(current_state)
    2'b00: r_Y=0;
    2'b01: r_Y=0;
    2'b10: r_Y=(C==1) ? 1:0;
    2'b11: r_Y=1;
    default r_Y=0;
    endcase
end
assign Y=r_Y;
endmodule
posted @ 2024-08-26 16:31  段星儿  阅读(48)  评论(0)    收藏  举报