FPGA没有双边缘触发触发器,@(posedge clk或negedge clk)会报错
“FPGA(以及其他任何地方)上的触发器是一个具有一个时钟且仅对该时钟的一个边缘敏感的器件。”参考verilog为什么不能双边沿触发
实现双边沿的两种方法
module top_module (
input clk,
input d,
output q
);
reg a,b;
always@(posedge clk)
begin
a <= d;
end
always@(negedge clk)
begin
b <= d;
end
assign q = clk?a:b;
endmodule
HDLbits官方答案
module top_module(
input clk,
input d,
output q);
reg p, n;
// A positive-edge triggered flip-flop
always @(posedge clk)
p <= d ^ n;
// A negative-edge triggered flip-flop
always @(negedge clk)
n <= d ^ p;
// Why does this w