2020年4月12日 星期日

4bit comparator using == ,>, < operator (Dataflow level)

4bit comparator using == ,>, < operator (Dataflow level)




//=====================================================
// 4bit comparator using = operator (Dataflow level)
//=====================================================
module comp_4bit(a,b,Result);
input [3:0] a,b;
output [2:0] Result;

reg [2:0]tmp;
always @(*) begin
if (a>b)
tmp<=3'b100; //a>b
else if (a==b)
tmp<=3'b010; //a=b
else
tmp<=3'b001; //a<b
end
assign Result=tmp;
endmodule

// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps 
module TB;
/*
module comp_4bit(a,b,Result);
input [3:0] a,b;
output [2:0] Result;
*/
reg [3:0] a,b;
wire [2:0] Result;

integer i;
 
comp_4bit UUT(a,b,Result);
 
initial begin  
   for ( i=0;i<=256;i=i+1) 
        begin
           {a,b}  = i;
            #1;
        end
end
endmodule


沒有留言:

張貼留言

Node-Red --> MQTT --> Fuxa 開源碼網頁式圖控平台

Node-Red --> MQTT --> Fuxa      FUXA(一個開源的 Web HMI / SCADA 自動化監控軟體)的專案設定檔 。 這份設定檔完整定義了 HMI 監控畫面的 後端通訊(MQTT 連線、點位標籤) 與 前端網頁圖形介面(SVG 畫布...