2009-05-12 7 views
11

여기에 무슨 일이 일어나고 있습니까? 왜 '연산자 인수 형식 불일치'가 발생하며이를 수정하려면 어떻게해야합니까? 당신이 STD_LOGIC를 증가 할 수왜이 'std_logic_vector'를 증가시킬 수 없습니까

-- 
-- 32-bit counter with enable and async reset 
-- 
architecture synthesis1 of counter_32bit is  
signal nextvalue : std_logic_vector (31 downto 0);  
begin 

    -- 
    -- combo 
    -- 
    nextvalue <= value + 1; -- here 

    -- 
    -- sequential 
    -- 
    ff:process(clk, rst) 
    begin 

    if(rst = '1') then 
     value <= 0; -- and here... 
    elsif(clk'event and (clk ='1')) then 
     if(ena = '1') then 
     value <= nextvalue; 
     end if; 
    end if; 

    end process ff;  

end synthesis1; 

감사

+0

시뮬레이터의 -v93 스위치가 깜빡이면'value'의 초기화를 위해'to_stdlogicvector (bit_vector '(X "0"))'또는'X "0"'만 사용하십시오. – Marty

답변

24

직접, 당신은 numeric_std 패키지를 사용 std_logic_vector 다시 unsigned 그 결과로 변환해야합니다. 예 : How Do Perform STD_LOGIC_VECTOR Addition Using IEEE.NUMERIC_STD 참조.

+0

감사! 이 VHDL 물건은 매우 까다 롭습니다 ... – Marty

+3

실제로 그 까다 롭지 않은, 사실은 매우 명시 적입니다. 'std_logic_vector'는 단지 비트 배열이므로 숫자 값은 없습니다. VHDL-2008에는'IEEE.Numeric_Std_Unsigned'와'IEEE.Numeric_Std_Signed'라는 두 개의 패키지가 있습니다.이 패키지는 std_logic_vector에 직접 산술 연산을 수행 할 수있게합니다. VHDL의 강력한 측면 중 하나가 explicitness이기 때문에 나는 이것이 좋은 일이라고 생각하는지 잘 모르겠습니다. 적어도 Verilog 스타일로하고 싶다면 거기에 있습니다. – trondd

+0

VHDL-2008은 IEEE.numeric_std_unsigned 만 추가합니다. –

3

또 하나의 방법은 당신이 쓸 수 있습니다이 경우 "+"오버로드 할 수 있습니다 :

function "+" (a : std_logic_vector; b : integer) return std_logic_vector is 
    variable result : unsigned(a'range); 
begin 
    result := unsigned(a) + 1 ; 
    return std_logic_vector(result) ; 
end function ; 

는 패키지를 만들고 해당 패키지에이 기능을 포함하고,이 트릭을 할 것입니다. 변환 함수가 포함되어 있으므로 ieee numeric_std 패키지를 추가해야합니다.

1

이미 제공된 답변 외에도 nextvalue을 데이터 유형이 unsigned (아래) 인 것으로 정의하는 코드를 다시 작성할 수 있습니다. 카운 터를 지우는 데 nextvalue <= to_unsigned(0, 32);을 사용하고, 상승 에지를 트리거하는 데 rising_edge(clk)을 사용하는 것에 유의하십시오.

-- 32-bit counter with enable and async reset 
architecture synthesis1 of counter_32bit is  
    signal nextvalue : unsigned (31 downto 0);  
begin 

    ff:process(clk, rst) 
    begin 

     if(rst = '1') then 
      nextvalue <= to_unsigned(0, 32); -- reset the count 
     elsif rising_edge(clk) then 
      if(ena = '1') then 
       nextvalue <= nextvalue + 1; -- increment the count 
      end if; 
     end if; 

    end process ff; 

    -- Concurrent assignment statement 
    value <= std_logic_vector(nextvalue); 

end synthesis1; 

동시 할당이 양식은 내가 책과 온라인으로 볼 것을에서 카운터를 업데이트하는 선호하는 방법이 될 것으로 보인다. 당신이 nextvalue에 대한 std_logic_vector 유형을 계속 사용하는 경우에도

는, 그것을 삭제하는 바람직한 방법은 nextvalue <= (others => '0');보다는 nextvalue <= 0; 것 같다.

1

간단히 말해서 STD_LOGIC_VECTOR는 바로 비트 벡터입니다. 그것은 자체적으로 아무것도 의미하지 않으므로 vhdl이 증분 작업이 의미 상으로 작동한다고 가정 할 수는 없습니다. 서명되지 않은 상태로 변환하는 방법에 대한 다른 게시물은 트릭을 수행해야합니다.

0

이것은 또한 작동합니다 : 당신이 정말 잘 VHDL에 정통한 경우

nextvalue <= value + '1'; 

그나마 알고있다. 이 코드를 사용해보십시오 std_logic_arith 패키지

1

를 사용하는 경우 논리적으로 올바른 다음 구문 IST : 내 경우

use IEEE.STD_LOGIC_ARITH.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 
... 
nextvalue <= value + "1"; 

이 솔루션은 작품입니다!

관련 문제