2016-04-26 3 views
-1

Xlinix ISE 14.1を使用して次のコードを記述しました。 私が書いた次のvhdlコードの構文エラーで助けてください

私は構文が正確であることが判明が、ザイリンクス IDEはライン27および30

私はエッジを見つけることに類似している数値の行列の最初の偏導関数を見つけることを試みている時のエラーを示しています画像。

関数by2iは、バイト(すなわちビット)を整数に変換するために使用されます。

私はエラーメッセージを取得しています。このVHDLコードで

"ERROR:HDLCompiler:806 B:/gxgyVHDL.vhd" Line 27: Syntax error near "return".
"ERROR:HDLCompiler:806 - "B:/gxgyVHDL.vhd" Line 30: Syntax error near ","".

私はVHDLで非常に少し知っているようにこれらのエラーを修正することができません。私は、MUX、カウンタなどの実装のようなVHDLの基本的なプログラミングを学んだ

これは初めての私は画像処理のためのプログラムを書いているそして私はこのプログラムが期待どおりに動作するかどうかはよくわからないがmatlabとpython。

これらのエラーを修正するのを手伝ってください。ここで

は、VHDLコードです:

enter code here 
library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 
use IEEE.numeric_std.ALL; 
use IEEE.math_real.ALL; 

entity getGxGy is 
    generic (width : natural := 66; 
      height : natural := 130); --width and height of the image window. 

Port(pxl : in STD_LOGIC_VECTOR(7 downto 0); 
     clk : in bit; 
     fv : out real); --need to configure 'fv' signal properly to appropriate bit vector. 
end getHOGfv; 

architecture behave of getGxGy is 

function by2i (b : STD_LOGIC_VECTOR(7 downto 0)) return natural is 
    variable num : natural; 
    begin 
    num := 0; 
    for i in b'Range loop 
     if b(i) = '1' then 
     num := num + 2**i; 
     end if; 
    end loop 
    return num 
end by2i; 

type bufarr is array (1 to height, 1 to width) of natural; 
type gxgy is array (1 to height-2, 1 to width-2) of integer; 

--signal tempfv : mat4; 

process(clk, pxl) 
variable buf: bufarr; 
variable gx, gy: gxgy; 

begin 
    --Buffer to store/create 64*128 pixels/widthindowidth 
    for h in 2 to height-1 loop 
    for w in 2 to width-1 loop 
     buf(h)(w) := by2i(pxl); 
    end loop; 
    end loop; 

    --1pixel padding 
    for w in 1 to width loop 
    buf(1)(w) := 0; 
    end loop; 
    for w in 1 to width loop 
    buf(height)(w) := 0; 
    end loop; 
    for h in 2 to height-1 loop 
    buf(h)(1) := 0; 
    end loop; 
    for h in 2 to height-1 loop 
    buf(h)(width) := 0; 
    end loop; 

    --compute gradients 
    for h in 2 to height-1 loop 
    for w in 2 to width-1 loop 
     gx(h)(w) := buf(h+1)(w)-buf(h-1)(w); 
     gy(h)(w) := buf(h)(w+1)-buf(h)(w-1); 
     mag(h)(w) := abs(gx(h)(w)+gy(h)(w)); 
     ang(h)(w) := gy(h)(w)/gx(h)(w); 
    end loop; 
    end loop; 

    end process; 

    end behave; 
+0

符号なしの値を含む 'std_logic_vector'を整数に変換する場合は、' value_as_int <= to_integer(unsigned(value_as_std_logic_vector)); 'を使用してください。 –

答えて

1

