Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 661955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:19:31+00:00 2026-05-13T23:19:31+00:00

I did a behavioral simulation of my code, and it works perfectly. The results

  • 0

I did a behavioral simulation of my code, and it works perfectly. The results are as predicted. When I synthesize my code and upload it to a spartan 3e FPGA and try to analyze using chipscope, the results are not even close to what I would have expected. What have I done incorrectly?
http://pastebin.com/XWMekL7r

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:19:31+00:00Added an answer on May 13, 2026 at 11:19 pm

    Your problem is with lines 13-16, where you set initial values for state registers:

     reg    [OUTPUT_WIDTH-1:0] previousstate = 0;              
     reg    [OUTPUT_WIDTH-1:0] presentstate = 1;
     reg    [6:0] fib_number_cnt = 1;  
     reg    [OUTPUT_WIDTH-1:0] nextstate = 1; 
    

    This is an equivalent to writing an “initial” statement assigning these values, which isn’t synthesizable — there is no such thing as a default value in hardware. When you put your design inside an FPGA, all of these registers will take on random values.

    Instead, you need to initialize these counters/states inside your always block, when reset is high.

    always @(posedge clk or posedge reset)
      if (reset) begin
         previousstate <= 0;
         presentstate <= 1;
         ... etc ...
      end
    

    Answer to the follow-up questions:

    When you initialize code like that, nothing at all happens in hardware — it gets completely ignored, just as if you’ve put in a $display statement. The synthesis tool skips over all simulation-only constructs, while usually giving you some kind of a warning about it (that really depends on the tool).

    Now, blocking and non-blocking question requires a very long answer :). I will direct you to this paper from SNUG-2000 which is probably the best paper ever written on the subject. It answers your question, as well as many others on the topic. Afterward, you will understand why using blocking statements in sequential logic is considered bad practice, and why your code works fine with blocking statements anyway.

    http://cs.haifa.ac.il/courses/verilog/cummings-nonblocking-snug99.pdf


    More answers:

    The usual “pattern” to creating logic like yours is to have two always blocks, one defining the logic, and one defining the flops. In the former, you use blocking statements to implement logic, and in the latter you latch in (or reset) the generated value. So, something like this:

    wire some_input;
    
    // Main logic (use blocking statements)
    reg state, next_state;
    always @*
      if (reset) next_state = 1'b0;
      else begin
        // your state logic
        if (state) next_state = some_input;
        else next_state = 1'b0;
      end
    
    // Flops (use non-blocking)
    always @(posedge clock)
      if (reset) state <= 1'b0;
      else state <= next_state;
    

    Note that I’m using a synchronous reset, but you can use async if needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Did I not get enough sleep or what? This following code var frame=document.getElementById(viewer); frame.width=100;
I did a sample code in pro*C language to fetch data from a table.
I've recently had a bit of code work perfectly on the simulator, and screw
Did you used Dynamic websites before? you see its a good way for making
Did some searches here & on the 'net and haven't found a good answer
Did you ever have the following situation: you need to store information, but a
Did anyone tried to customize the window in which the quicktime is playing video?
Did about 30 minutes worth of searching, found lots of relevant info, but none
Did not have luck with these examples: Javascript File remove Javascript FSO DeleteFile Method
Did actually someone make already a tutorial that shows how to customize an UITableView?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.