当前位置:   article > 正文

Circuits--Sequence --FSM--q8~q5a

Circuits--Sequence --FSM--q8~q5a

1. q8

  1. module top_module (
  2. input clk,
  3. input aresetn, // Asynchronous active-low reset
  4. input x,
  5. output z );
  6. parameter s0 = 2'd0;
  7. parameter s1 = 2'd1;
  8. parameter s2 = 2'd2;
  9. reg[1:0] state;
  10. reg[1:0] next_state;
  11. always@(*)
  12. begin
  13. case(state)
  14. s0:
  15. begin
  16. if(x) next_state = s1;
  17. else next_state = s0;
  18. end
  19. s1:
  20. begin
  21. if(x) next_state = s1;
  22. else next_state = s2;
  23. end
  24. s2:
  25. begin
  26. if(x) next_state = s1;
  27. else next_state = s0;
  28. end
  29. endcase
  30. end
  31. always@(posedge clk or negedge aresetn)
  32. begin
  33. if(~aresetn)
  34. state <= s0;
  35. else
  36. state <= next_state;
  37. end
  38. assign z = (state == s2) ? x : 1'b0;
  39. endmodule

2. q5a

  1. module top_module (
  2. input clk,
  3. input areset,
  4. input x,
  5. output z
  6. );
  7. parameter s0 = 2'd0;
  8. parameter s1 = 2'd1;
  9. parameter s2 = 2'd2;
  10. reg[1:0] state;
  11. reg[1:0] next_state;
  12. always@(*)
  13. begin
  14. case(state)
  15. s0:
  16. if(x) next_state = s1;
  17. else next_state = s0;
  18. s1:
  19. if(x) next_state = s2;
  20. else next_state = s1;
  21. s2:
  22. if(x) next_state = s2;
  23. else next_state = s1;
  24. endcase
  25. end
  26. always@(posedge clk or posedge areset)
  27. begin
  28. if(areset)
  29. state <= s0;
  30. else
  31. state <= next_state;
  32. end
  33. assign z = (state == s1);
  34. endmodule

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

闽ICP备14008679号