EDA Playground lets you type in and run HDL code (using a selection of free and commercial simulators and synthesizers).
It's great for learning HDLs, it's great for testing out unfamiliar things and it's great for sharing code.
You can start typing straight away. But to run your code, you'll need to sign or log in. Logging in with a Google account gives you access to all non-commercial simulators and some commercial simulators:
To run commercial simulators, you need to register and log in with a username and password. Registration is free, and only pre-approved email's will have access to the commercial simulators.
206
module tb_MUX4;
// Declare variables to be connected to inputs as regs
// declared as regs since we want to change them
reg IN0, IN1, IN2, IN3;
reg S1, S0;
// Declare output wires since we are not changing them but only observing them
wire OUTPUT;
// Instantiate the multiplexer, tie the ports
MUX4 mymux1 (
.f(OUTPUT),
.w0(IN0),
.w1(IN1),
.w2(IN2),
.w3(IN3),
.s1(S1),
.s0(S0)) ;
// Stimulate the inputs, set input lines of mux and
initial
begin
IN0=1; IN1=0; IN2=1; IN3=0; // you may change them as you like
for(int i=0; i<4; i=i+1 ) // checking all possible values of S1,S0
begin
#5 {S1, S0}=i;// 00,01,10,11
end
#5 $finish;
end
initial
begin
// dumps all values whenever there is a change in any.
$monitor( IN0, IN1, IN2, IN3, S1, S0,OUTPUT);
// Uncomment the next two lines if you want to see the timing diagram as well
$dumpfile("dump.vcd");// vcd=value change dump
$dumpvars(1); // dump all variables in the wave form
end
endmodule
xxxxxxxxxx
module MUX2(f,s,w0,w1);
input s,w0,w1;
output f;
// Using gate level assignement
wire sn, andout0, andout1;
not (sn,s);
and (andout0, sn,w0);
and (andout1, s ,w1);
or(f,andout0,andout1);
endmodule
module MUX4(f,s0,s1,w0,w1,w2,w3);
input s0,s1,w0,w1,w2,w3;
output f;
wire tmp0,tmp1;
MUX2 M0 (tmp0, s0,w0,w1);
MUX2 M1 (tmp1, s0,w2,w3);
MUX2 M2 (f, s1,tmp0,tmp1);
endmodule
Your account is not validated. If you wish to use commercial simulators, you need a validated account.
If you have already registered (or have recently changed your email address), but have not clicked on the link in the email we sent you, please do so. If you cannot find the email, please check your spam/junk folder. Or click here to resend the email.
If you have not already registered for a full account, you can do so by clicking below. You will then need to provide us with some identification information. You may wish to save your code first.
Creating, deleting, and renaming files is not supported during Collaboration. To encourage development of these features for Collaboration, tweet to @EDAPlayground
This playground may have been modified. Please save or copy before starting collaboration.
Your exercise has been submitted.