Question about conditional assignment

Discussion in 'VHDL' started by Rebecca, Mar 23, 2007.

  1. Rebecca

    Rebecca Guest

    Hello, all

    I want to implement the following logic
    if(C_ControlBits=0) then
    NULL;
    else
    Addr(C_ControlBits-1 downto 0) <= (others=>'0');
    end if;
    Because C_ControlBits-1 will become -1 when C_ControlBits=0.
    C_ControlBits is declared as constant in my design. But what's the
    synthesizable VHDL code for this? I tried to put it into process but
    failed.

    Thanks for any hints,
    Rebecca
    Rebecca, Mar 23, 2007
    #1
    1. Advertising

  2. Rebecca

    Jim Lewis Guest

    Rebecca,
    I would have to see more code to make a reasonable guess, so
    instead I will make a blind guess. Often in a process
    I find it handy to first initialize the entire array to
    0 and then later over-write only the bits I need to set.

    In this situation I would replace the conditional code
    with:
    Addr <= (others=>'0');
    Addr(C_ControlBits+3 downto C_ControlBits) <= "1111" ;


    Cheers,
    Jim

    > Hello, all
    >
    > I want to implement the following logic
    > if(C_ControlBits=0) then
    > NULL;
    > else
    > Addr(C_ControlBits-1 downto 0) <= (others=>'0');
    > end if;
    > Because C_ControlBits-1 will become -1 when C_ControlBits=0.
    > C_ControlBits is declared as constant in my design. But what's the
    > synthesizable VHDL code for this? I tried to put it into process but
    > failed.
    >
    > Thanks for any hints,
    > Rebecca
    >
    Jim Lewis, Mar 23, 2007
    #2
    1. Advertising

  3. On 23 Mar 2007 10:34:22 -0700, "Rebecca" <>
    wrote:

    >Hello, all
    >
    >I want to implement the following logic
    > if(C_ControlBits=0) then
    > NULL;
    > else
    > Addr(C_ControlBits-1 downto 0) <= (others=>'0');
    > end if;
    >Because C_ControlBits-1 will become -1 when C_ControlBits=0.
    >C_ControlBits is declared as constant in my design. But what's the
    >synthesizable VHDL code for this? I tried to put it into process but
    >failed.
    >
    >Thanks for any hints,


    Another wild guess...
    look at "if ... generate" and "for ... generate"

    - Brian
    Brian Drummond, Mar 24, 2007
    #3
  4. Rebecca

    Rebecca Guest

    Jim:

    I want to implement this
    Addr(15 downto C_controlBits) <= SignalB;
    if(C_ControlBits=0) then
    NULL;
    else
    Addr(C_ControlBits-1 downto 0) <= (others=>'0');
    end if;



    And your suggestion is what I can use.
    But is that a good idear to overwite it? I know it is handy, but would
    it cause problem for syncrounous design because it induces extra delay/
    unstable phases and then probably data hazard?

    Thanks,
    Hongyan
    Rebecca, Mar 26, 2007
    #4
  5. Rebecca

    Rebecca Guest

    Sorry I didn't describe it clear, Brian. What I want to implement is

    Addr(15 downto C_controlBits) <= SignalB;
    if(C_ControlBits=0) then
    NULL;
    else
    Addr(C_ControlBits-1 downto 0) <= (others=>'0');
    end if;

    I can't use the generated stuff here.

    Thank you,
    Rebecca
    Rebecca, Mar 26, 2007
    #5
  6. Rebecca

    Rebecca Guest

    Jim:

    I want to implement this
    Addr(15 downto C_controlBits) <= SignalB;
    if(C_ControlBits=0) then
    NULL;
    else
    Addr(C_ControlBits-1 downto 0) <= (others=>'0');
    end if;

    Sorry that I didn't describe it clear and you had to guess. You
    suggestion is what I needed.
    But is that a good idear to overwite it? I know it is handy, but would
    it cause problem for syncrounous design because it induces extra
    delay/
    unstable phases and then probably data hazard?

    Thank you very much,
    Rebecca
    Rebecca, Mar 26, 2007
    #6
  7. Rebecca

    Andy Guest

    If this has to be sequential code (inside a process), then Jim's
    solution works fine:

    Addr <= (others => '0');
    Addr(15 downto C_controlBits) <= SignalB;

    If this is supposed to be concurrent statements, then generate will
    work, since C_control_bits must be static because signalB is of static
    width.

    Addr(15 downto C_controlBits) <= SignalB;
    if C_controlBits /= 0 generate
    Addr(C_ControlBits-1 downto 0) <= (others=>'0');
    end generate;

    Take your pick.

    andy

    On Mar 26, 10:36 am, "Rebecca" <> wrote:
    > Sorry I didn't describe it clear, Brian. What I want to implement is
    >
    > Addr(15 downto C_controlBits) <= SignalB;
    > if(C_ControlBits=0) then
    > NULL;
    > else
    > Addr(C_ControlBits-1 downto 0) <= (others=>'0');
    > end if;
    >
    > I can't use the generated stuff here.
    >
    > Thank you,
    > Rebecca
    Andy, Mar 27, 2007
    #7
  8. Rebecca

    Rebecca Guest

    Thank you so much, Andy. I need both in my design.
    Thanks a lot,
    Rebecca
    Rebecca, Mar 28, 2007
    #8
  9. Rebecca

    Rebecca Guest

    Thank you so much, Andy. I need both in my design.
    Thanks a lot,
    Rebecca
    Rebecca, Mar 28, 2007
    #9
    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. itsme
    Replies:
    1
    Views:
    1,622
    Ralf Hildebrandt
    Jul 23, 2003
  2. Anand P Paralkar
    Replies:
    2
    Views:
    9,375
    Srinivasan Venkataramanan
    Aug 4, 2003
  3. Johnsy Joseph

    Conditional assignment to signals

    Johnsy Joseph, Sep 21, 2004, in forum: VHDL
    Replies:
    8
    Views:
    4,871
    Raghavendra
    Sep 24, 2004
  4. Replies:
    2
    Views:
    2,786
  5. Alec S.
    Replies:
    10
    Views:
    10,114
    Alec S.
    Apr 16, 2005
Loading...

Share This Page