在做工作之前等待 posege clk? - 如何

发布于 2024-11-04 16:06:08 字数 717 浏览 7 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

染墨丶若流云 2024-11-11 16:06:08

你必须更加批判性地思考你想要建模的内容。看起来您只是想用“打开”控制读/写操作来建模内存。

您可以异步写入数据和数据。同步读取数据。对于内存访问,最好具有完整的同步行为。

always @(posedge clk) begin
if( open )
    outp = Memory[addressOftheMemory];
else
    Memory[addressOftheMemory] = data;
end

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 @(posedge clk) begin
if( open )
    outp = Memory[addressOftheMemory];
else
    Memory[addressOftheMemory] = data;
end
月竹挽风 2024-11-11 16:06:08

您可以将执行延迟到时钟边缘,如下所示:

always @ ( open )  // open is 1 or 0 
  if ( open  )
     @(posedge clk) outp = Memory[addressOftheMemory];
  else if ( !open )    
     Memory[addressOftheMemory] = data;

这可能会也可能不会实现您想要的效果。它不可合成,并且 always 块在执行或挂起时不会被重新调度,因此如果 open 在一个时钟周期内多次切换,该代码可能不会去做你想做的事。

更多背景:您可以在任何语句上指定延迟/事件控制,包括空语句。 (例如,在@(posege clk);中,分号是空语句。)事实上,always构造的语法定义是:

always_construct:始终语句

这意味着 always @(open)always @(posedge clk) 并没有什么神奇之处,它们只是引入了一个语句并指定事件控制。当延迟控制 (#) 附加到语句时,该语句的执行将推迟到将来的固定时间。当事件控制 (@) 附加到语句时,该语句的执行将推迟到满足事件条件为止。

You can delay execution until the clock edge like this:

always @ ( open )  // open is 1 or 0 
  if ( open  )
     @(posedge clk) outp = Memory[addressOftheMemory];
  else if ( !open )    
     Memory[addressOftheMemory] = data;

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 if open 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 an always construct is:

always_construct: always statement

Meaning that there is nothing magical about always @(open) or always @(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文