我想熟悉FPGA开发,因此尝试将基于FPGA的脉冲计数器作为第一个项目来实现,该计数器简单地计数所有输入脉冲(例如,仅上升沿),并通过GPIO / AXI接口对其进行访问,如一个32位整数。
我尝试结合以下两个示例:
我以秒表项目为基础并对其进行了调整,以使二进制计数器不会由125Mhz FPGA时钟馈入,而是由输入脉冲馈入(该部分来自频率计数器项目)。 我还更改了FrequencyCounter的Verilog代码,它仅创建一个1位的高/低信号,因此可以驱动二进制计数器:
scrollToElement($element): void {
console.log($element);
$element.scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"});
}
它确实可以某种方式工作,但不能正常运行:
如果我在IN1输入上发送脉冲,则计数器值(0x48000008)会增加,但是会太快(我使用1Hz信号,计数器会快约1000倍):
module frequency_counter #
(
parameter ADC_WIDTH = 14,
parameter AXIS_TDATA_WIDTH = 32,
parameter COUNT_WIDTH = 32,
parameter HIGH_THRESHOLD = -100,
parameter LOW_THRESHOLD = -150
)
(
(* X_INTERFACE_PARAMETER = "FREQ_HZ 125000000" *)
input [AXIS_TDATA_WIDTH-1:0] S_AXIS_IN_tdata,
input S_AXIS_IN_tvalid,
input clk,
input rst,
input [COUNT_WIDTH-1:0] Ncycles,
output [AXIS_TDATA_WIDTH-1:0] M_AXIS_OUT_tdata,
output M_AXIS_OUT_tvalid,
output [0:0] counter_output
);
wire signed [ADC_WIDTH-1:0] data;
reg state, state_next;
reg [COUNT_WIDTH-1:0] counter=0, counter_next=0;
reg [COUNT_WIDTH-1:0] counter_output_next=0;
reg [0:0] counter_output=0;
reg [COUNT_WIDTH-1:0] cycle=0, cycle_next=0;
// Wire AXIS IN to AXIS OUT
assign M_AXIS_OUT_tdata[ADC_WIDTH-1:0] = S_AXIS_IN_tdata[ADC_WIDTH-1:0];
assign M_AXIS_OUT_tvalid = S_AXIS_IN_tvalid;
// Extract only the 14-bits of ADC data
assign data = S_AXIS_IN_tdata[ADC_WIDTH-1:0];
// Handling of the state buffer for finding signal transition at the threshold
always @(posedge clk)
begin
if (~rst)
state <= 1'b0;
else
state <= state_next;
end
always @* // logic for state buffer
begin
if (data > HIGH_THRESHOLD)
counter_output = 1;
else if (data < LOW_THRESHOLD)
counter_output = 0;
else
state_next = state;
end
endmodule
这是方块设计:
有人可以帮助我,我怎样才能使它工作?