在做工作之前等待 posege clk? - 如何
module DoorControl( clk, data, open,addressOftheMemory, outp );
localparam Size_ofTheWord = 32;
input open;
input [16:0] addressOftheMemory;
input [Size_ofTheWord-1:0] data;
input clk ;
output reg outp;
reg [WordSize-1: 0] Memory [65535: 0];
always @ ( open ) // open is 1 or 0
if ( open )
// i
outp = Memory[addressOftheMemory];
else if ( !open )
Memory[addressOftheMemory] = data;
endmodule
标有 (i) 的行,我想在将 outp 发送到输出端口之前等待 posege clk。但是,当我尝试像 ;
if ( posedge clk )
它给出错误,
while ( clk != 1 ) begin
end
它给出绝对答案/模拟输出。 在发送输出之前,我应该在该线上放置什么东西来等待 posege clk ?
module DoorControl( clk, data, open,addressOftheMemory, outp );
localparam Size_ofTheWord = 32;
input open;
input [16:0] addressOftheMemory;
input [Size_ofTheWord-1:0] data;
input clk ;
output reg outp;
reg [WordSize-1: 0] Memory [65535: 0];
always @ ( open ) // open is 1 or 0
if ( open )
// i
outp = Memory[addressOftheMemory];
else if ( !open )
Memory[addressOftheMemory] = data;
endmodule
Line marked with (i), I want wait just posedge clk before sending outp to output port.However, When I have tried like ;
if ( posedge clk )
it gives error
while ( clk != 1 ) begin
end
it gives absurb answer/simulation output.
What thing(s) should I put to that line to wait posedge clk before sending output ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你必须更加批判性地思考你想要建模的内容。看起来您只是想用“打开”控制读/写操作来建模内存。
您可以异步写入数据和数据。同步读取数据。对于内存访问,最好具有完整的同步行为。
You have to think a little more critically about what you are trying to model. It looks like you are just trying to model a memory with "open" controlling the read/write operation.
You have asynchronous writing of data & synchronous reading of data. For memory access it is better just to have complete synchronous behavior.
您可以将执行延迟到时钟边缘,如下所示:
这可能会也可能不会实现您想要的效果。它不可合成,并且
always
块在执行或挂起时不会被重新调度,因此如果open
在一个时钟周期内多次切换,该代码可能不会去做你想做的事。更多背景:您可以在任何语句上指定延迟/事件控制,包括空语句。 (例如,在@(posege clk);中,分号是空语句。)事实上,
always
构造的语法定义是:这意味着
always @(open)
或always @(posedge clk)
并没有什么神奇之处,它们只是引入了一个语句并指定事件控制。当延迟控制 (#
) 附加到语句时,该语句的执行将推迟到将来的固定时间。当事件控制 (@
) 附加到语句时,该语句的执行将推迟到满足事件条件为止。You can delay execution until the clock edge like this:
That may or may not accomplish what you want. It is not synthesizable, and the
always
block will not be rescheduled while it is executing or suspended, so ifopen
toggles multiple times in a clock period, that code is probably not going to do what you want.More background: you can specify a delay/event control on any statement, including a null statement. (e.g. in
@(posedge clk);
, the semicolon is a null statement.) In fact, the syntax definition of analways
construct is:Meaning that there is nothing magical about
always @(open)
oralways @(posedge clk)
, they are simply introducing a statement and specifying event control. When delay control (#
) is attached to a statement, execution of the statement is deferred until a fixed time in the future. When event control (@
) is attached to a statement, execution of the statement is deferred until the event condition is satisfied.