1

I am trying to make a two dimensional array of full adders with specific logic with their inputs and outputs. I currently have two for-generate statements of rows and columns, and then an if-elsif-else statement to decide how to connect that full adder. My code looks like this:

   rows : for row in 0 to n-1 generate
    columns : for col in 0 to n-1 generate
            if row = 0 then 
                null;
            elsif row = 1 then
                first: entity work.fa
                port map (  A => Ain(row)(col),
                                B => Bin(row)(col),
                                sum => sum(row+1)(col),
                                cin => cin,
                                cout => cout(row)(col+1)
                             );
            else
                process begin
                if (row = n/2) then
                    last: entity work.fa
                    port map ( A => Ain(row)(col),
                                B => Bin(row)(col-offset),
                                sum => sum(row)(col-offset),
                                cin => cin,
                                cout => cout(row)(col)
                             );
                else
                    middle: entity work.fa
                    port map (  A => mandq(row)(col-offset), 
                                B => sout(row)(col-offset),
                                sum => sout(row)(col-offset),
                                cin => cout(row)(col),
                                cout => cout(row)(col+1)
                             );
                end if;
                end process;
            end if;
            end process;
    end generate;
 end generate;

each entity is getting the following errors: - Syntax error near "entity". - Syntax error near "port". - Syntax error near ";".

The "entity" error is occuring on the lines titled first, middle and last

The "port" issue is occurring on the lines immediately after the entities.

The ";" issue is occuring on lines that contain the port map ending );

woo2
  • 33
  • 1
  • 7
  • 2
    A process statement part may only contain sequential statements. A component instantiation (such as your design entity work.fa) are concurrent statements. –  Apr 17 '17 at 05:57
  • You can try to use `if...generate` construct to generate requirement instantiation. – Roman Apr 17 '17 at 06:08
  • Your code example isn't a [Minimal, Complete and Verifiable example](https://stackoverflow.com/help/mcve) particularly missing declarations, meaning it's hard for someone to show you a correct construct and not possible to duplicate the errors. –  Apr 17 '17 at 10:31
  • Does this answer your question? [port map in structural VHDL code](https://stackoverflow.com/questions/21164449/port-map-in-structural-vhdl-code) –  Dec 02 '19 at 21:52

2 Answers2

2

You should not use if .. then, but instead use if .. generate. In VHDL-2008 this has become really easy, as elsif .. generate etc is supported. Or even case ... generate

You could write it like this:

rows : for row in 1 to n-1 generate -- shouldn't this only go to (n/2) ?
    columns : for col in 0 to n-1 generate
        element: case row generate
            -- when 0 no longer occurs with modified range
            when 1 =>
                first: entity work.fa
                port map (
                    A => Ain(row)(col),
                    B => Bin(row)(col),
                    sum => sum(row+1)(col),
                    cin => cin,
                    cout => cout(row)(col+1)
                    );
            when n/2 =>
                last: entity work.fa
                port map (
                    A => Ain(row)(col),
                    B => Bin(row)(col-offset),
                    sum => sum(row)(col-offset),
                    cin => cin,
                    cout => cout(row)(col)
                    );
            when others =>
                middle: entity work.fa
                port map (
                    A => mandq(row)(col-offset), 
                    B => sout(row)(col-offset),
                    sum => sout(row)(col-offset),
                    cin => cout(row)(col),
                    cout => cout(row)(col+1)
                    );
        end generate;
    end generate;
end generate;
JHBonarius
  • 10,824
  • 3
  • 22
  • 41
1
  1. Process is not supposed to appear inside if statement. It should go only by itself, inside architecture body.

  2. You can't (and you don't need to) use process for entity instantiation. In process you write something that is sequential, or for example some parallel statements, that are sensitive to clock edge. But definitely not entity instantiation.

You probably wanted to use process, because it has if...else statements. It's parallel equivalent is when...else statement. But I am not sure how it should be used here. As user1155120 already mentioned in comments, you should post a Minimal, Complete and Verifiable example. You missed all declarations, including entity.

EDIT: Of course there is also if...generate, as J.H.Bonarius wrote.

Staszek
  • 849
  • 11
  • 28