初めまして!『ぽき』です。

これから1年間記事を掲載させていただきます。

皆様の理解につながるような記事を書けるよう頑張ります。

 

 

技術研修が始まりハードウェア設計言語の一つである Verilog HDL を勉強しました。

C 言語の経験があったので、Verilog HDL の記述スタイルは理解しやすかったです。

大規模な論理回路の処理をプログラムで記述することができるので、回路図で記述するよりも非常に簡単に設計できるのですね!

さて、研修で Verilog HDL を使用して図1の回路を作成する課題がでました。

This circuit uses a counter (counter:u00) and a decoder (segment:u01).

図1:作成する論理回路

counter と segment というモジュールを作成して、上位階層ファイルで呼び出し接続しています。

 

問題はモジュールの作成時に起こりました。

 

Since Quartus ® II can perform logic check function and logic synthesis, when I tried logic synthesis using Quartus ® II,

4 bit の counter は論理合成。。。できました!

 

次の 7 bit のsegment は論理合成。。。が できません!

以下の Error が発生して、論理合成前の論理チェックで止まってしまいました。

 

Error (10137): Verilog HDL Procedural Assignment error at segment.v: object "out" on left-hand side of assignment must have a variable data type

 

どうやら segment モジュールの出力 out に原因があるようです。

もう少し詳しく知りたいなあ。。。

 

At that time, my senior said something.

先輩 「Help を見たら?」

 

ん? Help?そんな便利なものがあるのですか!?

 

All you have to do is highlight the Error you want to know more about and press the F1 key!

By pressing the F1 key (You can also do the same by right-clicking and clicking Help.)

You can see the explanation of the error content in the Quartus ® II Help.

 

すると今回は以下のような解説が出てきました。

ID:10137 Verilog HDL Procedural Assignment error at <location>: object "<name>" on left-hand side of assignment must have a variable data type

CAUSE: In a procedural assignment at the specified location in a Verilog Design File (.v), you assigned a value to the specified object, which was declared with a net data type (wire, wand, and so on) rather than with a variable data type (reg, integer, and so on). In Verilog HDL, you must use continuous assignments when targeting nets, and procedural assignments when targeting variables.

 

ACTION: Declare the specified object with a variable data type, if that is appropriate, or use a continuous assignment to assign a value to the object.

 ~~~~~~~~~~~~

(summary)

Cause: Declaring something of a net type (wire, wand, etc.) with a variable type (reg, integer, etc.).

In Verilog HDL, if the target is a net type, it must be used in a continuous assignment statement, and if it is a variable type, it must be used in a procedural assignment statement.

 

Workaround: Define the target of the error with a variable type, or describe the variable type defined with a procedure assignment statement.

ネット型を変数型に変更する?

ここで segment モジュールを見直してみると、、、

図2:segment モジュール

 

always 文で出力 out を使っています!

出力 out は wire で宣言しているので、always 文では使うことができません。

 

always 文で使うために図3のように wire を reg に変更したら無事論理合成できました。

図3:変更前(左) と 変更後(右)

補足としまして、各文で使えるデータタイプ型は以下のとおりです。

継続代入文 (continuous assignment )    assign文: ネット型 (  wire, wand  ) 

手続き代入文 (continuous assignment)   always文: 変数型 ( reg , integer  )

 

 

ちなみに過去の先輩も同じことで悩まれていました。

「Verilog HDL」

 

その後、上位階層を作成し、無事 RTL Viewer で図 1 の通りに回路を作ることができました。

Error は嫌ですけれど、原因が分かるとうれしいですよね。

みなさんも困ったときは「Error の上でハイライト(クリック)して F1 キー」押してみてください♪ 

新しい発見があるかも知れませんよ!

 

[This time's point! ]

Highlight Error and press F1 key ⇒ Go to Quartus® II Help to check details.