Cours:TP M1102 TP 3 Corr : Différence entre versions
m (→Question 2) |
m (→Question 2) |
||
Ligne 118 : | Ligne 118 : | ||
* S<sub>1</sub> <-> S(1) | * S<sub>1</sub> <-> S(1) | ||
* S<sub>0</sub> <-> S(0) | * S<sub>0</sub> <-> S(0) | ||
+ | |||
+ | Le programme VHDL devient : | ||
+ | |||
+ | <source lang=vhdl> | ||
+ | library IEEE; | ||
+ | use IEEE.std_logic_1164.all; | ||
+ | --use IEEE.std_logic_arith.all; | ||
+ | --use IEEE.STD_LOGIC_UNSIGNED.all; | ||
+ | |||
+ | ENTITY add4 IS | ||
+ | PORT (A,B : IN STD_LOGIC_VECTOR(3 DOWNTO 0); | ||
+ | Cin : IN STD_LOGIC; --retenue entrée dans le schéma | ||
+ | S : OUT STD_LOGIC_VECTOR(4 DOWNTO 0)); --retenue en S(4) | ||
+ | END add4; | ||
+ | |||
+ | |||
+ | </source> |
Version du 25 septembre 2020 à 15:43
TP 3
Exercice 1
Question 1
La table de vérité donnée dans wikipédia est :
A | B | Cin | S | Cout |
---|---|---|---|---|
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 |
Nous allons la modifier légèrement pour ses entrées et sorties : les 3 entrées sont regroupées et les 2 sorties sont aussi regroupées ensemble
- Table de vérité
Entrées Sorties e(2)=Cin e(1)=B e(0)=A S(1)=Cout S(0)=S 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1
ATTENTION : Nous avons aussi volontairement changé l'ordre ses entrées et des sorties.Il est préférable d'avoir les sorties dans ce sens pour avoir le poids fort des deux bits de sortie à gauche. Pour les entrées c'est moins important.
Voici le fichier VHDL correspondant :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
ENTITY add1bit IS PORT(
e : in std_logic_vector(2 downto 0); -- Cin, B, A
s : out std_logic_vector(1 downto 0)); -- Cout, S
END add1bit;
ARCHITECTURE arch of add1bit IS
BEGIN
with e select
S <= "00" when "000", --0+0+0=00
"01" when "001", --0+0+1=01
"01" when "010", --0+1+0=01
"10" when "011", --0+1+1=10
"01" when "100", --1+0+0=01
"10" when "101", --1+0+1=10
"10" when "110", --1+1+0=10
"11" when others;--1+1+1=11
END arch;
Question 2
Il faut déjà définir les entrées et sorties de notre problème, autrement dit définir l'entité. Parmi les diverses solutions possibles, nous allons choisir
library IEEE;
use IEEE.std_logic_1164.all;
--use IEEE.std_logic_arith.all;
--use IEEE.STD_LOGIC_UNSIGNED.all;
ENTITY add4 IS
PORT (A,B : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
Cin : IN STD_LOGIC; --retenue entrée dans le schéma
S : OUT STD_LOGIC_VECTOR(4 DOWNTO 0)); --retenue en S(4)
END add4;
Si l'on compare au schéma de l'énoncé :
on impose ainsi les correspondances suivantes :
Schéma <-> VHDL
- REntrée <-> Cin
- A3 <-> A(3)
- A2 <-> A(2)
- A1 <-> A(1)
- A0 <-> A(0)
- B3 <-> B(3)
- B2 <-> B(2)
- B1 <-> B(1)
- B0 <-> B(0)
- RSortie <-> S(4)
- S3 <-> S(3)
- S2 <-> S(2)
- S1 <-> S(1)
- S0 <-> S(0)
Le programme VHDL devient :
library IEEE;
use IEEE.std_logic_1164.all;
--use IEEE.std_logic_arith.all;
--use IEEE.STD_LOGIC_UNSIGNED.all;
ENTITY add4 IS
PORT (A,B : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
Cin : IN STD_LOGIC; --retenue entrée dans le schéma
S : OUT STD_LOGIC_VECTOR(4 DOWNTO 0)); --retenue en S(4)
END add4;