【问题标题】:Finite State Machine Verilog 4 num sequence有限状态机 Verilog 4 num 序列
【发布时间】:2014-05-19 04:05:24
【问题描述】:

好的,所以我知道我的代码适用于 3 数序列,但对于我绘制的有限状态机模型,这应该是正确的,但它不适用于 4 数序列。它只检测前 3 个。我需要检测序列 01100110110111 中的重叠“0110”。它应该有 3 个“0110”序列和 2 个重叠,但是当我运行 Verilog 时,它检测到 4 个“0110”序列告诉我它是只抓“011” 有人可以看看我的代码,看看我做错了什么吗?我可以简单地添加另一个状态,但我认为这不是正确的方法,因为我的图表中没有另一个状态。

module moore_seq
(
        input clock, reset, x,
        output reg z
);

//assign binary encoded codes to the states A through D
parameter       A = 2'b00,
                B = 2'b01,
                C = 2'b10,
                D = 2'b11;

reg [1:0] current_state, next_state;

//Section 1: Next state generator (NSG)
always@(*)
begin
        casex(current_state) //ignore unknown and Hi-Z inputs
        A:      if (x == 1)
                        next_state = A;
                else
                        next_state = B;
        B:      if (x == 1)
                        next_state = C;
                else
                        next_state = B;
        C:      if (x == 1)
                        next_state = D;
                else
                        next_state = B;
        D:      if (x == 1)
                        next_state = A;
                else
                        next_state = B;
        endcase
end
//Section 2: Output Generator (OG)
always@(*)
begin
        if(current_state == D)
                z = 1;
        else
                z = 0;
end

//Section 3: The Flip Flops
always@(posedge clock, posedge reset)
begin
        if(reset == 1)
                current_state <= A;
        else
                current_state <= next_state;
end
endmodule

更新:

parameter       A = 3'b000,
                B = 3'b001,
                C = 3'b010,
                D = 3'b011,
                E = 3'b100;

reg [1:0] current_state, next_state;

//Section 1: Next state generator (NSG)
always@(*)
begin
        casex(current_state) //ignore unknown and Hi-Z inputs
        A:      if (x == 1)
                        next_state = A;
                else
                        next_state = B;
        B:      if (x == 1)
                        next_state = C;
                else
                        next_state = B;
        C:      if (x == 1)
                        next_state = D;
                else   
                        next_state = B;
        D:      if (x == 1)
                        next_state = A;
                else
                        next_state = E;
        E:      if (x == 1)
                        next_state = C;
                else
                        next_state = B;
        endcase
end

//Section 2: Output Generator (OG)
always@(*)
begin
        if(current_state == E)
                z = 1;
        else
                z = 0;
end

【问题讨论】:

  • 你必须需要更多的状态,因为你在 3 次输入后达到了D(导致A-&gt;BB-&gt;CC-&gt;D)。
  • 是这样想的,我的图表没有其他状态所以我没有把它放进去。我不确定我是否知道如何在参数下添加另一个状态。会不会像 E = 2'b111; ?
  • 您的状态变量需要更多位(代码中未显示声明),并且您的状态常量也必须是 3 位宽(即3'b...)。
  • 更新了我的代码,但现在它不会检测到任何正确为 z = 1 的“0110”。
  • 您的状态变量需要更多位reg [1:0] 中不适合 3 位

标签: verilog hdl fsm state-machine


【解决方案1】:

我想,四个状态就足够了。换个方式

//Section 2: Output Generator (OG)
always@(*)
begin
    if(current_state == D)

//Section 2: Output Generator (OG)
always@(*)
begin
    if(current_state == D && x == 0 )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-16
    • 2021-08-08
    • 2015-10-14
    • 2016-08-27
    • 1970-01-01
    • 2019-02-12
    • 2018-10-07
    • 1970-01-01
    相关资源
    最近更新 更多