Wednesday, 9 November 2016

11. Verilog code for 8:1 Multiplexer( Different moduling style).

// Verilog code for 8:1 Multiplexer using Dataflow
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: RED-BLUE
// Engineer:
//
// Create Date:    21:33:27 11/08/2016
// Designer Name:  Madhu Krishna
// Module Name:    mux8_1_code
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module mux8_1_code(input_d0,
                                     input_d1,
     input_d2,
     input_d3,
     input_d4,
     input_d5,
     input_d6,
     input_d7,
     sel_0,
     sel_1,
             sel_2,
     output_y);
  // INPUTS
   input   input_d0;
   input   input_d1;
   input   input_d2;
   input   input_d3;
   input   input_d4;
   input   input_d5;
   input   input_d6;
   input   input_d7;
   input   sel_0;
   input   sel_1;
   input   sel_2;

  // OUTPUT
    output  output_y;
    wire    [10:0] mux_comb_out ;

  // Declaration using data flow

  assign  mux_comb_out[0]  = ~( sel_0);
  assign  mux_comb_out[1]  = ~( sel_1);
  assign  mux_comb_out[2]  = ~( sel_2);
  assign  mux_comb_out[3]  = (input_d0 & mux_comb_out[2] & mux_comb_out[1] & mux_comb_out[0]);
  assign  mux_comb_out[4]  = (input_d1 & mux_comb_out[2] & mux_comb_out[1] & sel_0);
  assign  mux_comb_out[5]  = (input_d2 & mux_comb_out[2] & sel_1 & mux_comb_out[0]);
  assign  mux_comb_out[6]  = (input_d3 & mux_comb_out[2] & sel_1 & sel_0);
  assign  mux_comb_out[7]  = (input_d4 & sel_2 & mux_comb_out[1] & mux_comb_out[0]);
  assign  mux_comb_out[8]  = (input_d5 & sel_2 & mux_comb_out[1] & sel_0);
  assign  mux_comb_out[9]  = (input_d6 & sel_2 & sel_1 & mux_comb_out[0]);
  assign  mux_comb_out[10] = (input_d7 & sel_2 & sel_1 & sel_0);
  assign  output_y = (mux_comb_out[3] | mux_comb_out[4] | mux_comb_out[5] | mux_comb_out[6] | mux_comb_out[7] |mux_comb_out[8] | mux_comb_out[9] | mux_comb_out[10]);
endmodule

------------------------------------------------------------------------------------------------------------------------------------------------

// Verilog code for 8:1 Multiplexer using strucutural 
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: RED-BLUE
// Engineer: 
// 
// Create Date:    21:33:27 11/08/2016 
// Designer Name:  Madhu Krishna
// Module Name:    mux8_1_str 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
            module mux8_1_str( input_d0,
                                                input_d1,
input_d2,
input_d3,
input_d4,
input_d5,
input_d6,
input_d7,
sel_0,
sel_1,
sel_2,
output_y
);
  // INPUTS
        input  input_d0;
input  input_d1;
input  input_d2;
input  input_d3;
input  input_d4;
input  input_d5;
input  input_d6;
input  input_d7;
input  sel_0;
input  sel_1;
input  sel_2;
  // OUTPUT
    output  output_y;
    wire    [10:0] mux_comb_out ;
 
  // NOT Gate Instantiation Template
   
not_gate_code U_NOT_GATE1 (
    .input_a(sel_0), 
    .output_y(mux_comb_out[0])
    );
 
 not_gate_code U_NOT_GATE2 (
    .input_a(sel_1), 
    .output_y(mux_comb_out[1])
    );
 
 not_gate_code U_NOT_GATE3 (
    .input_a(sel_2), 
    .output_y(mux_comb_out[2])
    );
 
  // AND Gate Instantiation Template
   and_gate4_code U_AND_GATE1 (
    .input_a(input_d0), 
    .input_b(mux_comb_out[0]), 
    .input_c(mux_comb_out[1]), 
    .input_d(mux_comb_out[2]), 
    .output_y(mux_comb_out[3])
    );
 
 and_gate4_code U_AND_GATE2 (
    .input_a(input_d1), 
    .input_b(sel_0), 
    .input_c(mux_comb_out[1]), 
    .input_d(mux_comb_out[2]), 
    .output_y(mux_comb_out[4])
    );
 
and_gate4_code U_AND_GATE3 (
    .input_a(input_d2), 
    .input_b(mux_comb_out[0]), 
    .input_c(sel_1), 
    .input_d(mux_comb_out[2]), 
    .output_y(mux_comb_out[5])
    );
 
and_gate4_code U_AND_GATE4 (
    .input_a(input_d3), 
    .input_b(sel_0), 
    .input_c(sel_1), 
    .input_d(mux_comb_out[2]), 
    .output_y(mux_comb_out[6])
    );
 
 and_gate4_code U_AND_GATE5 (
    .input_a(input_d4), 
    .input_b(mux_comb_out[0]), 
    .input_c(mux_comb_out[1]), 
    .input_d(sel_2), 
    .output_y(mux_comb_out[7])
    );
 
