2021年4月20日 星期二

HBLbits_Verilog Basic_Always case

 HBLbits_Verilog Basic_Always case 


Case statements in Verilog are nearly equivalent to a sequence of if-elseif-else that compares one expression to a list of others.

always @(*) begin     // This is a combinational circuit
    case (in)
      1'b1: begin 
               out = 1'b1;  // begin-end if >1 statement
            end
      1'b0: out = 1'b0;
      default: out = 1'bx;
    endcase
end


create a 6-to-1 multiplexer. When sel is between 0 and 5, choose the corresponding data input. Otherwise, output 0. The data inputs and outputs are all 4 bits wide.

// synthesis verilog_input_version verilog_2001
module top_module ( 
     input [2:0] sel, 
     input [3:0] data0, 
     input [3:0] data1, 
     input [3:0] data2, 
     input [3:0] data3, 
     input [3:0] data4, 
     input [3:0] data5, 
     output reg [3:0] out   );
     
    always@(*) begin  // This is a combinational circuit 
     case(sel) 
         3'd0: out=data0; 
         3'd1: out=data1; 
         3'd2: out=data2; 
         3'd3: out=data3; 
         3'd4: out=data4; 
         3'd5: out=data5; 
         default: out=4'd0; 
     endcase 
     end 
 endmodule

沒有留言:

張貼留言

2026 作業3 RFID+ Telegram 練習

 2026 作業3  RFID+ Telegram  練習 (Wokwi 與 Telegram 二者溝通訊息反映比較慢 ) 歡迎 Alex 使用 RFID 控制系統 /on : 開啟 LED /off : 關閉 LED /flash : 閃爍模式 /timer : 開啟 5 秒 ...