2013-07-02 3 views
4

직렬 데이터 신호 (에지)에서 에지를 감지하고 싶습니다. 나는 성공적으로 실행중인 VHDL에 다음과 같은 코드를 작성했지만 에지는 하나의 클록주기 지연으로 검출된다. 즉, 변경 출력은 각 에지에서 하나의 clk_50mhz주기 지연으로 생성된다. 아무도 지체없이 가장자리를 감지하도록 도와주세요. 고맙습니다. 나는 다음에 내 코드를 변경 VHDL 에지 감지

process (clk_50mhz) 
begin 
     if clk_50mhz'event and clk_50mhz = '1' then 
      if (rst = '0') then 
       shift_reg <= (others => '0'); 
      else 
       shift_reg(1) <= shift_reg(0); 
       shift_reg(0) <= din;  
         end if;  
     end if; 
end process; 

    process (clk_50mhz) 
    begin 
     if clk_50mhz'event and clk_50mhz = '1' then 
      if rst = '0' then 
       change <= '0' ; 
      elsif(clk_enable_2mhz = '1') then 
       change <= shift_reg(0) xor shift_reg(1);      
      end if ; 
     end if ; 
    end process ; 

내가 정확하게 당신이 필요 발견 가장자리

process (clk_50mhz) 
begin 
    if clk_50mhz'event and clk_50mhz = '1' then 
     if (RST = '0') then 
      shift_reg <= (others=>'0'); 
     else 
      shift_reg(1) <= shift_reg(0); 
      shift_reg(0) <= din;  
    end if;  
    end if; 
end process; 

change <= shift_reg(1) xor din; 

답변

2

를 감지 할 수 있어요.

어쩌면 좀 더 검색해야합니다 : http://fpgacenter.com/examples/basic/edge_detector.php.

편집 : 여기

당신은 당신은 여분의 클럭 사이클의 지연을 발생시키지 않고 차이를 감지하기 위해 조합 프로세스를 사용해야

library ieee; 
use ieee.std_logic_1164.all; 

entity double_edge_detector is 
    port ( 
     clk_50mhz : in std_logic; 
     rst   : in std_logic; 
     din   : in std_logic; 
     change  : out std_logic 
    ); 
end double_edge_detector; 

architecture bhv of double_edge_detector is 

signal din_delayed1 :std_logic; 

begin 
    process(clk_50mhz) 
    begin 
     if rising_edge(clk_50mhz) then 
      if rst = '1' then 
       din_delayed1 <= '0'; 
      else 
       din_delayed1 <= din; 
      end if; 
     end if; 

    end process; 

    change <= (din_delayed1 xor din); --rising or falling edge (0 -> 1 xor 1 -> 0) 


end bhv; 
+0

해당 페이지에서 제공되는 솔루션은 가장자리를 감지하거나 상승 또는 하강에 대한 참고 있지만 둘 다. –

+0

코드 패스포트 투트를 가져 주셔서 감사합니다. 나는 상승 및 하강 에지를 모두 감지하고 싶습니다. 코드를 구현할 때 din_delayed1은 din과 동일하므로 변경이 없습니다. – user24883

+0

din_delayed1이 din과 무엇을 의미합니까? 그것들은 1 클럭 사이클 씩 떨어져 있습니다. – Passepartout

1

이동합니다. (당신은 여전히뿐만 아니라 입력을 지연 한 레지스터가 필요합니다.)

DELAY: process(clk_50mhz) 
begin 
    if clk_50mhz'event and clk_50mhz = '1' then 
     din_reg <= din; 
    end if; 
end process; 

change <= din xor din_reg; 
+0

반드시 조합 논리에서 수행 할 필요는 없습니다. 그는 프로세스 문에서'if din_reg/= din'을 할 수 있습니다. –

+2

어떤 종류의 프로세스를 지정하지 않지만 클럭 된 프로세스에서 'if din_reg/= din'을 수행하면 상승 에지 이후 출력이 활성 클럭 사이클이됩니다. 프로세스가 클록되지 않으면 프로세스가 결합되어 본질적으로 내가 사용한 문과 동일합니다. –

+1

"변경"신호가 사용되는 방식에 따라 다릅니다. 다른 클럭 된 프로세스의 내부에서 읽혀질 경우, 타이밍은 클럭 된 프로세스에서'if din_reg/= din'을 사용한 것과 같은 것입니다. –