描述電路的三種層次

tags: verilog digital design 邏輯設計 邏設

English Version

English Version

Structure Description ( Structural Modeling )

Format:

<gate> name ( output, intput1, input2,... );
  • 又稱為 Gate Level Description
  • 簡單來說就是把用一個個 gate 把電路描述出來。
Gate Name Icon Example Info
NOT
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
not not1( B, A ); B = ~A
AND
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
and and1( C, A, B ); C = A & B
OR
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
or or1( C, A, B ); C = A | B
XOR
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
xor xor1( C, A, B ); C = A ^ B

Example:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
module comparator( A, B, gt, lt, eq );
input A, B;
output gt, lt, eq;
wire negA, negB;
not not1( negA, A );
not not2( negB, B );
and and1( gt, A, negB );
and and2( lt, negA, B );
xnor xnor1( eq, A, B );
endmodule

Dataflow Description ( Dataflow Modeling )

Format:

wire A;
assign A = 1'b0;
//Note!! assign statement have to be used with wire type
  • 又稱為 continuous assignment.

  • 只要 = 右邊的值改變,assgin statement 就會執行一次

  • = 左邊只能是 wire

  • 輸出 “ 不 ” 可以包含輸入。例如: assign a = a + b;

  • 一個參數只能被 assign 一次。例如: assign a = b; assign a = c; //error

  • assign 的值也可以用大括弧來串聯 bit。

    • assign a = { 1'b0, 1'b1 }; // a = 2'b01
    • assign a = { 2{2'b10} }; // a = 4'b1010
module comparator( A, B, gt, lt, eq );
input A, B;
output gt, lt, eq;
assign gt = A & ~B;
assign lt = ~A & B;
assign eq = ~( A ^ B );
endmodule

其他更詳盡的語法說明,請參考 Lexical Conventions

Behavior Description ( Behavior Modeling )

格式

initial begin
...
end
always @( sensitivity list ) begin
...
end
  • Behavior 也稱作 procedural assignment,意思是會依照一些程序條件來觸發。

  • 又稱作 block assignment

  • 可分成兩種,initial block 和 always block。

    1. initial block:只會在程式一進來的時候執行一次,但是 initial block 是不能夠合成的,只能用在testbench

    2. always block:只要 sensitivity list 裡的 value 有改變,就會執行一次 always block 裡面的程式。

  • 往往 sensitivity list 內的參數會過多,為避免少寫,通常會用 * 代替。

  • 等號左邊只能夠是 reg
module comparator( A, B, gt, lt, eq );
input A, B;
output gt, lt, eq;
always @(*) begin
gt = A & ~B;
lt = ~A & B;
eq = ~( A ^ B );
end
endmodule

在這個範例中,always block 裡面使用的是 blocking assignment,也就是在這個 block 內部會依序執行,之後在 sequential circuit 的時候會再詳細的介紹。

更多詳盡的說明,請同學 google 尋找,或上 「Verilog HDL 教學講義」。

Homepage
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

描述電路的三種層次 tags: verilog digital design 邏輯設計 邏設 English Version English Version Structure Description ( Structural Modeling ) Format: < gate > name ( output, intput1, input2,... ); 又稱為 Gate Level Description 簡單來說就是把用一個個 gate 把電路描述出來。 Gate Name Icon Example Info NOT not not1( B, A ); B = ~A AND and and1( C, A, B ); C = A & B OR or or1( C, A, B ); C = A | B XOR xor xor1( C, A, B ); C = A ^ B Example: module comparator( A, B, gt, lt, eq ); input A, B; output gt, lt, eq; wire negA, negB; not not1( negA, A ); not not2( negB, B ); and and1( gt, A, negB ); and and2( lt, negA, B ); xnor xnor1( eq, A, B ); endmodule Dataflow Description ( Dataflow Modeling ) Format: wire A; assign A = 1'b0 ; //Note!! assign statement have to be used with wire type 又稱為 continuous assignment . 只要 = 右邊的值改變,assgin statement 就會執行一次 = 左邊只能是 wire 輸出 “ 不 ” 可以包含輸入。例如: assign a = a + b; 一個參數只能被 assign 一次 。例如: assign a = b; assign a = c; //error assign 的值也可以用大括弧來串聯 bit。 assign a = { 1'b0, 1'b1 }; // a = 2'b01 assign a = { 2{2'b10} }; // a = 4'b1010 module comparator( A, B, gt, lt, eq ); input A, B; output gt, lt, eq; assign gt = A & ~B; assign lt = ~A & B; assign eq = ~( A ^ B ); endmodule 其他更詳盡的語法說明,請參考 Lexical Conventions 。 Behavior Description ( Behavior Modeling ) 格式 initial begin ... end always @( sensitivity list ) begin ... end Behavior 也稱作 procedural assignment,意思是會依照一些程序條件來觸發。 又稱作 block assignment 可分成兩種,initial block 和 always block。 initial block :只會在程式一進來的時候執行一次,但是 initial block 是不能夠合成的,只能用在 testbench 。 always block :只要 sensitivity list 裡的 value 有改變,就會執行一次 always block 裡面的程式。 往往 sensitivity list 內的參數會過多,為避免少寫,通常會用 * 代替。 等號左邊只能夠是 reg 。 module comparator( A, B, gt, lt, eq ); input A, B; output gt, lt, eq; always @(*) begin gt = A & ~B; lt = ~A & B; eq = ~( A ^ B ); end endmodule 在這個範例中,always block 裡面使用的是 blocking assignment,也就是在這個 block 內部會依序執行,之後在 sequential circuit 的時候會再詳細的介紹。 更多詳盡的說明,請同學 google 尋找,或上 「 Verilog HDL 教學講義 」。 Homepage