Ginerics mixed with if elsif else

Discussion in 'VHDL' started by michaelb, Sep 30, 2006.

  1. michaelb

    michaelb

    Joined:
    Sep 30, 2006
    Messages:
    1
    Hi everyone,

    I’m trying to generalize the following code so that RST_cmp can have any number of bits (b) and the number of state_counter can also change (upperbound).

    CODE in PROCESS:
    if state_counter = 0 then
    RST_cmp(0) <= '0';
    RST_cmp(1) <= '1';
    Daddr <= Daddr + 1;
    state_counter <= state_counter+1;​
    elsif state_counter = 1 then
    RST_cmp(1) <= '0';
    RST_cmp(2)<= '1';
    state_counter <= state_counter+1;​
    elsif state_counter = 2 then
    RST_cmp(2)<= '0';
    RST_cmp(3)<= '1';
    state_counter <= state_counter+1;​
    elsif state_counter = 3 then
    RST_cmp(4) <=’0’;
    state_counter <= state_counter+1;​
    elsif state_counter = 3 then
    state_counter <= state_counter+1;​
    else
    RST_cmp(0) <= '1';
    Daddr <= Daddr + 1;
    state_counter <= (others => '0');​
    end if;

    I want to generalize it so that if I have ‘b’ bits in RST_cmp it will automatically make the same if, elsif, else structure but scaled to not only how many ‘b’ bits there are but also scaled to whatever my max ‘state_counter’ is.

    I wanted to use something like this but it does not seem to work under Xilinx ISE. Am I doing anything wrong?

    if state_counter = 0 then
    RST_cmp(0) <= '0';
    RST_cmp(1) <= '1';
    Daddr <= Daddr + 1;
    state_counter <= state_counter+1;​
    for i in 1 to upperbound loop
    elsif state_counter = i then

    GEN1: if i <= b generate
    RST_cmp(i) <= '0';
    RST_cmp(i+1)<= '1';​
    end generate;
    state_counter <= state_counter+1;​
    end loop;
    else
    RST_cmp(0) <= '1';
    Daddr <= Daddr + 1;
    state_counter <= (others => '0');​
    end if;


    1) Would my generic code work with having a for statement in the middle of a if,elsif, else statement?

    2) If not have would I do such a thing?

    3) Is my idea of using a Generate statement valid in this context?

    Thank you for your ideas,

    Michael
    michaelb, Sep 30, 2006
    #1
    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. unexpected

    Avoiding if..elsif statements

    unexpected, Aug 25, 2006, in forum: Python
    Replies:
    11
    Views:
    580
    Tal Einat
    Aug 27, 2006
  2. karlwijk

    if/elsif problem

    karlwijk, Apr 16, 2007, in forum: VHDL
    Replies:
    3
    Views:
    661
    quantum_dot
    Apr 18, 2007
  3. palo
    Replies:
    0
    Views:
    1,292
  4. Brad Smallridge

    one hot machine without elsif

    Brad Smallridge, Feb 16, 2009, in forum: VHDL
    Replies:
    10
    Views:
    788
  5. apalopohapa
    Replies:
    0
    Views:
    556
    apalopohapa
    Oct 20, 2009
Loading...

Share This Page