我正在尝试编写一个verilog代码,它将在输入信号的正边沿和负边沿触发(我称之为'async')。我想要的输出是异步的每个边缘上的短暂光点(与异步频率相比),它从边缘('t1'和't3')稍微延迟并且其持续时间可以被控制('t2'和' T4' )。评论说我认为我的代码正在做什么,但我是Verilog的新手,并没有真正了解任何事情。任何帮助表示赞赏。
这是我的完整代码:
`timescale 1ns / 1ps
module attempt5(async, clk, o);
input async;
input clk;
reg switch = 1'b0; //will tell me when async changes
reg [1:3] resync = 3'b000;
reg counter = 1'b0; //keeping track of which edge of async we're on
output reg o = 1'b0;
parameter t1 = 0;
parameter t2 = 100000000;
parameter t3 = 0;
parameter t4 = 100000000;
always @ (posedge clk)
begin
switch <= resync[2] & !resync[3];
switch <= resync[3] & !resync[2];
resync <= {async, resync[1:2]};
end
//^^I'm pretty sure this makes the 'switch' register switch very quickly when 'async' changes
//I've included this always block because I wanted to sync my input signal to the clock, because I read that FPGAs don't do well with asynchronous stuff
always @ (posedge switch)
if (counter == 1) begin
counter = 0;
#t1 o <= ~o;
#t2 o <= ~o;
end else begin
counter = 1;
#t3 o <= ~o;
#t4 o <= ~o;
end
//^^ When the 'switch' register changes, start the the short blip
endmodule
我的约束文件:
NET "clk" TNM_NET = "clk";
TIMESPEC TS_clk = PERIOD "clk" 20 ns HIGH 50 %;
NET "switch" TNM_NET = "switch";
TIMESPEC TS_switch = PERIOD "switch" TS_clk HIGH 50 %;
NET "async" LOC = A2;
NET "o" LOC = C1;
INST "clk_BUFGP" LOC = F1;
NET "clk" LOC = F1;
NET "o" SLEW = FAST;
代码在合成器中工作,但是当我尝试使用1 Hz方波测试“异步”信号并使用示波器监视“o”时,没有任何反应。
其他细节: 使用Xilinx XEM 6001 FPGA和ISE Design Suite 14.4 我测试的方法是将函数发生器连接到引脚A2,将示波器连接到引脚C1,我看到的只是噪声。这里有没有明显的问题,也许是因为我实际上并没有正确连接到物理引脚或其他东西?
答案 0 :(得分:1)
您对switch
的第二次转让会覆盖第一项转让。这是一个永远阻止的本质...
您的意图是为两个边创建一个边缘检测器,因此您需要“或”#39;上升和下降边缘方程。
switch <= (resync[2] & !resync[3]) | (resync[3] & !resync[2]);
或者你使用apropiate布尔运算符xor
(又名不等)。
switch <= resync[2] ^ resync[3];