|
发表于 2009-11-24 12:07:45
|
显示全部楼层
楼主的程序从硬件角度来分析:pin_temp 是一个多bits的触发器, 可以由D触发器实现. OK.
但是d_in和second(0)都是上升沿的时钟信号,这样需要双时钟的D触发器. 现实中没有双时钟驱动的D触发器. 故例子失败!
故外接一个高频时钟(clk)来处理. 用这个时钟来检测d_in,second的边缘跳变. clk的频率按照精度要求确定.
process( rst, clk ) -- 复位和时钟
variable d, s : std_logic;
begin
if( rst = '0' ) then
pin_temp<="0000000000000000";
d := '0';
s := '0';
elsif( clk'event and clk='1' ) then
if( s='0' and second(0)='1') then
pin_temp<="0000000000000000";
elsif( d='0' and d_in='1' ) then
pin_temp<=pin_temp+1;
end if;
s := second(0);
d := d_in;
end if;
end process; |
|