//米勒机 //状态复位 always@(posedge clk orposedge reset) begin if(reset) pre_state_mealy <= a; else pre_state_mealy <= next_state_mealy; end
//状态转移过程 always@(pre_state_mealy or indata) begin case (pre_state_mealy) a: begin if (indata == 1) next_state_mealy <= a; else next_state_mealy <= b; end b: begin if (indata == 1) next_state_mealy <= a; else next_state_mealy <= c; end c: begin if (indata == 1) next_state_mealy <= a; else next_state_mealy <= d; end d: begin next_state_mealy <= a; end default: next_state_mealy <= a; endcase end
//状态输入映射输出(此时输入输出不隔离) always@(pre_state_mealy or indata) begin case (pre_state_mealy) a: begin if(indata == 1) outdata_mealy <= 2'b00; else outdata_mealy <= 2'b01; end b: begin if(indata == 1) outdata_mealy <= 2'b00; else outdata_mealy <= 2'b10; end c: begin if(indata == 1) outdata_mealy <= 2'b00; else outdata_mealy <= 2'b11; end d: begin outdata_mealy <= 2'b00; end default: outdata_mealy <= 2'b00; endcase end
//摩尔机 always@(posedge clk orposedge reset) begin if(reset == 1) pre_state_moore <= a; else pre_state_moore <= next_state_moore; end
always@(pre_state_moore or indata) begin case (pre_state_moore) a: begin if (indata == 1) next_state_moore <= a; else next_state_moore <= b; end b: begin if (indata == 1) next_state_moore <= a; else next_state_moore <= c; end c: begin if (indata == 1) next_state_moore <= a; else next_state_moore <= d; end d: begin next_state_moore <= a; end default: next_state_moore <= a; endcase end always@(pre_state_moore) begin case (pre_state_moore) a: begin if(indata == 1) outdata_moore <= 2'b00; else outdata_moore <= 2'b01; end b: begin if(indata == 1) outdata_moore <= 2'b00; else outdata_moore <= 2'b10; end c: begin if(indata == 1) outdata_moore <= 2'b00; else outdata_moore <= 2'b11; end d: begin outdata_moore <= 2'b00; end default: outdata_moore <= 2'b00; endcase end