FPGA程序设计者,最后是全同步设计,这样所有程序都在主时钟同一个节拍下工作,系统时序分析和统计都有参照,程序稳定不容易出问题。
但是很多初学者由于对这个问题不了解或研究不深入经常写下面的程序:
LIBRARY ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_signed.all;
ENTITY tongbu IS
PORT(
CLK : IN std_logic; --晶振时钟
clks : IN std_logic; --秒脉冲输入
reset : IN std_logic;
clk_tb : OUT STD_LOGIC ;--同步信号输出
right : OUT STD_LOGIC ;
fault : OUT STD_LOGIC );
END tongbu ;
ARCHITECTURE a OF tongbu IS
SIGNAL s0 : STD_LOGIC ;
SIGNAL s1 : STD_LOGIC ;
SIGNAL s2 : STD_LOGIC ;
signal count :integer range 0 to 255;
signal pps_count :integer range 0 to 8;
signal low_count :integer range 0 to 8;
BEGIN
process(clks,s0)
begin
if(clks'event and clks='1')then
s1<='1';
end if;
if(s0='1')then
s1<='0';
end if;
end process;
process(CLK,clks,s1,count,reset)
begin
if(s1='1')then
if(CLK'event and CLK='1')then
if(count=255 or (clks='1' and count>25)or reset='0')then
count<=0;
else count<=count+1;
end if;
end if;
end if;
end process;
process(clks,count)
begin
if(clks'event and clks='0')then
if(count<25 and s2='0')then
low_count<=low_count+1;
end if;
end if;
end process;
process(low_count)
begin
if(low_count>1)then
s0<='1';
else s2<='1';
end if;
end process;
process(clks,count,pps_count)
begin
if(count>248 and count<252 and pps_count<4)then
if(clks'event and clks='1')then
pps_count<=pps_count+1;
end if;
end if;
end process;
process(pps_count)
begin
if(pps_count>2)then
right<='1';
fault<='0';
elsif(pps_count<3)then
fault<='1';
right<='0';
end if;
end process;
END a;
上面程序写法对器件中D触发器结构和硬件实现非常不了解,产生了门控时钟(GATED CLOCK)。所谓门控时钟就是时钟信号通过逻辑门后去驱动D触发器,这样电路,软件经常不能准确评估延时和建立时间等路径参数。
如果对上面的电路仿真,就会出现下面告警:
Warning: No clock transition on "count[0]" register due to stuck clock or clock enable |