0

I'm looking to implement Y = (~A & ~B & C) | (A & ~B & ~C) | (~A & B & ~C) within ModelSim 10.7b. The following is what I have in ModelSim.

boolean_function.v

`timescale 1ns/1ps
module boolean_function (Ain, Bin, Cin, Yout);
  input Ain, Bin, Cin;
  output Yout;

  assign Yout = (~Ain & ~Bin & Cin) | (Ain & ~Bin & ~Cin) | (~Ain & Bin & ~Cin);
endmodule

boolean_function_tb.v

`timescale 1ns/1ps
module boolean_function_tb();
  reg Ain, Bin, Cin;
  wire Yout;

  boolean_function bf(.Ain(Ain),.Bin(Bin),.Cin(Cin),.Yout(Yout));

  initial
  begin
    Ain = 0; Bin = 0; Cin = 0;
    #50;
    Ain = 0; Bin = 0; Cin = 1;
    #50;
    Ain = 0; Bin = 1; Cin = 0;
    #50;
    Ain = 0; Bin = 1; Cin = 1;
    #50;
    Ain = 1; Bin = 0; Cin = 0;
    #50;
    Ain = 1; Bin = 0; Cin = 1;
    #50;
    Ain = 1; Bin = 1; Cin = 0;
    #50;
    Ain = 1; Bin = 1; Cin = 1;
    #50;
  end
endmodule

I am able to compile both of the codes but during the simulation, the outputs are all set to zero and do not change regardless of how long the output waveform runs.

I have tried assigning each of the cases seperateley such as:

assign Yout = (~Ain & ~Bin & Cin);
assign Yout = (Ain & ~Bin & ~Cin);
assign Yout = (~Ain & Bin & ~Cin);

This was able to compile as well but the output remained the same.

I have also changed the testbench lines

  Ain = 0; Bin = 0; Cin = 0;

to the format of

  Ain = 0'b0; Bin = 0'b0; Cin = 0'b0;

and this was also able to compile but again provide the same output.

I'm looking to go through all the possible combinations of the three inputs and have the output be equal to one when one of the boolean function's conditions are met.

  • Ain = 0'b0; Bin = 0'b0; Cin = 0'b0; I think you are incorret here when you say. 0'b0 it means that a 0 bit number has a value 0. Which I believe it should be 1'b0 to make sense. Also, in the test bench file it is usually opposite than your code. What I mean is if it is reg in your code the same variable will be wire in your testbench file – Shub Apr 15 at 23:42
  • I see no wrong points in your both codes. Did you run the testbench for enough time? #50 means 50ns, so check your simulator timeline to see it has passed 50ns mark. – csehydrogen Apr 16 at 19:05
  • I changed the code again to Ain = 1'b0; Bin = 1'b0; Cin = 1'b0; and my output didn't change. I ran the testbench over 10,000, but my output still didn't change. I tried the code on a separate computer and got the same results. I'm running Simulink on a Linux machine, so I will probably try it on a Windows machine and see if my output changes. – subject474 Apr 17 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.