Verilog 如何创建正面边缘检测器行为代码?
我目前正在尝试编写一个正边缘检测器,它在每次检测到正边缘时都会更改其输出。我成功地用门级建模构建了一个,但现在我需要使用行为建模来构建它。我试着用这个地基建造它:Verilog 如何创建正面边缘检测器行为代码?,verilog,Verilog,我目前正在尝试编写一个正边缘检测器,它在每次检测到正边缘时都会更改其输出。我成功地用门级建模构建了一个,但现在我需要使用行为建模来构建它。我试着用这个地基建造它: module pos_edge_det ( input sig, input clk, output pe); reg sig_dly;
module pos_edge_det ( input sig,
input clk,
output pe);
reg sig_dly;
always @ (posedge clk) begin
sig_dly <= sig;
end
assign pe = sig & ~sig_dly;
endmodule
模块位置边缘检测(输入信号,
输入时钟,
输出功率(pe);
注册标志;
始终@(posedge clk)开始
明显地该错误意味着当您在始终
块中分配给导线时,不能将输出
声明为导线
。您需要将out
声明为reg
。我将您的模块发布在上,并在多个模拟器上编译,其中一个模拟器产生了更具体的错误消息:
out在此声明为wire
至少这会提示您使用wire
有问题
这一行还有一个问题:
always @ (posedge in, posedge clk)
这不会合成为触发器
我想您正在寻找一个模块,它将检测到sig
上的posedge,并生成一个输出pe
,这将是一个单一的时钟宽度脉冲,还将生成一个输出out
,每次看到sig
上的posedge时都会切换。我假设你的res
信号是复位。我还包括一个简单的测试台
module pos_edge_det (
input sig,
input clk,
input res,
output pe,
output reg out
);
reg sig_dly;
always @ (posedge clk or posedge res) begin
if (res) begin
sig_dly <= 0;
end else begin
sig_dly <= sig;
end
end
assign pe = sig & ~sig_dly;
always @ (posedge clk or posedge res) begin
if (res) begin
out <= 0;
end else if (pe) begin
out <= ~out;
end
end
endmodule
module tb;
reg clk, res, sig;
wire pe, out;
initial begin
clk = 0;
forever #5 clk =~clk;
end
pos_edge_det dut (
// Inputs:
.clk (clk),
.res (res),
.sig (sig),
// Outputs:
.out (out),
.pe (pe)
);
initial begin
sig = 0;
res = 1;
#20 res = 0;
repeat (10) #30 sig = ~sig;
#5 $finish;
end
endmodule
模块位置边缘检测(
输入信号,
输入时钟,
输入res,
输出pe,
输出寄存器输出
);
注册标志;
始终@(posedge clk或posedge res)开始
如果(res)开始
信号out
是一条wire
。您不能从始终
块驱动导线
。这就是为什么会出现错误。
module pos_edge_det (
input sig,
input clk,
input res,
output pe,
output reg out
);
reg sig_dly;
always @ (posedge clk or posedge res) begin
if (res) begin
sig_dly <= 0;
end else begin
sig_dly <= sig;
end
end
assign pe = sig & ~sig_dly;
always @ (posedge clk or posedge res) begin
if (res) begin
out <= 0;
end else if (pe) begin
out <= ~out;
end
end
endmodule
module tb;
reg clk, res, sig;
wire pe, out;
initial begin
clk = 0;
forever #5 clk =~clk;
end
pos_edge_det dut (
// Inputs:
.clk (clk),
.res (res),
.sig (sig),
// Outputs:
.out (out),
.pe (pe)
);
initial begin
sig = 0;
res = 1;
#20 res = 0;
repeat (10) #30 sig = ~sig;
#5 $finish;
end
endmodule