You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.9 KiB

1 year ago
  1. module zutils_trigger_sig_gen (
  2. input clk, //clock input
  3. input rst_n, //asynchronous reset input, low active
  4. input start_sig,
  5. input stop_sig,
  6. input [31:0] cfg_freq_cnt,
  7. input [31:0] cfg_pluse_cnt,
  8. output reg output_signal
  9. );
  10. reg [31:0] cfg_freq_cnt_cache;
  11. reg [31:0] cfg_pluse_cnt_cache;
  12. reg work_state;
  13. reg [31:0] freq_cnt;
  14. reg [31:0] pluse_cnt;
  15. reg first_start;
  16. always @(posedge clk or negedge rst_n) begin
  17. if (!rst_n) begin
  18. cfg_freq_cnt_cache <= 0;
  19. cfg_pluse_cnt_cache <= 0;
  20. work_state <= 0;
  21. work_state <= 0;
  22. freq_cnt <= 0;
  23. pluse_cnt <= 0;
  24. output_signal <= 0;
  25. first_start <= 1;
  26. end else begin
  27. case (work_state)
  28. 0: begin
  29. if (start_sig || first_start) begin
  30. work_state <= 1;
  31. cfg_freq_cnt_cache <= cfg_freq_cnt;
  32. cfg_pluse_cnt_cache <= cfg_pluse_cnt_cache;
  33. freq_cnt <= 0;
  34. pluse_cnt <= 0;
  35. output_signal <= 0;
  36. first_start <= 0;
  37. end else begin
  38. output_signal <= 0;
  39. end
  40. end
  41. 1: begin
  42. if (!stop_sig) begin
  43. if (freq_cnt >= cfg_freq_cnt_cache) begin
  44. freq_cnt <= 0;
  45. output_signal <= 1;
  46. if (cfg_pluse_cnt_cache != 0) begin
  47. if (pluse_cnt == cfg_pluse_cnt_cache - 1) begin
  48. work_state <= 0;
  49. end else begin
  50. pluse_cnt <= pluse_cnt + 1;
  51. end
  52. end
  53. end else begin
  54. freq_cnt <= freq_cnt + 1;
  55. output_signal <= 0;
  56. end
  57. end else begin
  58. work_state <= 0;
  59. end
  60. end
  61. default: work_state <= 0;
  62. endcase
  63. end
  64. end
  65. endmodule