Re: When do I always put a "else NULL" statement in my VHDL code?

Discussion in 'VHDL' started by Kelvin, Sep 13, 2003.

  1. Kelvin

    Kelvin Guest

    u had better put something in the else{}, otherwise you get a latch.



    "walala" <> wrote in message
    news:...
    > Dear all,
    >
    > I feel confused by "else null" statement:
    >
    > if rst = '1' then
    > count <= 0;
    > elsif clk'event and clk = '1' then
    > if(INPUTEND = '1') then
    > ...
    > end if;
    > end if;
    >
    > I learned from books that I should exhaust all branches of "if"
    > statement, so I write in the following way:
    >
    > if rst = '1' then
    > count <= 0;
    > elsif clk'event and clk = '1' then
    > if (INPUTEND = '1') then
    > ...
    > else
    > null;
    > end if;
    > else
    > null;
    > end if;
    >
    >
    > But I also saw on the Internet sometimes people don't write code in my
    > cubersome way...
    >
    > Can anybody clarify a little for me? When I need to write this "else
    > null", and when I don't need it?
    >
    > Thanks a lot,
    >
    > -Walala
     
    Kelvin, Sep 13, 2003
    #1
    1. Advertising

  2. Kelvin

    Kelvin Guest

    In the first if statement, "if rst = '1' then count <= 0; elsif clk'event
    and clk = '1' then", you don't need an "else" if I remember the syntax
    correctly.
    In second if statement, you may replace the null with assignments, just to
    make the statement complete. for example,

    if rst = '1' then
    count <= 0;
    elsif clk'event and clk = '1' then
    if (INPUTEND = '1') then
    ...
    A <= B+C;
    else
    -- null;
    A <= A;
    end if;
    -- else
    -- null;
    end if;





    "walala" <> wrote in message
    news:bju4q1$afq$...
    > Dear Kelvin,
    >
    > Thank you for your answer...
    >
    > But it is unclear that which style is better...Can you tell me? (A) or

    (B)?
    >
    > By the way, I really don't have anything to do in "else" block, so I put
    > "null"... will that still infer a latch?
    >
    > < < "u had better put something in the else{}, otherwise you get a

    latch..."
    >
    >
    > (A)
    > > > if rst = '1' then
    > > > count <= 0;
    > > > elsif clk'event and clk = '1' then
    > > > if(INPUTEND = '1') then
    > > > ...
    > > > end if;
    > > > end if;
    > > >

    >
    >
    >
    > (B)
    > > > if rst = '1' then
    > > > count <= 0;
    > > > elsif clk'event and clk = '1' then
    > > > if (INPUTEND = '1') then
    > > > ...
    > > > else
    > > > null;
    > > > end if;
    > > > else
    > > > null;
    > > > end if;
    > > >

    >
    >
     
    Kelvin, Sep 13, 2003
    #2
    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. walala
    Replies:
    2
    Views:
    695
    Ken Smith
    Oct 11, 2003
  2. Mike Treseler
    Replies:
    0
    Views:
    556
    Mike Treseler
    Sep 12, 2003
  3. Jim Lewis
    Replies:
    1
    Views:
    550
    walala
    Sep 16, 2003
  4. Deryck
    Replies:
    4
    Views:
    552
    derek giroulle
    Jun 22, 2004
  5. afd
    Replies:
    1
    Views:
    8,566
    Colin Paul Gloster
    Mar 23, 2007
Loading...

Share This Page