Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
21615 Discussions

define base types when using enum

Altera_Forum
Honored Contributor II
2,651 Views

I noticed something with using the system verilog enum construct to define the states of a state machine.  

 

If the following syntax is used, Quartus seems to detect the FSM correctly and the Transitions and Encoding shows up in the State Machine Viewer correctly. 

 

enum logic [1:0] {INIT, RD_PTR_BEHIND, RD_PTR_AHEAD} ptrState;  

 

If you do not define the base type of the enum (as shown below) then Quartus will generate logic that works but it either won't detect it as a FSM or it does this weird thing where it shows up in the State Machine Viewer but the transitions tab is blank. (seems like a bug to me) 

 

enum {INIT, RD_PTR_BEHIND, RD_PTR_AHEAD} ptrState;  

 

This last method would have been convenient if it worked since one could then add states as they go along and not have to worry about how many bits its going to take.  

 

The behavior is the same if you use typedef along with enum.
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
1,765 Views

Did you notice this comment in the Altera Software Handbook about System Verilog state machine coding style? 

 

 

--- Quote Start ---  

In Quartus II integrated synthesis, the enumerated type that defines the states for the state machine must be of an unsigned integer type as in Example 10–52. If you do not specify the enumerated type as int unsigned, a signed int type is used by default. In this case, the Quartus II integrated synthesis synthesizes the design, but does not infer or optimize the logic as a state machine. 

--- Quote End ---  

 

 

Suggested definition is: 

 

enum int unsigned { S0 = 0, S1 = 2, S2 = 4, S3 = 8 } state, next_state;
0 Kudos
Altera_Forum
Honored Contributor II
1,765 Views

Thanks! I didn't know about this. I'll have to troll through this document to find other gems. 

 

I still think the behavior I see where the SM Viewer's Transitions Tab page blank is a bug. How can I report that to Altera?
0 Kudos
Altera_Forum
Honored Contributor II
1,765 Views

Inferring a FSM without displaying it correctly in the viewer can be at least considered an inconsistency. I hesiate to call it a bug because FSM inference isn't supported for this syntax according to the Software Manual. 

 

In any case, filing a support request at Altera MySupport is the regular way to report bugs or ask for clarifications.
0 Kudos
Reply