いくつかの問題:

  1. あなたのエンティティ名が一致していません。それはあなたが上の末尾;が欠落しているend getHOGfv;
  2. と一致していないentity getGxGy、あるend loopあなたが間(あなたのアーキテクチャでbeginの文が欠落しているby2i
  3. にリターンの末尾;が欠落している
  4. by2iで多次元配列を使用するためのtype gxgyprocess(clk, pxl)
  5. あなたの構文が間違っている。むしろbuf(1)(w)よりも、それはbuf(1, 2)でなければなりません。
  6. magでもangも定義されていません。

エラーが多数ある場合は、正確な原因を追跡するのが難しい場合があります。多くの場合、コンパイラはエラーを報告する際に混乱します。最初のものから始めて、修正して、再コンパイルしてください。物事の清掃まで続きます。

また、明確化のポイント。 by2iは必要ありません。 numeric_stdを使って変換を行うことができます(これを指摘するscary_jeffのおかげで)。変換を行うにはto_integer(unsigned(pxl))を使用してください。

さらに1点。 std_logic_unsignednumeric_stdの両方を同時に使用しないでください。 numeric_stdは、符号付きおよび符号なしの数値を使用する標準的な方法です。 std_logic_unsignedはベンダー固有の拡張であり、標準ではありませんでした。

編集:あなたは、あなたの配列を定義するには、次の構文を使用:

type bufarr is array (1 to height, 1 to width) of natural; 

これで結構です。上記のように、buf(h, w)の構文を使用する必要があります。

あなたは、インデックス buf(h)(w)を使用でき
type width_array is array(1 to width) of natural; 
type bufarr is array(1 to height) of width_array; 

:しかし、あなたのような、違っそれを定義することができます。

私は前者を好みます。

+0

ありがとうございました。それは多くの助けとなりました。 – manid2

1

PlayDoughが指摘している構文項目と欠落した宣言に加えて、パッケージnumeric_std(Synopsysの算術ページstd_logic_unsignedと混同しないでください)とmath_real(未使用)の2つの余分なコンテキスト節があります。すべての変更がで編集された後

fvへの割り当てがありません注意して、

library ieee; 
use ieee.std_logic_1164.all; 
use ieee.std_logic_unsigned.all; 
-- use ieee.numeric_std.all; 
-- use ieee.math_real.all; 

entity getgxgy is 
    generic (width : natural := 66; 
      height : natural := 130); -- width and height of the image window. 

port(pxl : in std_logic_vector(7 downto 0); 
     clk : in bit; 
     fv : out real); -- need to configure 'fv' signal properly to appropriate bit vector. 
end getgxgy;   -- WAS gethogfv; 

architecture behave of getgxgy is 

    function by2i (b : std_logic_vector(7 downto 0)) return natural is 
     variable num : natural; 
    begin 
     num := 0; 
     for i in b'range loop 
      if b(i) = '1' then 
       num := num + 2 ** i; 
      end if; 
     end loop; -- MISSING ';' 
     return num; -- MISSING ';' 
    end function by2i; 

    type bufarr is array (1 to height, 1 to width) of natural; 
    type gxgy is array (1 to height - 2, 1 to width - 2) of integer; 

    --signal tempfv : mat4; 

begin -- for architecture modiy WAS MISSING 

    process (clk, pxl) 
     variable buf: bufarr; 
     variable gx, gy: gxgy; 
     variable mag, ang: gxgy; -- MISSING DECLARATIONS 

    begin 
     --buffer to store/create 64*128 pixels/widthindowidth 
     for h in 2 to height - 1 loop 
      for w in 2 to width - 1 loop 
       buf(h, w) := by2i(pxl); -- WAS buf(h)(w) 
      end loop; 
     end loop; 

     --1pixel padding 
     for w in 1 to width loop 
      buf(1, w) := 0;    -- WAS buf(1)(w) 
     end loop; 
     for w in 1 to width loop 
      buf(height, w) := 0;   -- WAS buf(height)(w) 
     end loop; 
     for h in 2 to height - 1 loop 
      buf(h, 1) := 0;    -- WAS buf(h)(1) 
     end loop; 
     for h in 2 to height - 1 loop 
      buf(h, width) := 0;   -- WAS buf(h)(width) 
     end loop; 

    --compute gradients 
     for h in 2 to height - 1 loop 
      for w in 2 to width - 1 loop 
       gx(h, w) := buf(h + 1, w) - buf(h - 1, w); -- WAS gx(h)(w), buf(h+1)(w) and buf(h-1)(w) 
       gy(h, w) := buf(h, w + 1) - buf(h, w - 1); -- WAS gy(h)(w), buf(h)(w+1) and buf(h)(w-1) 
       mag(h, w) := abs(gx(h, w) + gy(h, w)); -- WAS mag(h)(w), x(h)(w) and gy(h)(w) 
       ang(h, w) := gy(h, w)/gx(h, w); --WAS ang(h)(w), gy(h)(w) and gx(h)(w) 
      end loop; 
     end loop; 

    end process; 

end architecture behave; 

あなたのコードが分析し、詳しく説明、タイプREALは、対象と合成されていないとclkのない合成資格を使用することはありません。

clkがstd_logic(またはstd_ulogic)だった場合は、std_logic_1164関数rising_edgeを使用できます。認識された順序論理RTLクロックエッジに対して構築追加

を与える:

process (clk) -- pxl NOT NEEDED , pxl) 
     variable buf: bufarr; 
     variable gx, gy: gxgy; 
     variable mag, ang: gxgy; -- MISSING DECLARATIONS 

    begin 
     if clk'event and clk = '1' then 
      --buffer to store/create 64*128 pixels/widthindowidth 
      for h in 2 to height - 1 loop 
       for w in 2 to width - 1 loop 
        buf(h, w) := conv_integer(pxl); -- WAS buf(h)(w) 
       end loop;   -- CHANGED to use conv_integer 
      end loop; 

      --1pixel padding 
      for w in 1 to width loop 
       buf(1, w) := 0;    -- WAS buf(1)(w) 
      end loop; 
      for w in 1 to width loop 
       buf(height, w) := 0;   -- WAS buf(height)(w) 
      end loop; 
      for h in 2 to height - 1 loop 
       buf(h, 1) := 0;    -- WAS buf(h)(1) 
      end loop; 
      for h in 2 to height - 1 loop 
       buf(h, width) := 0;   -- WAS buf(h)(width) 
      end loop; 

     --compute gradients 
      for h in 2 to height - 1 loop 
       for w in 2 to width - 1 loop 
        gx(h, w) := buf(h + 1, w) - buf(h - 1, w); -- WAS gx(h)(w), buf(h+1)(w) and buf(h-1)(w) 
        gy(h, w) := buf(h, w + 1) - buf(h, w - 1); -- WAS gy(h)(w), buf(h)(w+1) and buf(h)(w-1) 
        mag(h, w) := abs(gx(h, w) + gy(h, w)); -- WAS mag(h)(w), x(h)(w) and gy(h)(w) 
        ang(h, w) := gy(h, w)/gx(h, w); --WAS ang(h)(w), gy(h)(w) and gx(h)(w) 
       end loop; 
      end loop; 
     end if; 

    end process; 

