なぜ私はこの `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 );
<のhref = "https://web.archive.org/web/20160322172912/http://objectmix.com/vhdl/190708-how-do-perform-std_logic_vector-addition-using-ieee-numeric_stdを参照してください。 .htmlを」REL = "nofollowをnoreferrer">どのようSTD_LOGIC_VECTOR添加は、例えばIEEE.NUMERIC_STD を使用して実行してください。
他のヒント
このコードを試してみてください。
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パッケージを使用している場合は、次の構文が論理的に正しいです。