微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > 请帮我看看这段代码有没有问题啊?

请帮我看看这段代码有没有问题啊?

时间:10-02 整理:3721RD 点击:
always @(posedge clk)
  begin : rst_proc
    if (sync_por_n == 0)
    begin
      rst_first    <= 0;  // in first cycle
      old_rst_in_n <= rst_in_n; // save current state
      sync_rst_n   <= rst_in_n; // follow rst_in_n state
    end
    else
    begin
      // check rst_in state in c4:
      if (t_cycle == `c4)
      begin
        if (((old_rst_in_n == 1) && (rst_in_n == 0)) |
            ((old_rst_in_n == 0) && (rst_in_n == 1)))
        begin
          // rst_in goes low or high:
          rst_first <= 1;
        end
        // action only in second cycle:
        if (rst_first == 1)
        begin
          if (rst_in_n == 0)  // still applied ?
          begin
            sync_rst_n <= 0;
            rst_first  <= 0;
          end
          else if (rst_in_n == 1)
          begin
            sync_rst_n <= 1;
            rst_first  <= 0;
          end
        end
        old_rst_in_n <= rst_in_n; // save current state
      end
    end
  end  // rst_proc
感觉不对阿,这里面rst_in_n是芯片外面进来的信号,是异步信号.old_rst_in_n是时钟rst_in_n打了一拍产生的信号,如果rst_in_n的下降沿来得时候刚好和时钟的上升沿对齐 那么old_rst_in_n就可能是亚稳态信号,0,1不确定,rst_first是对old_rst_in_n和rst_in_n异或信号的同步,那么rst_first这时也有可能是亚稳态信号,0,1不确定.那若是old_rst_in_n和rst_first都稳定在0,那sync_rst_n不就检测不到rst_in_n的下降沿了吗?也就是sync_rst_n不就等于不了0了吗?这段代码是权威公司的正规代码,不知道是怎么回事啊?望高手帮我解释一下啊?谢谢?

因为你这只是一段的代码,其实还有代码做这样的处理,那就是消除clk与rst_in_n的亚稳态,你没有看到那部分的代码

从代码来看,应该是像二楼说的一样,还有其它地方有外部复位的同步。
否则即使没有亚稳态问题, “rst_in_n”直接给多个寄存器赋值,也会出现不同步问题(因为延时不同,不同的寄存器在两个时钟内采样到rst_in_n信号的变化)。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top