diff --git a/main.pdf b/main.pdf new file mode 100644 index 0000000..5ce7ac1 Binary files /dev/null and b/main.pdf differ diff --git a/main.tex b/main.tex index 74d2e49..a7ccc9c 100644 --- a/main.tex +++ b/main.tex @@ -17,14 +17,283 @@ \newpage \section{Introduzione} % finalità del progetto, ecc. -L'obiettivo di questo progetto è ... - +L'obiettivo di questo progetto è la progettazione di un sommatore a selezione +del riporto a 16 bit utilizzando il software di design di circuiti elettronici Vivado. +Quest'ultimo dispone di tutti gli strumenti utili ai fini del design e del testing dei circuiti digitali che andremo a +sviluppare nel corso della trattazione e utilizza per i suoi scopi due linguaggi di descrizione dell'hardware: +Verilog e VHDL (noi utilizzeremo quest'ultimo). \section{RCA} +Per poter sviluppare il nostro sommatore a selezione del riporto dobbiamo innanzitutto costruire il suo componente fondamentale: +il sommatore a propagazione del riporto. +Per i nostri scopi, durante lo svolgimento di questo progetto abbiamo progettato due sommatori di questo genere +: uno a 4bit e l'altro, che sfruttava il primo, a 8bit. + +La necessità di quest'ultima scelta sarà più chiara nel seguito, quando andremo a costruire il nostro sommatore a selezione del riporto. + \subsection{Funzionamento} + +Il sommatore a propagazione del riporto è il più "semplice" tra i sommatori, perchè ricalca perfettamente il modo naturale +in cui calcoliamo a mano le somme in colonna. + +In particolare, abbiamo dei componenti, che andremo ad esplorare nella prossima sottosezione, che sommano 2 bit, e producono +un riporto da collegare al blocco successivo del sommatore. + +\makebox[\linewidth][c]{\includegraphics[scale=0.35]{RCA4.pdf}} + +Questa soluzione è di facile implementazione, ma è lenta e impraticabile su larga scala: +Affinchè l'ultimo sommatore possa mostrare l'output corretto, bisogna attendere che tutti i suoi precedenti abbiamo terminato i loro calcoli. +Questo problema, per sommatori di numeri a 64 o 128 bit diventa insostenibilmente lento ed è per questo che si ricorre a varianti +più "furbe" per poter calcolare i riporti in maniera più immediata. + + +Dopo questa breve introduzione possiamo procedere su Vivado a sviluppare i nostri componenti e testarli. + +\begin{minted}{vhdl} +entity RCA4 is + Port (A,B: in bit_vector(3 downto 0); + cin: in bit; + S: out bit_vector(3 downto 0); + cout: out bit); +end RCA4; + +architecture MyRCA4 of RCA4 is +signal C: bit_vector(3 downto 1); +component FullAdder is + Port ( a,b,cin : in bit; + s,cout : out bit); +end component; +begin + FA0: FullAdder port map(A(0),B(0),cin,S(0),C(1)); + FA1: FullAdder port map(A(1),B(1),C(1),S(1),C(2)); + FA2: FullAdder port map(A(2),B(2),C(2),S(2),C(3)); + FA3: FullAdder port map(A(3),B(3),C(3),S(3),cout); +end MyRCA4; +\end{minted} + +Questo è il codice VHDL necessario a definire un'"entità" "RCA4" (Il componente rappresentato nella figura precedente) che definisce le porte di input e output del componente, +che è astratta rispetto a una specifica implementazione di quest'ultimo. +Immediatamente dopo andiamo a definire un'"architecture" dell'entità definita sopra, che è un'implementazione specifica +dell'astrazione definita dall'entità. + +Come anticipato, in questa implementazione facciamo uso di un componente che andremo a vedere nel dettaglio nel seguito della +trattazione, il FullAdder. + +Ora ci basta utilizzare due sommatori a 4 bit per costruire in maniera molto semplice il nostro sommatore a 8 bit: +\begin{minted}{vhdl} +entity RCA8 is + Port (A,B: in bit_vector(7 downto 0); + cin: in bit; + S: out bit_vector(7 downto 0); + cout: out bit); +end RCA8; + +architecture MyRCA8 of RCA8 is +component RCA4 is + Port (A,B: in bit_vector(3 downto 0); + cin: in bit; + S: out bit_vector(3 downto 0); + cout: out bit); +end component; +signal c4: bit; +begin +RCA4_1: RCA4 port map(A(3 downto 0),B(3 downto 0), cin, S(3 downto 0), c4); +RCA4_2: RCA4 port map(A(7 downto 4),B(7 downto 4), c4, S(7 downto 4), cout); +end MyRCA8; +\end{minted} + +\makebox[\linewidth][c]{\includegraphics[scale=0.65]{RCA8.pdf}} + +Adottiamo quindi un procedimento molto simile a quello utilizzato per il sommatore a 4 bit, creando l'entità e l'architettura distinte per modularità. + \subsubsection{Full Adder} +Dopo aver trattato nel dettaglio i componenti essenziali per il nostro sommatore a selezione del riporto, discutiamo del mattoncino di base anche dei due sommatori costruiti precedentemente. + +Il FullAdder è un circuito che somma 3 bit, $a$, $b$, e un riporto in entrata $c_{in}$ e produce in output un bit di somma $s$, e un riporto in uscita $c_{out}$ secondo da la seguente tabella di verità: + +\begin{displaymath} +\begin{array}{|c c c|c c|} +% |c c|c| means that there are three columns in the table and +% a vertical bar ’|’ will be printed on the left and right borders, +% and between the second and the third columns. +% The letter ’c’ means the value will be centered within the column, +% letter ’l’, left-aligned, and ’r’, right-aligned. + a & b & c_{in} & s & c_{out} \\ % Use & to separate the columns +\hline % Put a horizontal line between the table header and the rest. + 0 & 0 & 0 & 0 & 0\\ + 0 & 0 & 1 & 1 & 0\\ + 0 & 1 & 0 & 1 & 0\\ + 0 & 1 & 1 & 0 & 1\\ + 1 & 0 & 0 & 1 & 0\\ + 1 & 0 & 1 & 0 & 1\\ + 1 & 1 & 0 & 0 & 1\\ + 1 & 1 & 1 & 1 & 1\\ +\end{array} +\end{displaymath} + +In VHDL: + +\begin{minted}{vhdl} +entity FullAdder is + Port ( a,b,cin : in bit; + s,cout : out bit); +end FullAdder; + +architecture MyFullAdder of FullAdder is +signal p: bit; +begin + p <= a xor b; + s <= p xor cin; + cout <= a when p='0' else cin; +end MyFullAdder; +\end{minted} + +Abbiamo inserito un segnale "ausiliario" $p$ anche detto di propagazione, per semplificare il design. +Dalla tabella di verità possiamo notare infatti che nel caso in cui "a" e "b" siano diversi, l'output su $c_{out}$ è +uguale a $c_{in}$. +Nella situazione opposta: $a = b$, $c_{out} = a$ o anche $c_{out} = b$ essendo i due uguali. + +\makebox[\linewidth][c]{\includegraphics[scale=0.75]{FullAdder.pdf}} + \subsection{Simulazione} +Le simulazioni svolte per i componenti sviluppati durante questa sezione sono semplici in funzionamento: +Andiamo a testare ogni possibile combinazione degli input del componente sotto test, e quindi il codice VHDL di tutti e 3 sarà molto simile: + +\begin{minted}{vhdl} +entity Sim_FullAdder is +end Sim_FullAdder; + +architecture MySim_FullAdder of Sim_FullAdder is +component FullAdder is + Port ( a,b,cin : in bit; + s,cout : out bit); +end component; +signal Ia, Ib, Icin, Os, Ocout: bit; +begin + CUT: FullAdder port map(Ia, Ib, Icin, Os, Ocout); + process begin + Ia <= '0'; + Ib <= '0'; + Icin <= '0'; + wait for 10ns; + Ia <= '1'; + Ib <= '0'; + Icin <= '0'; + wait for 10ns; + Ia <= '0'; + Ib <= '1'; + Icin <= '0'; + wait for 10ns; + Ia <= '0'; + Ib <= '0'; + Icin <= '1'; + wait for 10ns; + Ia <= '1'; + Ib <= '1'; + Icin <= '0'; + wait for 10ns; + Ia <= '1'; + Ib <= '0'; + Icin <= '1'; + wait for 10ns; + Ia <= '0'; + Ib <= '1'; + Icin <= '1'; + wait for 10ns; + Ia <= '1'; + Ib <= '1'; + Icin <= '1'; + end process; + +end MySim_FullAdder; +\end{minted} + +\begin{minted}{vhdl} +library IEEE; +use IEEE.numeric_bit.all; + +entity Sim_RCA4 is +end Sim_RCA4; + +architecture MySim_RCA4 of Sim_RCA4 is +component RCA4 is + Port (A,B: in bit_vector(3 downto 0); + cin: in bit; + S: out bit_vector(3 downto 0); + cout: out bit); +end component; + +signal IA,IB,OS: bit_vector(3 downto 0); +signal Icin, Ocout: bit; +begin +CUT: RCA4 port map(IA,IB,Icin,OS,Ocout); + process begin + Icin <= '0'; + for j in 0 to 15 loop + for k in 0 to 15 loop + IA <= bit_vector(to_unsigned(j,4)); + IB <= bit_vector(to_unsigned(k,4)); + wait for 10ns; + end loop; + end loop; + Icin <= '1'; + for j in 0 to 15 loop + for k in 0 to 15 loop + IA <= bit_vector(to_unsigned(j,4)); + IB <= bit_vector(to_unsigned(k,4)); + wait for 10ns; + end loop; + end loop; + end process; +end MySim_RCA4; + +%% +Tommischiri inserisci alcune immagini delle forme d'onda +%% + +\end{minted} + +\begin{minted}{vhdl} +library IEEE; +use IEEE.numeric_bit.all; + +entity Sim_RCA8 is +end Sim_RCA8; + +architecture MySim_RCA8 of Sim_RCA8 is +component RCA8 is + Port (A,B: in bit_vector(7 downto 0); + cin: in bit; + S: out bit_vector(7 downto 0); + cout: out bit); +end component; + +signal IA,IB,OS: bit_vector(7 downto 0); +signal Icin, Ocout: bit; +begin +CUT: RCA8 port map(IA,IB,Icin,OS,Ocout); + process begin + Icin <= '0'; + for j in 0 to 255 loop + for k in 0 to 255 loop + IA <= bit_vector(to_signed(j,8)); + IB <= bit_vector(to_signed(k,8)); + wait for 10ns; + end loop; + end loop; + Icin <= '1'; + for j in 0 to 255 loop + for k in 0 to 255 loop + IA <= bit_vector(to_signed(j,8)); + IB <= bit_vector(to_signed(k,8)); + wait for 10ns; + end loop; + end loop; + end process; +end MySim_RCA8; + +\end{minted} \section{CSA} \subsection{Funzionamento}