noob_circuit

Exams/2014 qfsm

Aug 6th, 2025
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. module top_module (
  2. input clk,
  3. input reset, // Synchronous reset
  4. input s,
  5. input w,
  6. output z
  7. );
  8. parameter A=1'd0, B=1'd1;
  9.  
  10. reg [1:0] w_count, cycle_count;
  11. reg [3:0] current_state, next_state;
  12.  
  13. // next state logic
  14. always @(*) begin
  15. case (current_state)
  16. A : next_state = s ? B : A;
  17. B : next_state = B;
  18. endcase
  19. end
  20.  
  21. // current state logic
  22. always @(posedge clk) begin
  23. if (reset) begin
  24. current_state <= A;
  25. end else begin
  26. current_state <= next_state;
  27. end
  28. end
  29.  
  30. // tracks w frequency and clock cycle
  31. always @(posedge clk) begin
  32. if (reset) begin
  33. cycle_count <= 1'd0;
  34. w_count <= 1'd0;
  35. end else begin
  36. if (current_state == B) begin
  37. if (cycle_count == 2'd3) begin
  38. cycle_count <= 1'd0;
  39. w_count <= 1'd0;
  40. end else begin
  41. cycle_count <= cycle_count + 1'd1;
  42. w_count <= w_count + w;
  43. end
  44. end
  45. end
  46. end
  47.  
  48. assign z = (cycle_count == 2'd3) * (w_count == 2'd2);
  49. endmodule
  50.  
Advertisement
Add Comment
Please, Sign In to add comment