+ Post New Thread
Results 1 to 5 of 5
  1. #1
    Member level 2
    Points: 1,506, Level: 8

    Join Date
    Oct 2005
    Posts
    44
    Helped
    3 / 3
    Points
    1,506
    Level
    8

    while loop depending on input argument

    (cross posting)

    now this is a very basic question:

    The code seen below goes to infinite loop during synthesis, hence my sythesis tool halts (with an error like, "loop has iterated 64 times so i am halting blah blah"). The reason behind this is that "data" is assigned to X (undefined-unknown) and the evaluation (i<data) yields X, and a while loop executes if its condition is X.

    Isn't this an apparent problem? Am i missing some point? What is the workaround?


    module example(data, trig)

    input [4:0] data;
    input trig;
    output out;
    reg out;
    integer i;

    always @ trig
    begin

    out=0;
    i=0;
    while(i<data)
    begin
    out=~out;
    end

    end

    endmodule


    I just need a loop which runs until it hits a variable number given by the user, not until a constant predefined value..

    How to?

    •   AltAdvertisment

        
       

  2. #2
    Full Member level 4
    Points: 3,024, Level: 12

    Join Date
    Jun 2004
    Posts
    229
    Helped
    16 / 16
    Points
    3,024
    Level
    12

    Re: while loop depending on input argument

    hi
    While loop is not synthesiable
    Please re-write your code using synthesiable conditional statement

    thanks



    •   AltAdvertisment

        
       

  3. #3
    Member level 2
    Points: 1,506, Level: 8

    Join Date
    Oct 2005
    Posts
    44
    Helped
    3 / 3
    Points
    1,506
    Level
    8

    Re: while loop depending on input argument

    Quote Originally Posted by haytham
    hi
    While loop is not synthesiable
    Please re-write your code using synthesiable conditional statement

    thanks

    can show me a source stating that while loops are not synthesiable?

    indeed, if while loops were not synthesiable my synthesis tool would generate an error message stating that "it is not supporting while loops and it is not synthesiable". but i do not get such an error message. i get an error message stating that "the loop is not finite".



    •   AltAdvertisment

        
       

  4. #4
    Full Member level 5
    Points: 3,676, Level: 14
    tkbits's Avatar
    Join Date
    Dec 2004
    Posts
    242
    Helped
    39 / 39
    Points
    3,676
    Level
    14

    Re: while loop depending on input argument

    To the synthesizer, a while loop is a macro loop. The number of repetitions must be known at synthesis time.

    Keep in mind that you are describing digital logic. Digital logic is not a computer - it does not have "instructions" that are "executed".

    You implemented a counter as a variable. In digital logic, one implements a counter device that you can start and stop with control signals.

    A free-running counter that doesn't stop looks like this:
    Code:
    register [4:0] i;
    
    always @(posedge clk)
    begin
        i <= i + 1;
    end
    It will "wrap around" when it reaches its maximum value. The clk signal will determine how fast the counter will count. To this basic counter, you add "sequential code" to set what conditions the values will change under, and what values they will change to. In synthesis, "sequential code" is not "sequenced"!


    1 members found this post helpful.

  5. #5
    Full Member level 4
    Points: 3,024, Level: 12

    Join Date
    Jun 2004
    Posts
    229
    Helped
    16 / 16
    Points
    3,024
    Level
    12

    Re: while loop depending on input argument

    Hi
    I am working in the field of digital design for about four years now.
    I saw different designs
    I did never see a while loop used in the RTL because as said in a previous post Hardware is different than Software because the synthesis tool should know the size of hardware at synthesis time.

    In digital world, never use while loop in making yuor design hardware. Use it in Test benches only

    This is an advice, take it or leave it :)

    Welcome in the hardware world.

    Thanks
    Haytham


    1 members found this post helpful.

--[[ ]]--