Forum: FPGA, VHDL & Co. Reihe von FullAdders mit Generate


von Samer A. (Firma: Personal) (thedestroyer)


Lesenswert?

Hallo :),

(sorry für meine schlechte sprache) :)

ich hab einen lockeren VHDL Code für einen Full-Adder. Ich möchte mit 
Generate und Generic N blocks von diesem Full-Adder zusammen verbinden, 
damit ich N Bits mit anderen N Bits adde, und N+1 Bits als Ergebnis 
bekomme.

mein FA Code ist der Folgende:

---------------------------------

entity FA is
    Port ( a : in  std_logic;
           b : in  std_logic;
           cin : in  std_logic; --carry in
           s : out  std_logic;
           cout : out  std_logic); --carry out
end FA;

architecture Behavioral of FA is

begin
s <= a XOR b XOR cin;
cout <= (a AND b) OR (a AND cin) OR (b AND cin);

end Behavioral;

--------------------------------

Und mit dem Folgenden Code habe ich es versucht, die FA Blöcke zusammen 
zu verbinden:

-----------------------------------------------


entity FASeries is
generic (N : NATURAL := 8);
  port(
    a : std_logic_vector(N downto 0);
    b : std_logic_vector(N downto 0);
    res : std_logic_vector(N+1 downto 0)
    );
end FASeries;

architecture Behavioral of FASeries is
component FA
   Port ( a : in  std_logic;
           b : in  std_logic;
           cin : in  std_logic;
           s : out  std_logic;
           cout : out  std_logic);
end component;
signal cout : std_logic_vector(N downto 0);
signal resultBuffer : std_logic_vector(N+1 downto 0);
begin
comp: FA
PORT MAP(
   a => a(0),
   b => b(0),
   cin => '0',
   s => resultBuffer(0)
);
g1: FOR i IN 1 TO N GENERATE
          comp: FA
          PORT MAP(
               a => a(i),
               b => b(i),
               cin => cout(i-1),
         s => resultBuffer(i)
         );
END GENERATE g1;
resultBuffer(N+1) <= cout(N);
res <= resultBuffer; -- Error passiert hier, Line 69
end Behavioral;

------------------------------------------------------------

ich bin mir nicht sicher, dass meine Idee richtig ist (wie ich den Code 
geschrieben habe). Der Code gibt ein Problem mit dem Syntax, und sagt:

Line 69. Object res of mode IN can not be updated.

Warum bekomme ich dieses Error? könnt ihr mir helfen? bekommet man den 
erwarteten Ergebnis mit diesem Code?

Vielen Dank :)

von Lothar M. (Firma: Titel) (lkmiller) (Moderator) Benutzerseite


Lesenswert?

Samer Afach schrieb:
> Line 69. Object res of mode IN can not be updated.
> Warum bekomme ich dieses Error?
Das ist ja wohl SELBSTERKLÄREND. Das Signal res hat die Richtung in 
und kann daher nicht beschrieben werden.

Und der Hintergrund?
1
port(
2
     a   : std_logic_vector(N downto 0);
3
     b   : std_logic_vector(N downto 0);
4
     res : std_logic_vector(N+1 downto 0)
5
     );
Bei diesen Ports fehlt noch die Richtung (in, out, inout, buffer...). 
Defaulteinstellung ist in. Probiers mal (mindestens) so:
1
port(
2
     a   : std_logic_vector(N downto 0);
3
     b   : std_logic_vector(N downto 0);
4
     res : out std_logic_vector(N+1 downto 0)
5
     );

von Samer A. (Firma: Personal) (thedestroyer)


Lesenswert?

Ah Gott! wie peinlich! :$!! Vielen Dank!!

Sorry bin ganz noob mit VHDL :)

Aber ist mein Code für die Idee richtig? Alle FAs zusammen zu 
kombinieren?

von Lothar M. (Firma: Titel) (lkmiller) (Moderator) Benutzerseite


Lesenswert?

Samer Afach schrieb:
> Aber ist mein Code für die Idee richtig?
Das habe ich nicht kontrolliert.
Das ist eine Hausaufgabe, und deren Ergebnis kannst du mit einer 
Simulation ganz leicht testen...

von Samer A. (Firma: Personal) (thedestroyer)


Lesenswert?

Vielen Dank für deine Antwort :),

nur zur Information, ich bin Doktorand von Physik. Also vielleicht die 
Idee von Hausaufgaben ist noch ein bißchen veraltet für mich :P

