-2

I am using Aldec Active HDL Simulator and I am Trying to access an array in my verilog code. When I simulate it, it gives:

XXXXXXX (unknown in hold and outb2 variable ).

Both hold and outb are array.

Here is my code (Design Block)----

module design_blk(input wire clk,input wire sw1,input wire sw2,input wire sw3,input wire start,output reg[7:0 ]out,output reg rs,output reg rw,output reg en);  

//Slow Clock Instance
wire sclk;
sender send1(clk,sclk);     

//Releated to Braun Multiplier
reg [3:0]a=4'b0000;
reg [3:0]b=4'b0000;
wire [7:0]outb;
reg[7:0]outb2[255:0]; //use for holdin outb value
reg[7:0]hold[255:0];//Used for Holding Output/Return of Function
braun sd(.x(a),.y(b),.out(outb));

integer state5=0;  //State for start checking

//Integer for Array for a & b
integer s=0;

reg cnt=1'b0;

always @(posedge sclk)
begin 
  //Fault Checking Condition
  if( (start==1'b0) & (sw3==1'b0) & (cnt==1'b0))
  begin
    case(state5)
    0:begin
      a<=4'b1000;
      s<=s+1;
      b<=b + 1'b1;
      hold[s]<=ora(a,b);
      $display("hold=%b and s=%d",hold[s],s);
      outb2[s]<=outb;
      $display("outb2=%band s=%d",outb2[s],s);

      if(s!=15)
      begin
        state5<=0;
      end

      else if(s==15)
      begin                                              
        state5<=1;
      end
    end

    1:begin
      a<=4'b0001;
      s<=s+1;
      b<=b+ 1'b1;
      hold[s]<=ora(a,b);
      $display("hold=%b and s=%d",hold[s],s);
      outb2[s]<=outb;
      $display("outb=%b and s=%d",outb2[s],s);

      if(s!=31)
       begin
       state5<=1; 
      end

      else if(s==31) 
      begin   
        cnt<=1'b1; 
        $display("I am in last s=%d",s);

      end  
    end             


    endcase
  end //if end


end//always end

//Function For ORA Checking Purpose......         
function  [7:0]ora (input reg [3:0]X,input reg [3:0]Y);
  begin 
    $display("X=%b & Y=%b",X,Y);
    //Positive-Positive Operations
    ora=X * Y;
  end
endfunction

endmodule

and here is my another file of Counter(i named it sender.v) file-

`timescale 1ns / 1ps

module sender(input wire clkin, output reg clkout);
 reg [2:0]tmp=3'b000;

//Delay Generation////////

always@(posedge clkin)
 begin 
  tmp <= tmp+1'b1;
  clkout<=tmp[2];
 end
endmodule

and the file of Multiplier(Braun Multiplier) is here-

module braun(x,y,out);
input wire [3:0]x;
input wire [3:0]y; //Input/Output Port Declarations
output [7:0]out;
wire [5:0]a;
wire [8:0]b;
wire [5:0]sa;
wire [1:0]cc;
//If we place 1'b0 in place of "zero"then this was not work so we use this...
wire k[8:0];

//There are 16 And Gates used here....
and a1(out[0],x[0],y[0]);
and a2(a[0],x[1],y[0]);
and a3(a[1],x[2],y[0]);
and a4(a[2],x[3],y[0]); 
and a5(b[0],x[0],y[1]);
and a6(b[1],x[1],y[1]);
and a7(b[2],x[2],y[1]);
and a8(a[3],x[3],y[1]);
and a9(b[3],x[0],y[2]);
and a10(b[4],x[1],y[2]);
and a11(b[5],x[2],y[2]);
and a12(a[4],x[3],y[2]);
and a13(b[6],x[0],y[3]);
and a14(b[7],x[1],y[3]);
and a15(b[8],x[2],y[3]);
and a16(a[5],x[3],y[3]);

//There are 12 Full Adder used here....
full_adder f1(out[1],k[0],a[0],b[0],1'b0);
full_adder f2(sa[0],k[1],a[1],b[1],1'b0);
full_adder f3(sa[1],k[2],a[2],b[2],1'b0);
full_adder f4(out[2],k[3],sa[0],b[3],k[0]);
full_adder f5(sa[2],k[4],sa[1],b[4],k[1]);
full_adder f6(sa[3],k[5],a[3],b[5],k[2]);
full_adder f7(out[3],k[6],sa[2],b[6],k[3]);
full_adder f8(sa[4],k[7],sa[3],b[7],k[4]);
full_adder f9(sa[5],k[8],a[4],b[8],k[5]);
full_adder f10(out[4],cc[0],sa[4],k[6],1'b0);
full_adder f11(out[5],cc[1],sa[5],k[7],cc[0]);
full_adder f12(out[6],out[7],a[5],k[8],cc[1]);

endmodule

module full_adder(output reg sum,output reg carry,input wire a,input wire b,input wire c);

always@(a,b,c)
begin
  case({a,b,c})
    3'b000:begin
             sum=1'b0;
             carry=1'b0;
           end
    3'b001:begin
             sum=1'b1;
             carry=1'b0;
           end
    3'b010:begin
             sum=1'b1;
             carry=1'b0;
           end
    3'b011:begin
             sum=1'b0;
             carry=1'b1;
           end
    3'b100:begin
             sum=1'b1;
             carry=1'b0;
           end
    3'b110:begin
             sum=1'b0;
             carry=1'b1;
           end
    3'b111:begin
             sum=1'b1;
             carry=1'b1;
            end
    3'b101:begin
             sum=1'b0;
             carry=1'b1;
           end
  endcase
end

endmodule

and the Testbench code is here-

module top;
reg start;
reg sw3;
reg clk=1'b0;

lcdfgh lcd(clk,,,sw3,start,,,,);    

initial
 begin
 sw3=1'b0;
 start=1'b0;
 end

always
    begin

#20 clk=!clk;
    end


endmodule

Simulator Gives this Error-

# KERNEL: hold=xxxxxxxx
# KERNEL: outb2=xxxxxxxx

What does the error mean?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Rocky_s
  • 1
  • 3

2 Answers2

0

I didn't go through all you code, it is a little bit hard to be understand. But what I want to say is you simulator should have the capability to trace 'X'. Trace the driver back from the first 'X' you found. Good Look.

enchanter
  • 884
  • 8
  • 20
  • sir how can i trace "X" in simulator ? and in which simulator this capability is present...Can you tell me some names...Thanks – Rocky_s Mar 17 '14 at 09:24
  • I have use Active HDL for ages. I'm sure simulators from Mentor/Synopsys/Cadence all have that feature. You should check the manual of your one. But the normal way to do it is all the signal with 'X' value to the waveform and right click the mouse should have option for that. Or you can check the tool bar or menu bar. – enchanter Mar 17 '14 at 22:55
0

s goes out of range for the index of hold and outb2. Add s your display message and you'll see s is greater than 255 (the max index of hold and outb2) when Xs are read out. Out of range assignments will never assign anything. When reading from out of range, the value will always be the default value of the type. The default value of a reg is X.

Other issue: Non-blocking assignment (<=) should be use when assigning sequential logic.

Greg
  • 18,111
  • 5
  • 46
  • 68
  • Now i change my code and use non blocking assignment but it doesn't change XXXX......Sir is there any race condition are present in my code.........and if present then how to remove it i am new in verilog...help me.......and your another suggestion for changing "s"....... I am now try to change it(s) according to your suggestion.... – Rocky_s Mar 18 '14 at 05:32
  • sir after applying your suggestion of (1)Using Non-Blocking assignment and (2)Making s<255 so that it not go out of the range.. i now able to see value using $display task but sir still XXXXX is shows in waveform windows...........help me – Rocky_s Mar 18 '14 at 12:09
  • @Rocky_s, you haven't shown your changes. If I had to guess, `disable` does not work the way you think it does. `disable` kills the current process thread and `@(posedge sclk)` spawns another. Try setting `cnt` to 1 instead of using `disable`. – Greg Mar 18 '14 at 18:06
  • Sir now i modified "design block" according to your suggestion please check it but sir i dont now what happen it not working now even it not display value of "outb2" and "hold" even using $display.....sir but yesterday when i use s<=31 in place of cnt==1'b1 and adding s<=0 inside in else if(s=31) then it display value of both outb2 and hold but only using $display and also change it value from 0-31 then 0-31 in this fashion ....i am blank now and not now what to do....help sir – Rocky_s Mar 20 '14 at 07:53
  • You do not full understand the concepts of blocking vs non-blocking assignments, or why and when each should be used. I suggest reading: http://www.sunburst-design.com/papers/CummingsSNUG2000SJ_NBA.pdf – Greg Mar 20 '14 at 15:33
  • Sir i have read all the 24 pages of the the documents("Nonblocking assignment that kill") including the most important "8 coding guidelines" and the "Strategic Event Queue" and after reading and comparing my code with Document i have found no guideline violations sir..............now i realize that something is wrong with the storing of Instance output that is "outb" and also with function output that is "hold".........sir can you tell me that is this the wrong way to store variable of "Instance(Braun) and output of function inside always block or inside case statement....please help – Rocky_s Mar 22 '14 at 11:17