当前位置:   article > 正文

Circuits--Sequential--Finite4

Circuits--Sequential--Finite4

1. Simple  FSM3 asy

  1. module top_module(
  2. input clk,
  3. input in,
  4. input areset,
  5. output out); //
  6. parameter A=2'd0;
  7. parameter B=2'd1;
  8. parameter C=2'd2;
  9. parameter D=2'd3;
  10. reg[1:0] state;
  11. reg[1:0] next_state;
  12. // State transition logic
  13. always@(*)
  14. begin
  15. case(state)
  16. A:
  17. begin
  18. if(in==0) next_state = A;
  19. else next_state = B;
  20. end
  21. B:
  22. begin
  23. if(in==0) next_state = C;
  24. else next_state = B;
  25. end
  26. C:
  27. begin
  28. if(in==0) next_state = A;
  29. else next_state = D;
  30. end
  31. D:
  32. begin
  33. if(in==0) next_state = C;
  34. else next_state = B;
  35. end
  36. endcase
  37. end
  38. // State flip-flops with asynchronous reset
  39. always@(posedge clk or posedge areset)
  40. begin
  41. if(areset)
  42. state = A;
  43. else
  44. state = next_state;
  45. end
  46. // Output logic
  47. assign out = (state == D);
  48. endmodule

2. Simple FSM3 sy

  1. module top_module(
  2. input clk,
  3. input in,
  4. input reset,
  5. output out); //
  6. parameter A=2'd0;
  7. parameter B=2'd1;
  8. parameter C=2'd2;
  9. parameter D=2'd3;
  10. reg[1:0] state;
  11. reg[1:0] next_state;
  12. // State transition logic
  13. always@(*)
  14. begin
  15. case(state)
  16. A:
  17. begin
  18. if(in==0) next_state = A;
  19. else next_state = B;
  20. end
  21. B:
  22. begin
  23. if(in==0) next_state = C;
  24. else next_state = B;
  25. end
  26. C:
  27. begin
  28. if(in==0) next_state = A;
  29. else next_state = D;
  30. end
  31. D:
  32. begin
  33. if(in==0) next_state = C;
  34. else next_state = B;
  35. end
  36. endcase
  37. end
  38. // State flip-flops with asynchronous reset
  39. always@(posedge clk )
  40. begin
  41. if(reset)
  42. state = A;
  43. else
  44. state = next_state;
  45. end
  46. // Output logic
  47. assign out = (state == D);
  48. endmodule

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/502735
推荐阅读
相关标签
  

闽ICP备14008679号