cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Explorer
Explorer
2,534 Views
Registered: ‎11-06-2011

States Machines vs. If Statements

Hey guys.

 

When I write a code, it's easier for me to think in a "state machine way" as oppose to if statements.

 

My question is, what is safer hardware wise?

 

When I work on Altera FPGAs, I like to keep the code as simple as I can, so the hardware wont mess it up. I don't like changing too many bits at one clock cycle, that's I'm asking this question.

 

Thanks a lot.

 

Assaf.

0 Kudos
1 Reply
Highlighted
Instructor
Instructor
2,532 Views
Registered: ‎07-21-2009

Re: States Machines vs. If Statements

When I write a code, it's easier for me to think in a "state machine way" as oppose to if statements.

 

For sequential logic, state machine code is easier to read and understand than deeply nested IF statements

 

My question is, what is safer hardware wise?

 

If your code is limited to functions supported in the hardware, there is no inherent difference between the two coding styles which is more or less likely to result in "unsafe hardware".  Are you violating datasheet operating limits?  If so, that would indeed be "unsafe hardware".  Does your code describe asynchronous logic?  This, too, would generate "unsafe hardware".

 

When I work on Altera FPGAs, I like to keep the code as simple as I can, so the hardware wont mess it up.

 

If a synthesised design does not operate reliably or does not function as intended, it is almost certainly the designer's doing rather than a result of the hardware 'messing it up'.  This is generally true for both Xilinx FPGAs and non-Xilinx FPGAs.

 

Use a logic simulator to verify and debug logic function.

Use a timing analyser and timing constraints to verify signal timing.

 

If you travel from Tel Aviv to Haifa and you end up in Ashdod instead, do you fault the bus, the road, or the bus driver?

 

I don't like changing too many bits at one clock cycle, that's I'm asking this question.

 

A proper Hardware Design or Verilog course instructor would be able to help you understand why this statement reflects fundamental misunderstanding.

 

-- Bob Elkind

SIGNATURE:
README for newbies is here: http://forums.xilinx.com/t5/New-Users-Forum/README-first-Help-for-new-users/td-p/219369

Summary:
1. Read the manual or user guide. Have you read the manual? Can you find the manual?
2. Search the forums (and search the web) for similar topics.
3. Do not post the same question on multiple forums.
4. Do not post a new topic or question on someone else's thread, start a new thread!
5. Students: Copying code is not the same as learning to design.
6 "It does not work" is not a question which can be answered. Provide useful details (with webpage, datasheet links, please).
7. You are not charged extra fees for comments in your code.
8. I am not paid for forum posts. If I write a good post, then I have been good for nothing.
0 Kudos