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.

How to get parallel hardware in simulation using case statment?

Status
Not open for further replies.

bharat_in

Member level 4
Joined
Oct 5, 2006
Messages
78
Helped
9
Reputation
18
Reaction score
7
Trophy points
1,288
Activity points
1,716
Till now, i was under impression that case statment will generate non-priority encoder hardware both in simulation and synthesis, but following coding shows that in simulation in works like proirity encoder... :-(

module m ();

wire [3:0] w1 = 4'b1101 ;

initial
begin
#4;
case(1'b1)
w1[0]: $display("0") ;
w1[1]: $display("1") ;
w1[2]: $display("2") ;
w1[3]: $display("3") ;
default: $display("Default") ;
endcase
end

endmodule

Output:
0

I guess, in this case it will have pre-synthesis and post-synthesis simulation mismatch.
Can anyone please explain, how to get parallel hardware in simulation using case statment?
 

nikhilindia85

Member level 4
Joined
Feb 28, 2007
Messages
78
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,712
case statement

initial will be ignored by synthesis tool and display also not synthesizble
try to write synthesizable rtl code
 

fm_com_28

Full Member level 1
Joined
Feb 2, 2006
Messages
99
Helped
11
Reputation
22
Reaction score
7
Trophy points
1,288
Location
Fayoum, Egypt
Activity points
1,916
Re: case statement

What I know is that in VHDL, case statement is a sequential statement not a concurrent, is this the situation for Verilog?
 

pinnacle.chip

Newbie level 1
Joined
Sep 17, 2007
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,286
Re: case statement

When u r talking about synthesis then #4 and $display should not be there in ur RTL.
After u have rectified this, u have should add parallel_case directive specifically for this condition as choice of case statement is variable here. write like this:

case(1'b1) //synopsis parallel_case
w1[0]:
-----
-----
 

cherjier

Member level 5
Joined
Dec 6, 2006
Messages
84
Helped
6
Reputation
12
Reaction score
1
Trophy points
1,288
Activity points
1,909
case statement

copy your code here:
case(1'b1)
w1[0]: $display("0") ;
w1[1]: $display("1") ;
w1[2]: $display("2") ;

i think is ur case condition have some issue.
u try the case statement as follow:

case(w1) //<- here should be w1, not 1'b1
w1[0]: $display("0") ;
w1[1]: $display("1") ;
w1[2]: $display("2") ;
 

foster_cn

Member level 4
Joined
Jan 14, 2003
Messages
73
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,288
Activity points
442
case statement

have you tried with synthesis directive on those
 

bharat_in

Member level 4
Joined
Oct 5, 2006
Messages
78
Helped
9
Reputation
18
Reaction score
7
Trophy points
1,288
Activity points
1,716
Re: case statement

for those who were asking for synthesizable module....

Code:
module m1(w1,a,y);

input wire [3:0] w1;
input wire [3:0] a ;
output reg y;

always @ *
begin
  case(1'b1) 
    w1[0]: y = a[0];
    w1[1]: y = a[1];
    w1[2]: y = a[2];
    w1[3]: y = a[3];
    default: y = 0;
  endcase
end  

endmodule

for w1 = 4'b1001 and a = 4'b0001. In simulation Y evaluates to 1'b1 as w1[0] is 1'b1 and it is having higher priority than others.

Now may question is, if i want to create parallel case in simulation that how can i create it. For synthesis i can specify parallel case directive, but then i will have post-synthesis and pre-synthesis simulation mismatch....
 

shiv_emf

Advanced Member level 2
Joined
Aug 31, 2005
Messages
605
Helped
22
Reputation
44
Reaction score
6
Trophy points
1,298
Activity points
4,106
case statement

U can use constraint to avoid mismatches :)
 

bharat_in

Member level 4
Joined
Oct 5, 2006
Messages
78
Helped
9
Reputation
18
Reaction score
7
Trophy points
1,288
Activity points
1,716
Re: case statement

@shiv_emf
Please, tell me what kind of constrains should i use, in that case?
 

avimit

Banned
Joined
Nov 16, 2005
Messages
413
Helped
91
Reputation
182
Reaction score
23
Trophy points
1,298
Location
Fleet, UK
Activity points
0
Re: case statement

Hi bharat_in,
Let me look at the problem from a straight fwd perspective.
One output Y, may get a value from either of 4 inputs a0, a1, a2, a3,
depending upon 4 other inputs w0, w1, w2 ,w3. OK?

ok 4to1 mux, but you have 4 lines to select(instead 2, which you normally have), i.e 16 input combinations to decide 4 choices for y i.e a0, a1, a2, a3?
4 choices aur 16 select combinations, bahut beinsaafi hai ye ;)

So to have an exact sim/syn match, you may want to re-write your case statement as

Code:
case w1
  4'b0001 :
  4'b0010 :
  4'b0011 :
  4'b0100 :
  .
  .
  4'b1110 :
  4'b1111 :
  default y = 0;
endcase

you decide under these 16 cirumstances clearly, what Y should get.
This is an absolutely parallel code, with no amiguity, and no sim/syn mismatches.

coding it in a way you have done, is technically correct, but is not very explicit, as to what exactly you are after.
Kr,
Avi
https://www.vlsiip.com
 

    bharat_in

    Points: 2
    Helpful Answer Positive Rating

nand_gates

Advanced Member level 3
Joined
Jul 19, 2004
Messages
892
Helped
175
Reputation
350
Reaction score
51
Trophy points
1,308
Activity points
6,838
Re: case statement

This is the way !
Hope this helps!
Code:
module m1(w1,a,y); 
input  [3:0] w1; 
input  [3:0] a ; 
output y; 
       assign y = (a[0] & w[0]) | (a[1] & w[1]) | (a[2] & w[2]) | (a[3] & w[3]);
endmodule
 

    bharat_in

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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top