Verilog class 2 - aries.dyu.edu.twaries.dyu.edu.tw/~thhu/DE/verilog class 2.pdf · 9 HW#3 •...

31
1 Verilog class 2

Transcript of Verilog class 2 - aries.dyu.edu.twaries.dyu.edu.tw/~thhu/DE/verilog class 2.pdf · 9 HW#3 •...

  • 1

    Verilog class 2

  • 2

    D型正反器

  • 3

    D型正反器

  • 4

    Always Block

    • always blocks :當觸發訊號啟動後, always block 就會執行一次。

    • always@(posedge clk)begin

    q

  • 5

    Clock 訊號設定

  • 6

    Clock 訊號設定(cont.)

    • Period (週期)=100 ns• Duty = 50 (logic 1 與 logic 0各佔

    50%)

  • 7

    D型正反器測試模組

  • 8

    D型正反器

  • 9

    HW#3

    • 製作一個負緣觸發的D型正反器,與其測試 模組 test_d_ff

    • 使用Simulation驗證電路正確

  • 10

    循序邏輯

    • 顧名思意,依序執行邏輯運算• 常見的方塊有: if, if_else, if_else_if, case,

    while_loop, for_loop.

  • 11

    if statementalways @ (觸發訊號) begin

    if ( 條件

    ) begin執行邏輯運算

    endend

  • 12

    if _else statementalways @ (觸發訊號) begin

    if ( 條件 ) begin執行邏輯運算1

    end else begin執行邏輯運算2

    end end

  • 13

    if _else_if statementalways @ (觸發訊號) begin

    if ( 條件 1 ) begin執行邏輯運算1

    end else if (條件 2) begin執行邏輯運算2

    end end

  • 14

    4 bit counter

    U/D

    clk

    enable reset

    count04 bit counter

    致能 重致

    數 器 之 輸 出

    上數/下數

    脈衝訊號

    count1count2count3

  • 15

    4 bit counter (Cont.)

  • 16

    4 bit counter (Cont.)

    • 測試模組 test_four_bit_counter

  • 17

    4 bit counter (Cont.)

  • 18

    HW#4

    • 製作一個負緣觸發的8 bit counter,與其測 試模組 test_8_bit_counter

    • 使用Simulation驗證電路正確

  • 19

    4-to-1 Multiplexer

    Y

    A B

    c04 to 1 Mux

    4 類

    輸 入

    僅一類輸出c1c2c3

  • 20

    4-to-1 Multiplexer

  • 21

    4-to-1 Multiplexer(Cont.)

  • 22

    4-to-1 Multiplexer(Cont.)

  • 23

    case statementalways @ (觸發訊號) case(訊號)

    : 執行邏輯運算1: 執行邏輯運算2

    …..default: 執行邏輯運算n

    end case

  • 24

    4-to-1 Multiplexer(Cont.)

  • 25

    4-to-1 Multiplexer(Cont.)

    • 測試模組 test_four_to_1_mux_1:

  • 26

    HW#5

    • 製作一個 2_to_1 multiplexer,與其測試模 組 test_2_to_1_multiplexer

    • 使用Simulation驗證電路正確

  • 27

    Assign Statement

    Assign 訊號A = (訊號B) ? 數值X:數值Y

    if (訊號B == 1 ) 訊號A = 數值Xelse 訊號A = 數值Y

    =訊號A 需被宣告為 wire, 如 wire signal A;

  • 28

    3-to-8 decoder

    input output000 00000001001 00000010010 00000100011 00001000100 00010000101 00100000110 01000000111 10000000

  • 29

    3-to-8 decoder

  • 30

    3-to-8 decoder(Cont.)

  • 31

    HW#6

    • 使用assignment 指令,製作一個 2-to-4 decoder,

    • 使用Simulation驗證電路正確

    input output00 000101 001010 010011 1000

    Verilog class 2D型正反器D型正反器Always BlockClock 訊號設定Clock 訊號設定(cont.)D型正反器測試模組D型正反器HW#3循序邏輯if statementif _else statementif _else_if statement4 bit counter4 bit counter (Cont.)4 bit counter (Cont.)4 bit counter (Cont.)HW#44-to-1 Multiplexer4-to-1 Multiplexer 4-to-1 Multiplexer(Cont.)4-to-1 Multiplexer(Cont.)case statement4-to-1 Multiplexer(Cont.)4-to-1 Multiplexer(Cont.)HW#5Assign Statement3-to-8 decoder3-to-8 decoder3-to-8 decoder(Cont.)HW#6