Ich habe empfunden, dass etwas mit dem Code nicht stimmt. Ich habe die 
Simulation gemacht für N=2, die Ergebnisse waren aber total falsch. Habe 
immer im Ausgabe "res" entweder UUU0 oder UUU1 bekommen... ich weiß 
nicht was das bedeutet.

Das Problem mit dem Code, wie ich es sehe, ist dass ich nicht weiß, wie 
ich cin(1) mit cout(0) verbinden kann, und res(N+1) mit cout(N) 
verbinden kann. Manche von diesen Signalen braucht kein Generate, wie 
ich es geschrieben habe. Die Verbindung zwischen die Signale im Befehl 
Generate und außerhalb Generate kann ich nicht machen. Ich weiß nicht 
einfach wie!

Wie kann ich diese Verbindung machen? Es würde mich sehr freuen mir zu 
sagen :)

von D. I. (Gast)


Lesenswert?

Wie hast dus denn bis zum Diplom geschafft, ...

von Samer A. (Firma: Personal) (thedestroyer)


Lesenswert?

wie meinst du das?
Vielleicht habe ich es falsch gesagt :P

The idea of homework is a little bit obsolete for me, cuz I'm a PhD 
student.

Sieht das besser aus? ^^

ich bin Physiker. Ich lerne VHDL ganz allein! also eure Hilfe schätze 
ich sehr :)

Bitte, auf eine Antwort warte ich :)

von Lothar M. (Firma: Titel) (lkmiller) (Moderator) Benutzerseite


Lesenswert?

Samer Afach schrieb:
> nur zur Information, ich bin Doktorand von Physik. Also vielleicht die
> Idee von Hausaufgaben ist noch ein bißchen veraltet für mich :P
Willst du diesen Addierer "nur so als Übung" machen, oder hat das einen 
Sinn? Ich mache in VHDL Additionen einfach mit c <= a+b;

> Ich habe empfunden, dass etwas mit dem Code nicht stimmt. Ich habe die
> Simulation gemacht für N=2, die Ergebnisse waren aber total falsch. Habe
> immer im Ausgabe "res" entweder UUU0 oder UUU1 bekommen...
Zeig doch mal deine Testbench...
(Am besten als Dateianhang mit Endung *.vhd)

Samer Afach schrieb:
1
component FA
2
   Port ( a : in  std_logic;  --  5 Ports
3
           b : in  std_logic;
4
           cin : in  std_logic;
5
           s : out  std_logic;
6
           cout : out  std_logic);
7
end component;
8
9
10
 comp: FA  
11
 PORT MAP(        -- 4 Ports...   :-o
12
    a => a(0),
13
    b => b(0),
14
    cin => '0',
15
    s => resultBuffer(0)
16
 );
17
18
 g1: FOR i IN 1 TO N GENERATE   -- auch 4 Ports...
19
           comp: FA
20
           PORT MAP(
21
                a => a(i),
22
                b => b(i),
23
                cin => cout(i-1),
24
                s => resultBuffer(i)
25
          );
26
 END GENERATE g1;
27
 :
28
 resultBuffer(N+1) <= cout(N);  -- hier sind wir ausserhalb der Schleife!!!
29
 :
30
end Behavioral;
> ich bin mir nicht sicher, dass meine Idee richtig ist (wie ich den Code
> geschrieben habe)
Nein, das kann so nicht stimmen. Mich wundert, dass da überhaupt was 
rauskommt...

von Samer A. (Firma: Personal) (thedestroyer)


Angehängte Dateien:

Lesenswert?

Vielen Dank für die Antwort :)

Die Codes kannst du als Anhang finden! :)

von Lothar M. (Firma: Titel) (lkmiller) (Moderator) Benutzerseite


Lesenswert?

Probier das:
1
entity FASeries is
2
generic (N : NATURAL := 2);
3
  port(
4
    a : in std_logic_vector(N downto 0); 
5
    b : in std_logic_vector(N downto 0);
6
    res : out std_logic_vector(N+1 downto 0)
7
   );
8
end FASeries;
9
10
architecture Behavioral of FASeries is
11
component FA
12
   Port ( a : in  std_logic;
13
           b : in  std_logic;
14
           cin : in  std_logic;
15
           s : out  std_logic;
16
           cout : out  std_logic);
