이`std_logic_vector`를 증가시킬 수없는 이유는 무엇입니까?
-
21-08-2019 - |
문제
여기서 무슨 일이야? 왜 '운영자 인수 유형 불일치'를 받고있는 이유는 무엇입니까?
--
-- 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;
감사
해결책
std_logic을 직접 증가시킬 수 없으므로 변환해야합니다. unsigned
그리고 결과는 다시 std_logic_vector
사용 numeric_std
패키지.
use ieee.numeric_std.all
...
nextvalue <= std_logic_vector( unsigned(value) + 1 );
보다 ieee.numeric_std를 사용하여 std_logic_vector 추가를 수행하는 방법 예를 들어.
다른 팁
이 코드를 시도하십시오 :
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
...
nextvalue <= value + "1";
제 경우에는이 솔루션이 작동합니다!
또 하나의 방법은 "+"에 과부하하는 것입니다.이 경우 다음을 쓸 수 있습니다.
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 패키지가 포함됩니다.
이미 제공된 답변 외에도 코드를 다시 작성하여 정의 할 수 있습니다. 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;
이 형태의 동시 할당은 책과 온라인에서 찾은 것들에서 카운터를 업데이트하는 선호하는 방법 인 것 같습니다.
또한 계속 사용하는 경우 std_logic_vector
유형 nextvalue
, 그것을 지우는 선호하는 방법은 nextvalue <= (others => '0');
단지보다는 nextvalue <= 0;
.
간단히 말해서, std_logic_vector는 바로 비트의 벡터입니다. 그것은 그 자체로는 아무것도 의미하지 않으므로 VHDL이 증분 작동이 작동한다고 의미 적으로 가정 할 수 없습니다. 서명되지 않은 것으로 변환하는 것에 대한 다른 게시물은 트릭을 수행해야합니다.
이것은 또한 작동합니다 :
nextvalue <= value + '1';
VHDL에 정통한지 모르겠습니다. STD_LOGIC_ARITH 패키지를 사용하는 경우 다음 구문 IST 논리적 올바른