Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

[SOLVED] Sate assignment VHDL versus Verilog

Status
Not open for further replies.

mdep87

Newbie level 2
Joined
May 11, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
I have a question about implementing an FSM in Verilog. In VHDL, we assign states using a type:

type state is (s1,s2,s3);

the only way I can see to do something like this in verilog is with parameters:

parameter s1=2'b00, s2=2'b01, s3=2'b10;

this implementation seems very lacking to me for couple reasons. If I go back and add more states, I could end up needing more bits. I could end up needing to modify the declaration of 128 states to add number 129, etc.

More importantly, optimal state assignment is not a trivial problem. Different state assignments can have significant impact on power, area and speed of a design. In the VHDL case, the synthesizer can assign the states according to an optimization algorithm, whereas when I write the code, states are just going to be added in the order I think of them, practically guaranteeing a sub-optimal assignment.

Sorry for the long lead-in. My basic question is:
How do I write a verilog FSM that allows the compiler to assign states? I'm using synplify, if anyone is aware of a compiler directive for this.

Matthew
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,489
Helped
14,048
Reputation
28,351
Reaction score
12,706
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,162
the only way I can see to do something like this in verilog is with parameters
It's Verilog.
More importantly, optimal state assignment is not a trivial problem. Different state assignments can have significant impact on power, area and speed of a design. In the VHDL case, the synthesizer can assign the states according to an optimization algorithm, whereas when I write the code, states are just going to be added in the order I think of them, practically guaranteeing a sub-optimal assignment.
Fortunately, most synthesis tools will simply ignore your hand coded enumeration and code state variables according to their default FSM coding style (mostly one hot), unless you explicitely specified a particular style through synthesis attributes or another means. But I'm not aware how it's handled in Synplify, you should check the user's manual.
 
  • Like
Reactions: mdep87

    mdep87

    points: 2
    Helpful Answer Positive Rating

atulaxc

Member level 1
Joined
Jan 25, 2010
Messages
39
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,467
Lets use example at this link
The case statement at that link can be modified to use parameters
// Declare parameters soon after Inputs/Outputs declaration
parameter S1 = 10, S2= 11,S3 = 12, S4= 13, S5 = 14, S6= 15;
// Replace the values with parameters
case (r_count)
S1 : begin
packet_in = 'haa; wr_en = 'b1; end
S2 : begin
packet_in = 'hbb; wr_en = 'b1; end
S3 : begin
packet_in = 'hcc; wr_en = 'b1; end
S4 : begin
packet_in = 'hdd; wr_en = 'b1; end
S5: begin
packet_in = 'hee; wr_en = 'b1; end
S6 : begin
packet_in = 'hff; wr_en = 'b1; end
default: begin
packet_in = 'd0; wr_en = 'd0; end
endcase end

Note Referred the example from fullchipdesign.com/verilogtb.htm
 

mdep87

Newbie level 2
Joined
May 11, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
Wow, I didn't expect a response so quickly. Thanks, FvM! That answered my question. The idea of hand-coding state values just seemed ludicrous. It's still annoying to have to assign a number to each state that will just be ignored anyways, but as you said, It's verilog. I'm going to mark this as solved.

atulaxc, thanks for taking the time to respond. Your answer didn't really address my question though. I know about using parameters, I wanted a way to do an FSM without explicit assignments.

Matthew
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top