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.

[SOLVED] problem with a simple verilog code

Status
Not open for further replies.

saad

Advanced Member level 4
Joined
Jun 8, 2005
Messages
101
Helped
10
Reputation
20
Reaction score
7
Trophy points
1,298
Location
Pakistan
Activity points
2,080
Dear all, I am an intermediate-level verilog programmer. I was out of touch with Verilg programming so not really sure whats wrong with the following piece of verilog code.

Code:
module single_bit(
    input [1:0] a,
    input index, 
    output out);
 	 reg out;
	 always @ index
		out = a[index];
endmodule

and the test bench:
Code:
module test_single_bit;

	reg [1:0] a;
	reg index;
             wire out;

	single_bit uut (
		.a(a), 
		.out(out), 
		.index(index));

	initial begin
		#100
		a = 2'b01;
		index = 1'b0;
		
		#100;
		index = 1'b1;
		end      
endmodule

when I simulate it using xilinx ISE 13.1,

a remains 'zz' for all the time
index remains 'z' for all the time
out remains 'x' for all the time

Variables do no change their value even once. What could be the possible problem?

Thanks in advanced

Saad
 

I believe you're trying to assign different values at the same time #100, which is resolved to Z.
 

you assign input values after 100 time units, if by chance the default
simulation time is the same or shorter you will get the results described;
change:
initial begin
#100
a = 2'b01;
index = 1'b0;

to
initial begin
a = 2'b01;
index = 1'b0;

---
have fun
 

you assign input values after 100 time units, if by chance the default
simulation time is the same or shorter you will get the results described;
change:
initial begin
#100
a = 2'b01;
index = 1'b0;

to
initial begin
a = 2'b01;
index = 1'b0;

---
have fun

i m using `timescale 1ns / 1ps and simulation is running for 1000ns = 1µs.

so that removing #100 from the start did not work!!

what else could be wrong.. this simple thing is driving me crazy :evil:

Saad
 

I run your example in Questasim and as expected first 100ns are red 'Xs'
then looks ok, I'm afraid I can't help more;
----
 

HTML:
module test_single_bit;

	reg [1:0] a;
	reg index;
             wire out;

	single_bit uut (
		.a(a), 
		.out(out), 
		.index(index));

	initial begin
		#100
		a = 2'b01;
		index = 1'b0;
		
		#100
		index = 1'b1;
		end      
endmodule

Remove the semicolon, you will see expected results in ISIM
 

Remove the semicolon, you will see expected results in ISIM

which semicolon?? I removed all of them in the stimulus but its behaving the same way.. :-(
 
Last edited:

module test_single_bit;

reg [1:0] a;
reg index;
wire out;

single_bit uut (
.a(a),
.out(out),
.index(index));

initial begin
#100
a = 2'b01;
index = 1'b0;

#100
index = 1'b1;
end
endmodule

The above code works for me in ISIM. Its suprising why you are seeing Hi-Z on the inputs.
 

The above code works for me in ISIM. Its suprising why you are seeing Hi-Z on the inputs.

I dont know whats wrong. I have previously used modelsim. Are there any simulation/project settings specific to ISIM, which might be causing problems for me?
 

when in doubt, rebuild the project.
 
  • Like
Reactions: saad

    saad

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top