17
end component;
18
signal cout : std_logic_vector(N downto 0);
19
begin
20
comp: FA
21
PORT MAP(
22
   a => a(0), 
23
   b => b(0),
24
   cin => '0',
25
   s => res(0),
26
   cout => cout(0)             --- !!!
27
);
28
g1: FOR i IN 1 TO N GENERATE
29
          comp: FA
30
          PORT MAP(
31
               a => a(i),
32
               b => b(i),
33
               cin => cout(i-1),
34
               s => res(i),
35
               cout => cout(i) ---- !!!
36
  );
37
END GENERATE g1;
38
39
res(N+1) <= cout(N);           --- !!!
40
41
end Behavioral;
Und überleg dir: wie soll denn ein Addierer funktionieren, wenn der 
Übertrag nicht weitergegeben wird?

Ich muß D. I. (grotesque) da schon recht geben: das Nichterkennen dieses 
Problems hat m.E. nichts mit Sprachproblemen oder VHDL an sich zu tun...

von Samer A. (Firma: Personal) (thedestroyer)


Lesenswert?

Thank you so much for your solution. It worked perfectly.

Why am I writing this in English? because I really feel insulted right 
now. Mr. Miller, with all due respect. I appreciate your help a lot, and 
I'm very happy to find people helping and being nice with nothing asked 
in return. But eventually you don't have to agree with someone accusing 
me of not deserving my Diploma. This is extremely insulting. I'm very 
new to VHDL, and concurrent code confuses me a lot, because I'm a C++ 
programmer since 10 years. I admit, the questions are very easy to 
answer for a pro like you, but for someone like me, it's just difficult 
to "see" the errors the way you see them in the code. We all have a 
starting point, and we all pose embarrassing question. This is how we 
learn :)

When I said the homework thing, I posed it as a joke, and posed the 
right smiley beside it so you won't think I'm refusing cooperating with 
you. It's just that I knew the code didn't make sense somehow. And I 
mentioned at the beginning of this post that my German is very weak. So 
please appreciate this point a lot. I'm doing all I can!

Thanks again for the help. But please consider people's feelings next 
time, and when someone says a rude comment, you don't have to agree with 
them.

Best regards, and thanks again.

Samer Afach
Universitätsklinikum, Jena.

von Lothar M. (Firma: Titel) (lkmiller) (Moderator) Benutzerseite


Lesenswert?

Samer Afach schrieb:
> It worked perfectly.
Nice to hear. You see: you have not been very far from the correct 
solution.

> But eventually you don't have to agree with someone accusing
> me of not deserving my Diploma. This is extremely insulting.
It was not my intetion to offend you. It just seemed to me (as obviously 
to Duke) as if you have a very high grade qualification and you ask very 
simple low grade questions with (fairly) obvious answers. Of course you 
are right with the comparision of a starter vs. a pro. I just loose the 
focus on that fact from now to then.

> I appreciate your help a lot, and I'm very happy to find people
> helping and being nice with nothing asked in return.
Get a copy of the book "VHDL-Synthese" from Reichardt&Schwarz. As a 
little penalty for you its German, but your knowledge of the language 
doesn't look all that bad... ;-)
BTW: what did you mean with
Samer Afach schrieb:
>>>> ich hab einen lockeren VHDL Code

> Best regards, and thanks again.
You're welcome. Good luck for your further work.

von Samer A. (Firma: Personal) (thedestroyer)


Lesenswert?

locker = simple :)

Ich hole mir das Buch. Danke!

von Uwe Bonnes (Gast)


Lesenswert?

Do you really feel insilted by Lothar Miller .

Or did you mean the anonymous "D. I. (grotesque)"?

von Samer A. (Firma: Personal) (thedestroyer)


Lesenswert?

D. I. wasn't a guest. He's a user with an account. I didn't care when D. 
I. said what he said, because he didn't even contribute to the answer. 
So some guy being rude and talking inappropriate is something you'd find 
in all communities, and they're there just to be ignored.
But then agreeing with that was by Lothar was offensive. I think Lothar 
didn't mean it, he was just surprised from my low-grade questions, as he 
mentioned. He already expressed that he's not that happy by agreeing to 
D. I.'s statement.

Let's not blow the problem and give it greater than its dimensions. A 
person like D. I., with all due respect, who enters a topic just to 
write an offensive sentence is a type of people, for which I wouldn't 
give the least care. He could stay away and get all conceited with his 
brilliant answers and science that he knows.

We're all here to help each other, and we're all humans who err, pose 
stupid and embarrassing question, but eventually we learn. Let's not 
talk about this anymore :-)

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.