も機能by2iを使用することから、パッケージstd_logic_unsigned機能conv_integerにスイッチを指摘しました。

したがって、これらの変更は、by2i関数の削除とともに行われます。

library ieee; 
use ieee.std_logic_1164.all; 

entity getgxgy_tb is 
end entity; 

architecture foo of getgxgy_tb is 
    signal pxl: std_logic_vector(7 downto 0) := (others => '0'); 
    signal clk: bit; 
    signal fv: real; 
begin 

DUT: 
    entity work.getgxgy 
     port map (
      pxl => pxl, 
      clk => clk, 
      fv => fv 
     ); 

CLOCK: 
    process 
    begin 
     wait for 10 ns; 
     clk <= not clk; 
     if now > 120 ns then 
      wait; 
     end if; 
    end process; 

end architecture; 

をそして、我々は手の込んだとテストベンチを実行し、実行時エラーを取得:

は、境界エラーを探すためにテストベンチをアップGenning!

angへの割り当てでエラーがゼロ除算になるため、アルゴリズムにはまだ少しの作業が必要です。

if文で、私たちが割り当てにおける境界エラーがあります見つけることブロッキング:

gx(h, w) := buf(h + 1, w) - buf(h - 1, w); -- WAS gx(h)(w), buf(h+1)(w) and buf(h-1)(w) 

そして、それはとき

type gxgy is array (1 to height - 2, 1 to width - 2) of integer; 

タイプgxgyの二次元w = 65を押すことによって引き起こされていますwに対応する範囲はwidth - 2の範囲であり、wwidth - 1に達する範囲外である。

それでは、さらにアルゴリズム的な表現の調整がまだあります。

登録する予定は特にありません。現在のところプロセスの感度リストがpxlおよびgxに設定されている場合、gy,magおよびangがシグナルに変換され、異なるプロセスで発生する可能性があるのはfvの場合のみです。

abs、multiplies、およびdivideがすべてターゲットFPGAに収まらない可能性があり、算術演算に共通のリソースを使用して演算をいくつかのクロックに分散する必要があります。 VHDLはハードウェアを表し、すべてのオペレータ呼び出しまたは関数呼び出しは、それ自身のハードウェアを暗示することができます。

ループステートメントには、「展開された」ステートメントのシーケンスがあり、相互依存関係が見つからない場合は別のハードウェアが生成されます。あなたの入れ子にされたループの2〜1の範囲と2〜幅1の範囲では、gxgyのそれぞれについて8001減算を意味し、absと加算してmagを加算し、angの値を変更しますpxl。これは、あなたのハードウェアが、時間と空間のトレードオフのうちのいくつかのクロックでリソースを共有することなく、どのFPGAにも適合しないことを示しています。

あなたのアルゴリズムはちょっとした作業が必要なだけでなく、実装リソースも考慮する必要があります。

VHDLでハードウェアを記述することはできません。

+0

"ハードウェアについて記述したVHDLでプログラミングしないでください。"アーメン。私は自分のコード(ループ、関数、時折手続き、配列、レコード)のほとんどの構造体でかなり自由であると思うが、私は常にハードウェアアーキテクチャを念頭に置いている。そして、私はコードが実際のハードウェアでどのように生成されるのかを知っています。 VHDLは終わりの手段です。道具。 – PlayDough

+0

ありがとうございます。今日私はたくさんのことを学びました。それは私をとても助けました。 – manid2

関連する問題