对于第三题,画出可以检测10010串的状态图,并用verilog实现。
我觉得这个是为了考察大家对状态机的了解程度,要不也就不用画状态图了,以下是我自己写的一段代码,应该没什么问题,如有问题,欢迎大家提出。
module j(clk , rst_b , i , o);
input clk;
input rst_b;
input i;
output o;
parameter C1 = 0,
C2 = 1,
C3 = 2,
C4 = 3,
C5 = 4,
C6 = 5;
reg [2:0] CS , NS;
always @(posedge clk or negedge rst_b) begin
if (!rst_b) begin
CS <= C1;
end
else begin
CS <= NS;
end
end
reg reg_o;
always @(i or CS) begin
case (CS)
C1: begin
if (i) begin
NS = C2;
end
else begin
NS = CS;
end
reg_o = 0;
end
C2: begin
if (~i) begin
NS = C3;
end
else begin
NS = C2;
end
reg_o = 0;
end
C3: begin
if (~i) begin
NS = C4;
end
else begin
NS = C2;
end
reg_o = 0;
end
C4: begin
if (i) begin
NS = C5;
end
else begin
NS = C1;
end
reg_o = 0;
end
C5: begin
if (~i) begin
NS = C6;
end
else begin
NS = C2;
end
reg_o = 0;
end
C6: begin
if (i) begin
NS = C2;
end
else begin
NS = C4;
end
reg_o = 1;
end
default: begin
NS = C1;
reg_o = 0;
end
endcase
end
assign o=reg_o;
endmodule |