2019年12月27日 星期五

Verilog 範例 5-5 布林代數 f= sigma(0,1,2,4,5,6,8,10,11)

Verilog 範例 5-5 布林代數 f= sigma(0,1,2,4,5,6,8,10,11)





//EX5-5_p133
module EX5_5_p133(A,B,C,D,F);

input  A,B,C,D ; // A, B ,C  1位元輸入
output F ;     // Output    1位元輸出
reg F;

always@(A or B or C or D)
begin
 case({A,B,C,D})
  4'b0000:F=1'b1;   //0
  4'b0001:F=1'b1; //1
  4'b0010:F=1'b1; //2
  4'b0011:F=1'b0; //3
  4'b0100:F=1'b1; //4
  4'b0101:F=1'b1; //5
  4'b0110:F=1'b1; //6
  4'b0111:F=1'b0; //7

  4'b1000:F=1'b1; //8
  4'b1001:F=1'b0; //9
  4'b1010:F=1'b1; //10
  4'b1011:F=1'b1; //11
  4'b1100:F=1'b0; //12
  4'b1101:F=1'b0; //13
  4'b1110:F=1'b0; //14
  4'b1111:F=1'b0; //15
//sigma(0,1,2,4,5,6,8,10,11)
 endcase
end

endmodule


// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps
module Test_bench;
reg t_A = 1'b0;   //  暫存器資料初值為‘0’
reg t_B = 1'b0;   //  暫存器資料初值為‘0’
reg t_C = 1'b0;   //  暫存器資料初值為‘0’
reg t_D = 1'b0;   //  暫存器資料初值為‘0’

wire t_F;

integer i;

EX5_5_p133  DUT(.A(t_A), .B(t_B), .C(t_C),.D(t_D),.F(t_F) );
// initial程序結構區塊, 產生A、B輸入信號波形
initial begin
    $monitor(t_A,t_B,t_C,t_D,t_F);
    for (i=0; i<16; i=i+1) begin
        {t_A,t_B,t_C,t_D} = i;
        #20;
    end
end

initial
begin
  #340;   // 模擬終止時間  200 ns
    $stop;
end

endmodule


沒有留言:

張貼留言

Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3

  Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3 AngularJS 實例 <!DOCTYPE html> <html> <head> <meta charse...