2017-12-09 30 views
-1
library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_ARITH.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 


entity A is 
    Port (
     clk : in STD_LOGIC; 
     reset: in std_logic; -- reset input 
     counter: out std_logic_vector(3 downto 0) := "0000"-- output 4-bit counter 
); 
end A; 

architecture Behavioral of A is 
signal counter_up: std_logic_vector(3 downto 0) := "0000"; 
signal countOf : integer := -1; 
signal count : integer := 0; 
signal temp : std_logic := '0'; 
begin 
-- up counter 

     process(clk) 
    begin 
if(clk'event and clk='1') then 
count <=count+1; 
if(count = 50000000) then 
temp <= not temp; 
count <=1; 
end if; 
end if; 
end process; 

process(temp,reset) 
begin 
if(reset = '1') then 
    countOf <= 0; 
else 
     if(temp = '1') then 

      if(countOf < 4) then countOf <= countOf + 1; 
      else countOf <= 0; end if; 

      if(countOf = 0) then counter_up <= "0000"; end if; 
      if(countOf = 1) then counter_up <= "0001"; end if; 
      if(countOf = 2) then counter_up <= "0010"; end if; 
      if(countOf = 3) then counter_up <= "0100"; end if; 
      if(countOf = 4) then counter_up <= "1000"; end if; 


     end if; 

end if; 
end process; 

counter <= counter_up; 

end Behavioral; 

안녕하세요 저는 0에서 4까지의 카운터를 만들고 싶습니다. 제 시계를 1 HZ로 나누고 임시 및 리셋 과정에서 모든 조건을 할당했으나 어떻게 내가 원하는지. 그것은 매우 이상합니다. 어떻게 해결할 수 있습니까? 미리 감사드립니다.각각의 카운트 vhdl

+0

귀하의 조합 프로세스가 작동하지 않습니다. 모든 것을 클럭 처리에 적용하지 않는 이유는 무엇입니까? 추신. 테스트 벤치를 작성했다면 이미 작동하지 않는 것을 보았을 것입니다. – JHBonarius

답변

0

process(temp, reset)은 조합 방식으로 만들어 졌으므로 사용할 수 없습니다.이 경우에는 필요한 것이 아닙니다. 시뮬레이션에서 잘 작동하고 하드웨어에서 전혀 작동하지 않습니다. 당신이 쓴 무엇

하드웨어에서 루프를 생성 countOf의 상태는 tempcountOf 자체의 상태의 상태에 따라 달라집니다. 프로세스에 시계가 포함되어 있지 않으므로 countOf의 상태는 게이트 지연만큼 빠르게 변경됩니다 (이 코드가 올바르게 합성되는 경우). 사례의 99 %에 그 당신이 얻을 것이다 의미하기 때문에,

[Synth 8-614] signal 'countOf' is read in the process but is not in the sensitivity list 

당신이 무시하지한다 : 소프트웨어가 좋은 경우

, 그것은 당신에게이 같은 경고를 줄 것이다 바람직하지 않은 동작 및/또는 시뮬레이션 불일치.

당신이해야 할 일은 temp입니다. 그것은 클럭 분배기에 의해 생성되므로, 논리적으로는 거의 확실하게 시계이기를 원할 것입니다. if (temp = '1') thenif rising_edge(temp) then으로 바꾸면 코드가 원하는대로 작동합니다.

사이드 노트 : use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;을 삭제하십시오. 코드에 서명되지 않은 라이브러리가 전혀 필요하지 않을뿐만 아니라 IEEE.STD_LOGIC_ARITH이 아니며 더 이상 사용하지 않아야합니다.. 수년간 지속되어 왔습니다. 대신 IEEE.NUMERIC_STD을 사용하십시오.