Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Assignment MUXs in Verilog

Status
Not open for further replies.

IBNobody

Junior Member level 1
Joined
Jan 22, 2006
Messages
18
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,283
Activity points
1,473
One thing in Verilog always gives me fits:

assign data_out =
((output_select == 3'h01) * {2'b0, saved_rx_data[12:7]})
+ ((output_select == 3'h02) * {1'b0, saved_rx_data[6:0]})
+ ((output_select == 3'h03) * 8'h00);

This statement only produces 1 bit because of the logical equal-to sign. Similar logic would work just fine in C.

Can anyone tell me a better way to write out an equation-based MUX?

I thought about assigning aliases for each of the 3 MUX terms and using generates to combine them... But that's kinda clunky.

I'd love to hear your suggestions
 

I think this is the best way to write a MUX!!
The output is not 1 bit. Plaese checkout.
Here is an example!
Code:
module mux (
   // Outputs
   data_out,
   // Inputs
   output_select, saved_rx_data
   );
   input [2:0] output_select;
   input [12:0] saved_rx_data;
   output [7:0] data_out;
   
   assign data_out = ((output_select == 3'h1) * {2'b0, saved_rx_data[12:7]})
                   + ((output_select == 3'h2) * {1'b0, saved_rx_data[6:0]})
                   + ((output_select == 3'h3) * 8'h00);
endmodule // mux

module test();
   reg [2:0]            output_select;          // To mux of mux.v
   reg [12:0]           saved_rx_data;          // To mux of mux.v
   wire [7:0]           data_out;               // From mux of mux.v
   mux mux (
            // Outputs
            .data_out                   (data_out[7:0]),
            // Inputs
            .output_select              (output_select[2:0]),
            .saved_rx_data              (saved_rx_data[12:0]));
   initial begin
      $monitor ($time,,"A= %x B= %x C= %x SEL=%x Y= %x",
                {2'b0, saved_rx_data[12:7]}, {2'b0, saved_rx_data[6:0]}, 
                0, output_select, data_out);
      output_select = 0;          
      saved_rx_data[12:7] = 6'h1a;
      saved_rx_data[6:0]  = 7'h55;
      #10 output_select = 1;
      #10 output_select = 2;
      #10 output_select = 3;
      #10 $finish;
   end
endmodule // test
 

i think using a case statement is better way to code a mux
for eg
Code:
reg [7:0] data_out ;
always @ *
begin
   case(output_select)
   3'h1:
   begin
      data_out = {2'b0, saved_rx_data[12:7]} ;
   end
   3'h2:
   begin
      data_out = {1'b0, saved_rx_data[6:0]} ;
   end
   default:
   begin
      data_out = 8'b0 ;
   end
   endcase
end
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top