简体   繁体   English

如何在时钟的 posedge 和 negedge 设置信号?

[英]How to set a signal at both posedge and negedge of a clock?

I'm trying to implement a controller with the function that sends out the same clock signal as its input clock.我正在尝试使用 function 实现 controller,它发出与其输入时钟相同的时钟信号。 But the controller can also halt the output signal if needed.但如果需要,controller 也可以停止 output 信号。 I'm implementing it on Xilinx ISE.我正在 Xilinx ISE 上实现它。

My idea is: At the negedge of the input clock, the output clock signal set to 0. At the posedge of the input clock, if I want to send out the clock I'll set the output clock to 1, but if I want to halt the output clock, I'll set the output clock to 0 so other devices (all posedge-triggered) won't detect the posedge.我的想法是:在输入时钟的后沿,output 时钟信号设置为 0。在输入时钟的位置,如果我想发送时钟,我会将 output 时钟设置为 1,但如果我想为了停止 output 时钟,我将 output 时钟设置为 0,以便其他设备(所有 posedge 触发)不会检测到 posedge。

Here's my design:这是我的设计:

module controller(
    input clk_in,
    input reset,
    output clk_out
    //and other ports
);
    always @(negedge clk_in)
      clk_out<=0;

    always @(posedge clk_in)
      if(reset)
        clk_out<=1;
      else
      begin
        case(cases)
          case1:
          begin
            //do something and halt the output clock
            clk_out<=0;
          end
          case2:
          begin
            //do something and continue the output clock
            clk_out<=1;
          end
        endcase
      end       

When I synthesized the design I had an error saying the signal clk_out is connected to multiple drivers.当我合成设计时,我有一个错误说信号 clk_out 连接到多个驱动程序。 Is there any way to solve it?有什么办法可以解决吗?

You have two different always blocks which drive the same signal clk_out.您有两个不同的 always 块,它们驱动相同的信号 clk_out。 This is what synthesis tells you about.这就是综合告诉你的。 All signals in a synthesizable rtl must be driven from a single block only.可合成 rtl 中的所有信号必须仅从单个模块驱动。

It looks like you are trying to create some type of a gated clock.看起来您正在尝试创建某种类型的门控时钟。 Instead of going through the trouble of detecting negedges of the clock, which most likely will not be synthesizable as well, you can use a simple logic to do so:您可以使用一个简单的逻辑来执行此操作,而不是通过检测时钟信号的麻烦(这很可能也无法合成):

    always @*
        clk_out = enable & clk_in;

You just have to figure out how to generate enable .您只需要弄清楚如何生成enable

BTW, never use NBAs (<=) in generating clock signals or you end up with clock/data race conditions.顺便说一句,切勿在生成时钟信号时使用 NBA(<=),否则您最终会遇到时钟/数据竞争条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM