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.
204
package ABC;
class decoder;
randc logic [3:0] binary_in;
rand bit enable;
constraint c1 {binary_in < 15;};
endclass
endpackage
module tb_decoder();
import ABC::decoder;
decoder d2=new();
reg [3:0] in,en;
wire [15:0] decoder_out;
decoder_using_case d1(in,decoder_out,en);
initial begin
for(int i=0;i<16;i++)
begin
d2.randomize();
in = d2.binary_in;
en = d2.enable;
#10;
$display("enable = %d, decoder input = %h and output = %h", en,d2.binary_in, decoder_out);
end
end
endmodule
xxxxxxxxxx
// Code your design here
// Code your design here
module decoder_using_case (
input bit [3:0] binary_in , // 4 bit binary input
output reg [15:0] decoder_out , // 16-bit out
input bit enable // Enable for the decoder
);
always_comb
begin
decoder_out = 0;
if (enable==1) begin
case (binary_in)
4'h0 : decoder_out = 16'h0001;
4'h1 : decoder_out = 16'h0002;
4'h2 : decoder_out = 16'h0004;
4'h3 : decoder_out = 16'h0009;
4'h4 : decoder_out = 16'h0010;
4'h5 : decoder_out = 16'h0020;
4'h6 : decoder_out = 16'h0040;
4'h7 : decoder_out = 16'h0080;
4'h8 : decoder_out = 16'h0100;
4'h9 : decoder_out = 16'h0200;
4'hA : decoder_out = 16'h0400;
4'hB : decoder_out = 16'h0800;
4'hC : decoder_out = 16'h1000;
4'hD : decoder_out = 16'h2000;
4'hE : decoder_out = 16'h4000;
4'hF : decoder_out = 16'h8000;
endcase
a1: assert (^decoder_out==1);
end
end
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.