HDLbits Exams/2013 q2bfsm

Consider a finite state machine that is used to control some type of motor. The FSM has inputs x and y, which come from the motor, and produces outputs f and g, which control the motor. There is also a clock input called clk and a reset input called resetn.

The FSM has to work as follows. As long as the reset input is asserted, the FSM stays in a beginning state, called state A. When the reset signal is de-asserted, then after the next clock edge the FSM has to set the output f to 1 for one clock cycle. Then, the FSM has to monitor the x input. When x has produced the values 1, 0, 1 in three successive clock cycles, then g should be set to 1 on the following clock cycle. While maintaining g = 1 the FSM has to monitor the y input. If y has the value 1 within at most two clock cycles, then the FSM should maintain g = 1 permanently (that is, until reset). But if y does not become 1 within two clock cycles, then the FSM should set g = 0 permanently (until reset).

考虑一个用于控制某种电机的有限状态机。 FSM 有输入 x 和 y 来自电机,并产生输出 f 和 g 来控制电机。 还有一个称为 clk 的复位输入 resetn 。

FSM 必须按如下方式工作。 只要复位输入被置位,FSM 就停留在 开始状态,称为状态 A 。 当复位信号被置低时,则在下一个时钟之后 边沿 FSM 必须将输出 f 为 1 持续一个时钟周期。 然后 ,FSM 必须监控 x 输入。 当 x 在三个连续的时钟周期中产生值 1、0、1 时, g 应该 在下一个时钟周期设置为 1。 在保持 g = 1 的同时,FSM 必须监控 y 输入。 如果 y 在最多两个时钟周期内为 1,则 FSM 应保持 g = 1 永久(即,直到重置)。 但是如果 y 在两个时钟周期内没有变为 1,那么 FSM 应永久设置 g = 0(直到复位)。

这道题的关键在于理解题意,并画出状态转移图,就很容易实现了。


状态转移图:

x=1
x=0
x=0
x=1
x=1
x=0
y=0
y=1
y=0
y=1
areset
A
F/f=1
B
C
D
E/g=1
G/g=1
H/g=1
I

实现:

module top_module (
    input clk,
    input resetn,    // active-low synchronous reset
    input x,
    input y,
    output f,
    output g
); 
    
    parameter A=4'd0,B=4'd1,C=4'd2,D=4'd3,E=4'd4,F=4'd5,G=4'd6,H=4'd7,I=4'd8;
    reg [3:0] state,next_state;
    
    always@(posedge clk)begin
        if(!resetn)
            state<=A;
        else
            state<=next_state;
    end
    
    always@(*)begin
        case(state)
            A:next_state=F;
            F:next_state=B;
            B:next_state=x?C:B;
            C:next_state=x?C:D;
            D:next_state=x?E:B;
            E:next_state=y?H:G;
            G:next_state=y?H:I;
            H:next_state=H;
            I:next_state=I;
            default:next_state=B;
        endcase
    end
    
    
    assign f=(state == F);
    assign g=(state == E || state == H  || state == G);
    
endmodule

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值