Global constants definition problem

Discussion in 'VHDL' started by Weng Tianxiang, Sep 6, 2006.

  1. Hi,
    Help is needed.

    I have some global constants shared among several modules, so I
    set up a file to define a global package like the following:

    Package MG_x_Constant is
    constant DATA_BITS : integer := 16;
    constant DATA_RANGE : real := (2.0**16);
    -- constant DATA_BITS : integer := 64;
    -- constant DATA_RANGE : real := (2.0**64);


    -- used in all test bench
    constant DATABITS : integer := DATA_BITS;

    end MG_x_Constant;

    Package body MG_x_Constant is
    ....
    end MG_x_Constant;

    In other modules, DATA_BITS, DATABITS are freely used.

    This morning I found a problem:
    when I changed DATA_BITS from 16 to 64, the ModelSim
    sim window still shows constant DATABITS = 16 and it never changed,
    even though I tried to delete the module from library and
    re-compile it again. constant DATABITS = 16 doesn't change.

    IN compilation order, the global package definition file is always the
    first one.

    I though if the global constant definition changes, all its appearance
    should change, but it doesn't. Why?

    What is wrong with the above statements?

    Thank you.

    Weng
     
    Weng Tianxiang, Sep 6, 2006
    #1
    1. Advertising

  2. Weng Tianxiang

    Jozsef Guest

    Hello,
    Try to recompile ALL sources which references to this package. I think
    about modelsim don't check & update referenced variables under
    compilation process in other sources.

    Best regards

    Weng Tianxiang wrote:
    > Hi,
    > Help is needed.
    >
    > I have some global constants shared among several modules, so I
    > set up a file to define a global package like the following:
    >
    > Package MG_x_Constant is
    > constant DATA_BITS : integer := 16;
    > constant DATA_RANGE : real := (2.0**16);
    > -- constant DATA_BITS : integer := 64;
    > -- constant DATA_RANGE : real := (2.0**64);
    >
    >
    > -- used in all test bench
    > constant DATABITS : integer := DATA_BITS;
    >
    > end MG_x_Constant;
    >
    > Package body MG_x_Constant is
    > ...
    > end MG_x_Constant;
    >
    > In other modules, DATA_BITS, DATABITS are freely used.
    >
    > This morning I found a problem:
    > when I changed DATA_BITS from 16 to 64, the ModelSim
    > sim window still shows constant DATABITS = 16 and it never changed,
    > even though I tried to delete the module from library and
    > re-compile it again. constant DATABITS = 16 doesn't change.
    >
    > IN compilation order, the global package definition file is always the
    > first one.
    >
    > I though if the global constant definition changes, all its appearance
    > should change, but it doesn't. Why?
    >
    > What is wrong with the above statements?
    >
    > Thank you.
    >
    > Weng
     
    Jozsef, Sep 6, 2006
    #2
    1. Advertising

  3. Jozsef wrote:
    > Hello,
    > Try to recompile ALL sources which references to this package. I think
    > about modelsim don't check & update referenced variables under
    > compilation process in other sources.
    >
    > Best regards
    >
    > Weng Tianxiang wrote:
    > > Hi,
    > > Help is needed.
    > >
    > > I have some global constants shared among several modules, so I
    > > set up a file to define a global package like the following:
    > >
    > > Package MG_x_Constant is
    > > constant DATA_BITS : integer := 16;
    > > constant DATA_RANGE : real := (2.0**16);
    > > -- constant DATA_BITS : integer := 64;
    > > -- constant DATA_RANGE : real := (2.0**64);
    > >
    > >
    > > -- used in all test bench
    > > constant DATABITS : integer := DATA_BITS;
    > >
    > > end MG_x_Constant;
    > >
    > > Package body MG_x_Constant is
    > > ...
    > > end MG_x_Constant;
    > >
    > > In other modules, DATA_BITS, DATABITS are freely used.
    > >
    > > This morning I found a problem:
    > > when I changed DATA_BITS from 16 to 64, the ModelSim
    > > sim window still shows constant DATABITS = 16 and it never changed,
    > > even though I tried to delete the module from library and
    > > re-compile it again. constant DATABITS = 16 doesn't change.
    > >
    > > IN compilation order, the global package definition file is always the
    > > first one.
    > >
    > > I though if the global constant definition changes, all its appearance
    > > should change, but it doesn't. Why?
    > >
    > > What is wrong with the above statements?
    > >
    > > Thank you.
    > >
    > > Weng


    Hi Jozsef,
    I re-compiled every modules, but the constants in global package don't
    change as if they were compiled once and never re-compiled again.

    I even deleted all work directory contents, recompile every modules,
    but constants in the global package still don't change.

    That is what I have experienced.

    Any other ideas?

    Weng
     
    Weng Tianxiang, Sep 6, 2006
    #3
  4. Weng Tianxiang wrote:

    > I even deleted all work directory contents, recompile every modules,
    > but constants in the global package still don't change.


    Maybe they are declared in more than one place.

    -- Mike Treseler
     
    Mike Treseler, Sep 6, 2006
    #4
  5. Mike Treseler wrote:
    > Weng Tianxiang wrote:
    >
    > > I even deleted all work directory contents, recompile every modules,
    > > but constants in the global package still don't change.

    >
    > Maybe they are declared in more than one place.
    >
    > -- Mike Treseler


    Hi MIke,
    Never!

    I tried to move all constant definitions from package entity module to
    package body module, all constants usage are errors.

    Weng
     
    Weng Tianxiang, Sep 6, 2006
    #5
  6. Weng Tianxiang wrote:
    > Mike Treseler wrote:
    > > Weng Tianxiang wrote:
    > >
    > > > I even deleted all work directory contents, recompile every modules,
    > > > but constants in the global package still don't change.

    > >
    > > Maybe they are declared in more than one place.
    > >
    > > -- Mike Treseler

    >
    > Hi MIke,
    > Never!
    >
    > I tried to move all constant definitions from package entity module to
    > package body module, all constants usage are errors.
    >
    > Weng


    Hi,
    Is it possible that the error happens because I have used 2 levels of
    constants:

    constant DATA_BITS : integer := 16; <-- I change this value,
    constant DATABITS : integer := DATA_BITS; <-- this value doesn't
    change

    Weng
     
    Weng Tianxiang, Sep 6, 2006
    #6
  7. On 6 Sep 2006 08:07:21 -0700, "Weng Tianxiang" <> wrote:

    >
    >Jozsef wrote:
    >> Hello,
    >> Try to recompile ALL sources which references to this package. I think
    >> about modelsim don't check & update referenced variables under
    >> compilation process in other sources.


    >> > I have some global constants shared among several modules, so I
    >> > set up a file to define a global package like the following:
    >> >
    >> > Package MG_x_Constant is

    ....
    >> > end MG_x_Constant;


    >> > This morning I found a problem:
    >> > when I changed DATA_BITS from 16 to 64, the ModelSim
    >> > sim window still shows constant DATABITS = 16 and it never changed,
    >> > even though I tried to delete the module from library and
    >> > re-compile it again.


    >I re-compiled every modules, but the constants in global package don't
    >change as if they were compiled once and never re-compiled again.
    >
    >I even deleted all work directory contents, recompile every modules,
    >but constants in the global package still don't change.


    I've just been through something similar. What happened in my case was:

    the package was compiled into a library, and included in my desigh via
    "Library/Use" statements.

    The library was mapped into a particular Modelsim directory, and this
    mapping was stored in modelsim.ini, in the directory where I was working
    on the package.

    Later, when I worked on the design, I found it using an OLD version of
    the package - because its mapping for that library was in a DIFFERENT
    modelsim.ini file (because the design was in a different place from the
    package).

    I got into this mess because this project was a combination of two older
    ones, and not a fresh start.

    This may not be your problem, but it's worth checking the library
    mapping paths in ALL relevant versions of modelsim.ini are what you
    expect.

    - Brian
     
    Brian Drummond, Sep 7, 2006
    #7
  8. Brian Drummond wrote:
    > On 6 Sep 2006 08:07:21 -0700, "Weng Tianxiang" <> wrote:
    >
    > >
    > >Jozsef wrote:
    > >> Hello,
    > >> Try to recompile ALL sources which references to this package. I think
    > >> about modelsim don't check & update referenced variables under
    > >> compilation process in other sources.

    >
    > >> > I have some global constants shared among several modules, so I
    > >> > set up a file to define a global package like the following:
    > >> >
    > >> > Package MG_x_Constant is

    > ...
    > >> > end MG_x_Constant;

    >
    > >> > This morning I found a problem:
    > >> > when I changed DATA_BITS from 16 to 64, the ModelSim
    > >> > sim window still shows constant DATABITS = 16 and it never changed,
    > >> > even though I tried to delete the module from library and
    > >> > re-compile it again.

    >
    > >I re-compiled every modules, but the constants in global package don't
    > >change as if they were compiled once and never re-compiled again.
    > >
    > >I even deleted all work directory contents, recompile every modules,
    > >but constants in the global package still don't change.

    >
    > I've just been through something similar. What happened in my case was:
    >
    > the package was compiled into a library, and included in my desigh via
    > "Library/Use" statements.
    >
    > The library was mapped into a particular Modelsim directory, and this
    > mapping was stored in modelsim.ini, in the directory where I was working
    > on the package.
    >
    > Later, when I worked on the design, I found it using an OLD version of
    > the package - because its mapping for that library was in a DIFFERENT
    > modelsim.ini file (because the design was in a different place from the
    > package).
    >
    > I got into this mess because this project was a combination of two older
    > ones, and not a fresh start.
    >
    > This may not be your problem, but it's worth checking the library
    > mapping paths in ALL relevant versions of modelsim.ini are what you
    > expect.
    >
    > - Brian


    Hi,
    Thank you everyone who gave me an answer.

    The problem is resolved, I would like to share the lesson
    I learned from this experience.

    1. Original code:
    DATABITS_16_32_64 <= 64 when DATABITS = 64 else
    32 when DATABITS = 32 else
    16; -- for data bits between 4-16

    BlockRAM_A: for I in 0 to 2 generate
    BlockRAM_0: BlockRAM
    generic map (
    DATABITS => DATABITS_16_32_64,
    DEPTH => LEVEL_X)
    port map (
    ...
    );
    end generate;

    The problem is the following statement:
    DATABITS_16_32_64 <= 64 when DATABITS = 64 else
    32 when DATABITS = 32 else
    16; -- for data bits between 4-16

    I thought DATABITS_16_32_64 was assigned value before it was used
    in generic map, but it is wrong.

    Because block BlockRAM_A and DATABITS_16_32_64 assignment statement
    are in concurrent area, DATABITS_16_32_64 in generate map (...)
    doesn't use the value it is assigned to in the above statement.
    When loading, ModelSim immediately reports
    error for situation of DATABITS = 16 so that it seems to me that
    global variable DATABITS doesn't change.

    1. The answers everyone gave show unanimously that
    the grammar I used in global file is right;
    2. So I abandoned my original idea to search for other clues.
    3. Luckyly, I found the error after one day rest about the problem.

    The following is the right coding for the segment:

    BlockRAM_A: for I in 0 to 2 generate
    BlockRAM_64 : if DATABITS = 64 generate
    BlockRAM_0: BlockRAM
    generic map (
    DATABITS => 64,
    DEPTH => LEVEL_X)
    port map (
    ...
    );
    end generate;

    BlockRAM_64 : if DATABITS = 32 generate
    BlockRAM_0: BlockRAM
    generic map (
    DATABITS => 32,
    DEPTH => LEVEL_X)
    port map (
    ...
    );
    end generate;

    BlockRAM_64 : if(DATABITS /= 64 and DATABITS /= 32) generate
    BlockRAM_0: BlockRAM
    generic map (
    DATABITS => 16,
    DEPTH => LEVEL_X)
    port map (
    ...
    );
    end generate;
    end generate;

    Thank you.

    Weng
     
    Weng Tianxiang, Sep 7, 2006
    #8
  9. Weng Tianxiang

    jr Guest

    Weng Tianxiang:


    > 1. Original code:
    > DATABITS_16_32_64 <= 64 when DATABITS = 64 else
    > 32 when DATABITS = 32 else
    > 16; -- for data bits between 4-16



    Why do you make DATABITS_16_32_64 a signal? All your problems derive from
    that. It looks like a constant to me.

    Something like this would evaluate before the generic maps:
    constant DATABITS_16_32_64: integer := (((DATABITS-1)/16)+1)*16;

    DATABITS 4 to 16 : DATABITS_16_32_64 is 16
    DATABITS 32 : DATABITS_16_32_64 is 32
    DATABITS 64 : DATABITS_16_32_64 is 64.

    Other cases irrelevant, I assume.

    --
    jr
     
    jr, Sep 7, 2006
    #9
  10. jr wrote:
    > Weng Tianxiang:
    >
    >
    > > 1. Original code:
    > > DATABITS_16_32_64 <= 64 when DATABITS = 64 else
    > > 32 when DATABITS = 32 else
    > > 16; -- for data bits between 4-16

    >
    >
    > Why do you make DATABITS_16_32_64 a signal? All your problems derive from
    > that. It looks like a constant to me.
    >
    > Something like this would evaluate before the generic maps:
    > constant DATABITS_16_32_64: integer := (((DATABITS-1)/16)+1)*16;
    >
    > DATABITS 4 to 16 : DATABITS_16_32_64 is 16
    > DATABITS 32 : DATABITS_16_32_64 is 32
    > DATABITS 64 : DATABITS_16_32_64 is 64.
    >
    > Other cases irrelevant, I assume.
    >
    > --
    > jr


    Hi Jr,
    Wow! Wonderful !!!

    Your answer is very clever and absolute better than mine. I will use
    your code immediately without any conditions.

    I learned a trick from you.

    Thank you very much.

    Weng
     
    Weng Tianxiang, Sep 7, 2006
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. 2obvious

    no global constants in global.asax?

    2obvious, Sep 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,893
  2. Jianli Shen
    Replies:
    1
    Views:
    645
    Victor Bazarov
    Mar 13, 2005
  3. Replies:
    1
    Views:
    406
    Michael Ekstrand
    Aug 21, 2005
  4. Ark
    Replies:
    1
    Views:
    452
    Chris Torek
    Aug 7, 2004
  5. Jon Slaughter
    Replies:
    4
    Views:
    473
    Jon Slaughter
    Oct 26, 2005
Loading...

Share This Page