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.

[Help] write a complete RTL description for a ROM module

Status
Not open for further replies.

lee_trieu

Newbie level 6
Newbie level 6
Joined
Nov 5, 2012
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,355
Hi everybody !
I have a problem with my below lesson.
Code:
Write a complete RTL description for a ROM module by using 
a one-dimensional array and a Verilog reg data type and a case statement. 
  [ATTACH=CONFIG]82400._xfImport[/ATTACH]
The memory was modeled  as  a ROM, which  is  a  constant;  therefore,  you were 
required to assign values at the time of declaration. 
This  lab  comprises  three  primary  steps:  You  will  create  a  one  dimensional 
memory array using case statement; create a testbench with the Verilog testbench 
wizard  in  the  simulation  software;  finally,  verify  the  logic  structure  and 
functionality by running a simulation and examining the resulting waveforms.
hope you help me in this lab.
thank you very much !
(ps:I'm sorry, my english so bad !)
 

what have you written so far?

I still write RTL code for this lab, but I don't understand my code.
can you help me solve my problem ?
and this is my code (not for this lab, The first I want to understand this code )
Code:
module and_or(
in1,
in2, 
in3, 
in4, 
out 
); 
  input in1;
  input in2;
  input in3;
  input in4;
  output out;
  wire in1,in2,in3,in4;
  wire tmp1,tmp2; // temp var
  and(tmp1,in1,in2);
  and(tmp2,in3,in4);
  or(out,tmp1,tmp2);
endmodule
I have problems in testbench code for code above .
And this is my testbench code:
Code:
`timescale 1ms/1ms
`include "lab1.v" //include lab above
module tb_lab2;
  reg in1,in2,in3,in4;
  wire out;
  initial begin
    $monitor("in1=%b\tin2=%b\tin3=%b\tin4=%b\tout=%b", 
    in1, in2,in3,in4,out);
    in1=1;
    in2=1;
    in3=1;
    in4=1;
   #1 in1=1;
   #1 in2=0;
   #1 in3=1;
   #1 in4=1;
end
endmodule

Hope you help me ! thanks !
 

Code:
module and_or(
in1,
in2, 
in3, 
in4, 
out 
); 
  input in1;
  input in2;
  input in3;
  input in4;
  output out;
  wire in1,in2,in3,in4;
  wire tmp1,tmp2; // temp var
  and(tmp1,in1,in2);
  and(tmp2,in3,in4);
  or(out,tmp1,tmp2);
endmodule

What exactly don't you understand about this code. Please be specific.

FWIW it computes the following boolean equation: out = (in1 AND in2) OR (in3 AND in4)

Code:
`timescale 1ms/1ms
`include "lab1.v" //include lab above
module tb_lab2;
  reg in1,in2,in3,in4;
  wire out;
  initial begin
    $monitor("in1=%b\tin2=%b\tin3=%b\tin4=%b\tout=%b", 
    in1, in2,in3,in4,out);
    in1=1;
    in2=1;
    in3=1;
    in4=1;
   #1 in1=1;
   #1 in2=0;
   #1 in3=1;
   #1 in4=1;
end
endmodule

This TB code just applies a 1 to all the inputs at time 0 and changes only in2 to 0 2ms into the simulation.

Regards,
-alan
 

Code:
What exactly don't you understand about this code. Please be specific.

FWIW it computes the following boolean equation: out = (in1 AND in2) OR (in3 AND in4)
[/QUOTE]
thanks u so much !In above lab, I have designed success.
and thís is result ficgure
[ATTACH=CONFIG]82465._xfImport[/ATTACH]
[QUOTE="ads_ee, post: 1160147, member: 486795"]
[CODE]
`timescale 1ms/1ms
`include "lab1.v" //include lab above
module tb_lab2;
  reg in1,in2,in3,in4;
  wire out;
  initial begin
    $monitor("in1=%b\tin2=%b\tin3=%b\tin4=%b\tout=%b", 
    in1, in2,in3,in4,out);
    in1=1;
    in2=1;
    in3=1;
    in4=1;
   #1 in1=1;
   #1 in2=0;
   #1 in3=1;
   #1 in4=1;
end
endmodule

This TB code just applies a 1 to all the inputs at time 0 and changes only in2 to 0 2ms into the simulation.

Regards,
-alan

And main problem i have was :

i can't write exactly testbench code for above lab.
look at the picture I attached, please !
and this is simulation result:
result.png
(I using MoudleSim Software for my lab)
I think if i set
in1=1,in2=1 , in3=1,in4=1
the Out must be out=1 >??
but it is "X" ! Hope you helpme got it ! thanks u very much !
 

Didn't catch this earlier, but you forgot to add your and_or instance in the TB. There is nothing driving the out signal.

Put the and_or instantiation between the end and endmodule statments.

Regards,
-alan
 

Didn't catch this earlier, but you forgot to add your and_or instance in the TB. There is nothing driving the out signal.

Put the and_or instantiation between the end and endmodule statments.

Regards,
-alan
Did you mean like this right?

Code:
`timescale 1ms/1ms
`include "lab1.v" //include lab above
module tb_lab2;
  reg in1,in2,in3,in4;
  wire out;
  initial begin
    $monitor("in1=%b\tin2=%b\tin3=%b\tin4=%b\tout=%b", 
    in1, in2,in3,in4,out);
    in1=1;
    in2=1;
    in3=1;
    in4=1;
   #1 in1=1;
   #1 in2=0;
   #1 in3=1;
   #1 in4=1;
end

module and_or(
in1,
in2, 
in3, 
in4, 
out 
); 
  input in1;
  input in2;
  input in3;
  input in4;
  output out;
  wire in1,in2,in3,in4;
  wire tmp1,tmp2; // temp var
  and(tmp1,in1,in2);
  and(tmp2,in3,in4);
  or(out,tmp1,tmp2);
endmodule


endmodule
I think I Included "lab.v" to testbench code ?? please tell me why do that ?? thanks u so much !
 

You can't embed a module inside another module. That isn't how you add an instance of a module. I think you might want to read some of the verilog tutorials on the net to supplement your class.

I also noticed that you have no function definition for the and and or statements. Are these supposed to be functions or are they instances of a module and... and a module or... in a library or something?

Well for both the new module and the and and or modules (if they aren't functions)...

The syntax is supposed to be:
module_name instance_name (the_ordered_list_of_assignments_separated_by_commas);

e.g.
and u_and (tmp1, in1, in2);

I prefer named association though:

Code Verilog - [expand]
1
and u_mygate (.out(tmp1, .a(in1), .b(in2)); // assuming the [B]and[/B] module ports are: module and (output out, input a, input b)



Think of instances as components on a PCB and the wire declarations are your net names of the routing between components. So you need component the_u_number_identifier (list_of_the_ connections) to hook up the board. :)

Regards,
-alan
 
You can't embed a module inside another module. That isn't how you add an instance of a module. I think you might want to read some of the verilog tutorials on the net to supplement your class.

I also noticed that you have no function definition for the and and or statements. Are these supposed to be functions or are they instances of a module and... and a module or... in a library or something?

Well for both the new module and the and and or modules (if they aren't functions)...

The syntax is supposed to be:
module_name instance_name (the_ordered_list_of_assignments_separated_by_commas);

e.g.
and u_and (tmp1, in1, in2);

I prefer named association though:

Code Verilog - [expand]
1
and u_mygate (.out(tmp1, .a(in1), .b(in2)); // assuming the [B]and[/B] module ports are: module and (output out, input a, input b)



Think of instances as components on a PCB and the wire declarations are your net names of the routing between components. So you need component the_u_number_identifier (list_of_the_ connections) to hook up the board. :)

Regards,
-alan
Oh ! If I want to include module AND_OR to my testbench ,how do this ??
 

I gave you an example with the and gate...

I'm not going to do your homework for you. :)

Regards,
-alan
 
I gave you an example with the and gate...

I'm not going to do your homework for you. :)

Regards,
-alan

Hi !
I written RTL code for ROM module
but I don't known how to write a testbench for it.
hope you help me, solve this problem.
this my code:
Code:
module rom_using_case (
  address , // address input
  data    , //  data output
  read_en , // read enable
  clk        //Clock
  );
  input [3:0] address;
  output [7:0] data;
  input read_en;
  input clk;
  
  reg [7:0] data ;
         
  always @ (clk or read_en or address)
  begin
    case (address)
      0 : data = 10;
      1 : data = 25;
      2 : data = 34;
      3 : data = 66;
      4 : data = 98;
      5 : data = 163;
      6 : data = 178;
      7 : data = 184;
      8 : data = 196;
      default : data =0;
    endcase
  end
  
 endmodule
I want to write a testbench code like as:
- when I input address, the output = data(address)
for example:
Input(address) = 4 => (data) 98
Input(address) = 6 => (data) 178
Input(address) = 7 => (data) 184

etc

Hope you help me solve my problem ! thanks
 

I see some pretty basic stuff that you don't seem to have grasped.

I think you should invest some time in reading some of the basic tutorials on Verilog that are around on the web. Try google with "Verilog tutorial"

Code:
  always @ (clk or read_en or address)
  begin
    case (address)
      0 : data = 10;
      1 : data = 25;
      2 : data = 34;
      3 : data = 66;
      4 : data = 98;
      5 : data = 163;
      6 : data = 178;
      7 : data = 184;
      8 : data = 196;
      default : data =0;
    endcase
  end

In that block of code it looks like you want to have a registered data output, but you wrote the always block as combinatorial. You also included the signal read_en that you aren't even using in the block.

Hint1: in a registered always block you don't need to include any signals other than the clock and if required an asyncrhonous set/reset as the block should only be scheduled on a clock edge or when the asynchronous set/reset goes active. Try looking over a Verilog tutorial for ideas on how to do this.
Hint2: use an if statement to decide what to do when the read is enabled or disabled.

you should define the width of those decimal numbers in the case statement for both the address selected and the data assignment. What you have will compile and synthesize but you'll see a lot of warnings due to the width conversion as integers have a default of 32-bits and they will be truncated to fit the data width and the address comparison width.

Regards,
-alan
 

I see some pretty basic stuff that you don't seem to have grasped.

I think you should invest some time in reading some of the basic tutorials on Verilog that are around on the web. Try google with "Verilog tutorial"

Code:
  always @ (clk or read_en or address)
  begin
    case (address)
      0 : data = 10;
      1 : data = 25;
      2 : data = 34;
      3 : data = 66;
      4 : data = 98;
      5 : data = 163;
      6 : data = 178;
      7 : data = 184;
      8 : data = 196;
      default : data =0;
    endcase
  end

In that block of code it looks like you want to have a registered data output, but you wrote the always block as combinatorial. You also included the signal read_en that you aren't even using in the block.

Hint1: in a registered always block you don't need to include any signals other than the clock and if required an asyncrhonous set/reset as the block should only be scheduled on a clock edge or when the asynchronous set/reset goes active. Try looking over a Verilog tutorial for ideas on how to do this.
Hint2: use an if statement to decide what to do when the read is enabled or disabled.

you should define the width of those decimal numbers in the case statement for both the address selected and the data assignment. What you have will compile and synthesize but you'll see a lot of warnings due to the width conversion as integers have a default of 32-bits and they will be truncated to fit the data width and the address comparison width.

Regards,
-alan
Thank for you idea !
this is request of my lab
Code:
Write a complete RTL description for a ROM module b
a one-dimensional array and a Verilog reg data type and a case statement. 
and testbench for thís lab
I'm just start study Verylog, therefore i can't understand everything, so I want to exchange something with everyone in our forum.
hopr everybody help me complete my lesson ! thanks all !
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top