1
我想測量信號上升轉換和下降轉換的次數。我使用信號作爲時鐘並實現了2個計數器。一個計數器在每個上升沿遞增,另一個在每個下降沿遞增。我將這兩個計數器的結果相加以得到最終計數值。如何編寫可計算信號上升和下降的可綜合RTL
有沒有更好的方法來實現這個邏輯?什麼是最健壯的方法?
module clock_edge_counter (
clock_edge_count, // Output of the counter ,
clk , // clock Input
stop ,
reset
);
parameter CNTR_WIDTH = 16;
input clk ;
input stop ;
input reset ;
output [CNTR_WIDTH:0] clock_edge_count;
wire [CNTR_WIDTH:0] clock_edge_count;
reg [CNTR_WIDTH-1:0] clock_negedge_edge_count;
reg [CNTR_WIDTH-1:0] clock_posedge_edge_count;
always @(posedge clk or posedge reset)
if (reset) begin
clock_posedge_edge_count <= 0;
end
else if (!stop) begin
clock_posedge_edge_count <= clock_posedge_edge_count + 1;
end
always @(negedge clk or posedge reset)
if (reset) begin
clock_negedge_edge_count <= 0;
end
else if (!stop) begin
clock_negedge_edge_count <= clock_negedge_edge_count + 1;
end
assign clock_edge_count = clock_negedge_edge_count + clock_posedge_edge_count;
endmodule
感謝Rahul的解釋。 –
歡迎您:) –