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.

75 lines
1.7 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. //
  2. // @功能:
  3. // 1. 滤波(add later)
  4. // 2. 频率探测
  5. // 3. 输出灯光控制
  6. //
  7. module zutils_freq_detector
  8. (
  9. input clk, //! 时钟输入
  10. input rst_n, //! 复位输入
  11. input pluse_input, //! 输入信号1
  12. //处理后的信号输出
  13. output reg [31:0]pluse_width_cnt //! 输出捕获到的脉冲宽度
  14. );
  15. reg in_signal_last;
  16. reg in_signal_rising_edge; //! 上升沿
  17. //!in_signal_last 捕获
  18. always @(posedge clk or negedge rst_n) begin
  19. if (!rst_n) begin
  20. in_signal_last <= 0;
  21. end
  22. else begin
  23. in_signal_last <= pluse_input;
  24. end
  25. end
  26. //!边沿捕获
  27. always @(posedge clk or negedge rst_n) begin
  28. if (!rst_n) begin
  29. in_signal_rising_edge <= 0;
  30. end
  31. else begin
  32. if (in_signal_last == 0 && pluse_input == 1) begin
  33. in_signal_rising_edge <= 1;
  34. end
  35. else if (in_signal_last == 1 && pluse_input == 0) begin
  36. in_signal_rising_edge <= 0;
  37. end
  38. else begin
  39. in_signal_rising_edge <= 0;
  40. end
  41. end
  42. end
  43. // 计数器
  44. reg [31:0] pluse_width_cnt_reg;
  45. //!脉冲宽度计数
  46. always @(posedge clk or negedge rst_n) begin
  47. if (!rst_n) begin
  48. pluse_width_cnt_reg <= 0;
  49. pluse_width_cnt <= 32'hffff_ffff;
  50. end
  51. else begin
  52. if (in_signal_rising_edge) begin
  53. pluse_width_cnt <= pluse_width_cnt_reg;
  54. pluse_width_cnt_reg <= 0;
  55. end
  56. else begin
  57. pluse_width_cnt_reg <= pluse_width_cnt_reg + 1;
  58. if(pluse_width_cnt_reg >= 32'd11000000) begin //TODO:支持可配置
  59. pluse_width_cnt <= 32'hffff_ffff;
  60. pluse_width_cnt_reg <= 0;
  61. end
  62. end
  63. end
  64. end
  65. endmodule