当前位置:   article > 正文

Circuits--Sequential--FSM-Q3b~Q3c

Circuits--Sequential--FSM-Q3b~Q3c

1. q3b

  1. module top_module (
  2. input clk,
  3. input reset, // Synchronous reset
  4. input x,
  5. output z
  6. );
  7. parameter s0 = 3'b000;
  8. parameter s1 = 3'b001;
  9. parameter s2 = 3'b010;
  10. parameter s3 = 3'b011;
  11. parameter s4 = 3'b100;
  12. reg[2:0] state;
  13. reg[2:0] next_state;
  14. always@(*)
  15. begin
  16. case(state)
  17. s0:
  18. begin
  19. if(x) next_state = s1;
  20. else next_state = s0;
  21. end
  22. s1:
  23. begin
  24. if(x) next_state = s4;
  25. else next_state = s1;
  26. end
  27. s2:
  28. begin
  29. if(x) next_state = s1;
  30. else next_state = s2;
  31. end
  32. s3:
  33. begin
  34. if(x) next_state = s2;
  35. else next_state = s1;
  36. end
  37. s4:
  38. begin
  39. if(x) next_state = s4;
  40. else next_state = s3;
  41. end
  42. endcase
  43. end
  44. always@(posedge clk)
  45. begin
  46. if(reset)
  47. state <= s0;
  48. else
  49. state <= next_state;
  50. end
  51. assign z = (state == s3 || state == s4);
  52. endmodule

2. q3c

直接组合逻辑

  1. module top_module (
  2. input clk,
  3. input [2:0] y,
  4. input x,
  5. output z,
  6. output Y0
  7. );
  8. assign z = ((y == 3'b011)||(y == 3'b100));
  9. assign Y0 = ((~y[2]&y[0])|(y==3'b100))&~x | (~y[2]&~y[0])&x;
  10. endmodule

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/640219
推荐阅读
相关标签
  

闽ICP备14008679号