and_gate4_code U_AND_GATE6 (
    .input_a(input_d5), 
    .input_b(sel_0), 
    .input_c(mux_comb_out[1]), 
    .input_d(sel_2), 
    .output_y(mux_comb_out[8])
    );
 
and_gate4_code U_AND_GATE7 (
    .input_a(input_d6), 
    .input_b(mux_comb_out[0]), 
    .input_c(sel_1), 
    .input_d(sel_2), 
    .output_y(mux_comb_out[9])
    );
 
and_gate4_code U_AND_GATE8 (
    .input_a(input_d6), 
    .input_b(sel_0), 
    .input_c(sel_1), 
    .input_d(sel_2), 
    .output_y(mux_comb_out[10])
    );
 
  // OR Gate Instantiation Template 
    or_gate8_code U_OR_GATE (
    .input_a(mux_comb_out[3]), 
    .input_b(mux_comb_out[4]), 
    .input_c(mux_comb_out[5]), 
    .input_d(mux_comb_out[6]), 
    .input_e(mux_comb_out[7]), 
    .input_f(mux_comb_out[8]), 
    .input_g(mux_comb_out[9]), 
    .input_h(mux_comb_out[10]), 
    .output_y(output_y)
    );
endmodule

// 8 Input OR  Gate is required for above structural design

// Verilog code for 8 input or gate
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:  RED-BLUE
// Engineer: 
// 
// Create Date:    23:19:15 11/08/2016 
// Designer Name:  Madhu krishna
// Module Name:    or_gate8_code 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module or_gate8_code(input_a,
                                      input_b,
      input_c,
      input_d,
      input_e,
      input_f,
      input_g,
      input_h,
      output_y);
  // INPUTS
   input  input_a;  
   input  input_b;  
   input  input_c;  
   input  input_d;  
   input  input_e;  
   input  input_f; 
   input  input_g;  
   input  input_h;  
   
// OUTPUT
output output_y;
//Declaration of 8 input and gate
assign output_y = (input_a | input_b | input_c | input_d | input_e | input_f |input_g |input_h);  
     
 
endmodule

 
---------------------------------------------------------------------------------------------------------------------------------------------------


// Verilog code for 8:1 Multiplexer using behavioural
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: RED-BLUE
// Engineer: 
// 
// Create Date:    21:33:27 11/08/2016 
// Designer Name:  Madhu Krishna
// Module Name:    mux8_1_beh 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module mux8_1_beh( input_d0,
                                    input_d1,
    input_d2,
    input_d3,
    input_d4,
    input_d5,
    input_d6,
    input_d7,
    sel_0,
   sel_1,
   sel_2,
   output_y );
  // INPUTS
        input  input_d0;
input  input_d1;
input  input_d2;
input  input_d3;
input  input_d4;
input  input_d5;
input  input_d6;
input  input_d7;
input  sel_0;
input  sel_1;
input  sel_2;
  // OUTPUT
    output   output_y;
    wire      [2:0] con_out;
    reg        output_y;
  // Declaration 8:1 Multiplexer
  
  assign con_out = {sel_2, sel_1, sel_0};
    always @(*) begin
  if(con_out == 3'b000) begin
 output_y <= input_d0;
     end else if(con_out == 3'b001) begin
 output_y <= input_d1;
     end else if(con_out == 3'b010) begin
 output_y <= input_d2; 
      end else if(con_out == 3'b011) begin
 output_y <= input_d3;
      end else if(con_out == 3'b100) begin
 output_y <= input_d4;
      end else if(con_out == 3'b101) begin
 output_y <= input_d5;
      end else if(con_out == 3'b110) begin
 output_y <= input_d6;
      end else begin
 output_y <= input_d7;
     end
 end 
endmodule  


----------------------------------------------------------------------------------------------------------------------------------------------------------------

// Verilog code for 8:1 Multiplexer using behavioural
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: RED-BLUE
// Engineer: 
// 
// Create Date:    21:33:27 11/08/2016 
// Designer Name:  Madhu Krishna
// Module Name:    mux8_1_beh1 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module mux8_1_beh1( input_d0,
                                      input_d1,
      input_d2,
              input_d3,
      input_d4,
      input_d5,
      input_d6,
              input_d7,
      sel_0,
      sel_1,
      sel_2,
     output_ );
  // INPUTS
        input   input_d0;
input   input_d1;
input   input_d2;
input   input_d3;
input   input_d4;
input   input_d5;
input   input_d6;
input   input_d7;
input   sel_0;
input   sel_1;
input   sel_2;
  // OUTPUT
    output  output_y;
    wire    [2:0] con_out;
    reg       output_y;
 
  // Declaration 8:1 Multiplexer using case
  
  assign con_out  =  {sel_2 ,sel_1,sel_0};
  
    always @(*) begin
  case (con_out)
 3'b000: output_y = input_d0;
 3'b001: output_y = input_d1;
 3'b010: output_y = input_d2;
 3'b011: output_y = input_d3;
 3'b100: output_y = input_d4;
 3'b101: output_y = input_d5;
 3'b110: output_y = input_d6;
 3'b111: output_y = input_d7;
 default: output_y = 1'b0;
      endcase
    end
endmodule
--------------------------------------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment