2020年4月16日 星期四

BCD(8421) to Excess-3 Dataflow Level in Verilog

BCD(8421) to Excess-3  Dataflow Level in Verilog 




module BCD_EX3_Dataflow(B,Y);

input  [3:0]B;  // B  4位元輸入
output [3:0]Y;   // Y    4位元輸出
reg [3:0]Y;

always@(*)
begin
 Y[3] = B[3] | (B[2]&B[1]) | (B[2]&B[0]);
 Y[2] = (~B[2]&B[1]) | (~B[2]&B[0]) | (B[2] & ~B[1] & ~B[0]) ;
 Y[1] = ( B[1 ]& B[0]) | ( ~B[1] & ~B[0]) ;
 Y[0] =  ~B[0];
end

endmodule



// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps 
module TB;
/*
module BCD_EX3_Dataflow(B,Y);
input  [3:0]B;  // B  4位元輸入
output [3:0]Y;   // Y    4位元輸出
*/
reg [3:0]B= 4'b0000;   //  暫存器資料初值為‘0’

wire [3:0]Y;

integer i;

//DEVICE UNDER TEST (DUT) .
BCD_EX3_Dataflow DUT(B,Y);

initial begin
    for (i=0; i<16; i=i+1) begin
         B = i;
         #20;
    end
    #20
     $stop;
end

endmodule


沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...