reset的作用是强制系统在一个预知的状态开始运行。复位分为同步复位和异步复位两种,最近看了两篇有关同步复位和异步复位的论述,做一个总结。需要注意的是,无论在ASIC还是在FPGA中,reset低电平有效,即'0’复位。同步复位:同步复位是指复位发生在clock的激活沿。同步复位通过在flip-flop输入前通过组合逻辑实现。下面是一个标准的同步复位的flip-flop的例子:library ieee;use ieee.std_logic_1164.all;entity FF_S_rst is port ( clk : in std_logic; rst_n : in std_logic; d : in std_logic; q : out std_logic);end FF_S_rst;architecture rtl of FF_S_rst isbegin process (clk) begin if (clk'event and clk = '1') then if (rst_n = '0') then q = '0'; else q = d; end if; end if; end process;end rtl;可以在程序中加入如下命令// synopsys sync_set_reset "rst_n",使DC在综合时将同步复位的组合逻辑尽可能接近flip-flop。或者也可以将hdlin_ff_always_sync_set_reset设为true,以达到相同的目的。同步复位有以下优点:综合出来的flip-flop面积较小,大概每个flip-flop节省一到两个逻辑门;可以使电路100%同步;可以避免因为复位信号的毛刺而造成的系统误复位。同时,同步复位也有以下缺点:会在数据通路引入组下呒;并不是所有的ASIC库都有同步复位的flip-flop元件;需要复位信号长于一个时钟,这在多时钟系统中尤其要考虑;复位需要时钟信号,这在有门控时钟的电路的系统中就可能存在问题。异步复位:异步复位是指复位跟时钟没有关系,reset低电平系统将复位。下面是一个标准的异步复位的flip-flop的例子:library ieee;use ieee.std_logic_1164.all;entity asyncresetFFstyle is port ( clk : in std_logic; rst_n : in std_logic; d : in std_logic; q : out std_logic);end asyncresetFFstyle;architecture rtl of asyncresetFFstyle isbegin process (clk, rst_n) begin if (rst_n = '0') then q = '0'; elsif (clk'event and clk = '1') then q = d; end if; end process;end rtl;异步复位的优点:不会在数据通路引入组合逻辑;综合时不需要特别指定一个异步复位的管脚。异步复位的缺点:如果异步复位信号消失的时候,正好在或接近时钟的激活沿,可能导致复位失效;容易受复位信号上毛刺的影响造成误复位。可以增加复位同步电路以避免复位信号在时钟激活沿消失导致的复位失效:library ieee;use ieee.std_logic_1164.all;entity asyncresetFFstyle is port ( clk : in std_logic; asyncrst_n : in std_logic; rst_n : out std_logic);end asyncresetFFstyle;architecture rtl of asyncresetFFstyle is signal rff1 : std_logic;begin process (clk, asyncrst_n) begin if (asyncrst_n = '0') then rff1 = '0'; rst_n = '0'; elsif (clk'event and clk = '1') then rff1 = '1'; rst_n = rff1; end if; end process;end rtl;可以增加滤波电路去除毛刺造成的误复位:即复位信号的非与延迟一定时间后的复位信号的非求与非作为新的复位信号,这样可以可以去掉延迟时间以下的毛刺,避免误操作。总结:1、尽量使用同步复位,在使用同步复位的时候注意声明同步复位的信号。2、需要用异步复位的时候,可以加上同步电路,避免复位失效。电路内部产生的复位信号,慎用异步复位。References:1. Synchronous Resets? Asynchronous Resets? I am so confused. How will I ever know which to use.2. Asynchronous Synchronous Reset Design Techniques……