• [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

     

  • 相关阅读:
    使用Docker搭建Weblogic服务
    你真的懂反馈吗?
    我也差点“跑路”
    神经网络简介
    本地JS文件批量压缩
    机器人自适应控制
    《Go语言精进之路,从新手到高手的编程思想、方法和技巧1》读书笔记和分享
    //快速排序的非递归版本
    C# 语言的面向对象技术
    工业交换机为什么有必要进行老化测试?
  • 原文地址:https://blog.csdn.net/m0_66480474/article/details/133866312