• [HDLBits] Exams/2013 q2afsm


    Consider the FSM described by the state diagram shown below:

    Exams 2013q2.png

    This FSM acts as an arbiter circuit, which controls access to some type of resource by three requesting devices. Each device makes its request for the resource by setting a signal r[i] = 1, where r[i] is either r[1]r[2], or r[3]. Each r[i] is an input signal to the FSM, and represents one of the three devices. The FSM stays in state A as long as there are no requests. When one or more request occurs, then the FSM decides which device receives a grant to use the resource and changes to a state that sets that device’s g[i] signal to 1. Each g[i] is an output from the FSM. There is a priority system, in that device 1 has a higher priority than device 2, and device 3 has the lowest priority. Hence, for example, device 3 will only receive a grant if it is the only device making a request when the FSM is in state A. Once a device, i, is given a grant by the FSM, that device continues to receive the grant as long as its request, r[i] = 1.

    Write complete Verilog code that represents this FSM. Use separate always blocks for the state table and the state flip-flops, as done in lectures. Describe the FSM outputs, g[i], using either continuous assignment statement(s) or an always block (at your discretion). Assign any state codes that you wish to use.

    1. module top_module (
    2. input clk,
    3. input resetn, // active-low synchronous reset
    4. input [3:1] r, // request
    5. output [3:1] g // grant
    6. );
    7. parameter free=0,e1=1,e2=2,e3=3;
    8. reg [1:0] state,next;
    9. always@(*) begin
    10. case(state)
    11. free:begin
    12. if(r==3'b000)
    13. next<=free;
    14. else if(r[1])
    15. next<=e1;
    16. else if(r[2])
    17. next<=e2;
    18. else
    19. next<=e3;
    20. end
    21. e1:begin
    22. if(r[1])
    23. next<=e1;
    24. else
    25. next<=free;
    26. end
    27. e2:begin
    28. if(r[2])
    29. next<=e2;
    30. else
    31. next<=free;
    32. end
    33. e3:begin
    34. if(r[3])
    35. next<=e3;
    36. else
    37. next<=free;
    38. end
    39. endcase
    40. end
    41. always@(posedge clk) begin
    42. if(!resetn)
    43. state<=free;
    44. else
    45. state<=next;
    46. end
    47. assign g[1]=state==e1;
    48. assign g[2]=state==e2;
    49. assign g[3]=state==e3;
    50. endmodule

     

  • 相关阅读:
    2019 ICPC香港站 G. Game Design
    sqlite数据库乱码
    Ubuntu安装hwe内核解决硬件太新的问题
    【名词从句的练习题】名词从句的虚拟
    赋能新一代物联网的LoRaWAN技术
    xxx.ko 驱动模块加载报错 “unknown symbol in module or invalid parameter”
    Redis中的Hash设计和节省内存数据结构设计
    基于CSP的运动想象EEG分类任务实战
    python:OderedDict函数
    如约而至 拼多多发布2022“众声创作者计划”冬日书单
  • 原文地址:https://blog.csdn.net/m0_66480474/article/details/133866312