0% ont trouvé ce document utile (0 vote)
6 vues25 pages

Simulation FPGA pour Contrôleur VGA

Le document présente un rapport d'exécution sur le développement d'un contrôleur VGA pour afficher des motifs colorés sur un écran, en utilisant des interrupteurs pour sélectionner les couleurs. Il détaille les exercices réalisés, les solutions techniques mises en œuvre, ainsi que les codes développés pour chaque exercice, tout en abordant les performances et les perspectives d'amélioration. Les projets incluent l'affichage d'un damier et d'une brique, avec des spécifications techniques précises et des résultats de tests.

Transféré par

edanintech
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
6 vues25 pages

Simulation FPGA pour Contrôleur VGA

Le document présente un rapport d'exécution sur le développement d'un contrôleur VGA pour afficher des motifs colorés sur un écran, en utilisant des interrupteurs pour sélectionner les couleurs. Il détaille les exercices réalisés, les solutions techniques mises en œuvre, ainsi que les codes développés pour chaque exercice, tout en abordant les performances et les perspectives d'amélioration. Les projets incluent l'affichage d'un damier et d'une brique, avec des spécifications techniques précises et des résultats de tests.

Transféré par

edanintech
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd

REPUBLIQUE DU CAMEROUN REPUBLIQUE OF CAMEROON

********* *********
Paix-Travail-Patrie Peace-Work-Fatherland
********* *********
MINISTERE DE MINISTRY OF HYGHER
L’ENSEIGNEMENT SUPERIEURE EDUCATION

UNIVERSITE DE DOUALA
UNIVERSITY OF DOUALA
**************************
ECOLE NORMALE SUPERIEURE
D’ENSEIGNEMENT TECHNIQUE
***************************
BP : 1872 DOUALA Tél. / FAX : 340 72 91
Email : cabenset@[Link]

DEPARTEMENT DE GENIE INFORMATIQUE


CIRCUIT LOGIQUE PROGRAMMABLE

RAPPORT D’EXECUTION DES DEVOIRS

GROUPE 1
NOMS ET PRENOMS MATRICULE
EKENGLO EKWEL Patricia Daniel (TIC4) 24NTIL04A
FOTSE WOGUIA Glory (TIC4) 24NTIL07A

Sous la supervision de :

Pr GAMOM NGOUNOU EWO ROLAND CHRISTIAN

Année académique : 2024-2025

0
Table des matières
Exercice B : Affichage Damier ............................................................................................................. 2
1. Contexte et Problématique ......................................................................................................... 2
2. Solution Technique ..................................................................................................................... 2
3. Codes Développés ....................................................................................................................... 2
4. Détails Techniques Avancés ........................................................................................................ 6
5. Procédure de Test ....................................................................................................................... 6
6. Analyse des Résultats .................................................................................................................. 7
7. Perspectives d'Amélioration ....................................................................................................... 7
Exercice C : Affichage d’une brique .................................................................................................... 7
1. Contexte et Problématique ......................................................................................................... 7
2. Solution Technique ..................................................................................................................... 7
3. Détails Techniques ...................................................................................................................... 8
4. Codes Développés ....................................................................................................................... 9
5. Procédure de Test ..................................................................................................................... 14
6. Résultats et Performance.......................................................................................................... 14
Exercice D : Affichage de plusieurs briques ...................................................................................... 15
Code principal ............................................................................................................................... 15
Code testbench ............................................................................................................................. 20
Conclusion ..................................................................................................................................... 23
Captures d'écran de simulation .................................................................................................... 23

1
Exercice B : Affichage Damier
1. Contexte et Problématique
1.1 Objectif du Projet
Développer un contrôleur VGA capable de diviser l'écran en quatre quadrants, chacun
affichant une couleur distincte sélectionnée dynamiquement par des interrupteurs.
1.2 Contraintes Techniques
- Carte de développement : Nexys4
- Fréquence d'horloge : 100 MHz
- Interface VGA 640x480 @ 60Hz
- Sélection de couleur via 3 interrupteurs
- Gestion d'un reset asynchrone
1.3 Difficultés Anticipées
- Génération des signaux de synchronisation VGA
- Division précise de l'écran
- Gestion de l'horloge pixel
- Implémentation de la logique de sélection des couleurs

2. Solution Technique
2.1 Architecture Matérielle
- Utilisation de l'IP VGA
- Division de l'horloge système (100 MHz -> 25 MHz)
- Génération de signaux hsync et vsync
- Logique de sélection de quadrant et de couleur
2.2 Choix d'Implémentation
- Langage : VHDL
- Approche : Machine à états finis (FSM) séquentielle
- Gestion modulaire des différents processus (horloge, compteurs, affichage)

3. Codes Développés
3.1 Code Principal : Contrôleur Damier
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity damier is
Port (
clk100 : in STD_LOGIC;
reset : in STD_LOGIC;
bouton1 : in STD_LOGIC;
bouton2 : in STD_LOGIC;

2
bouton3 : in STD_LOGIC;
red : out STD_LOGIC;
green : out STD_LOGIC;
blue : out STD_LOGIC;
hsync : out STD_LOGIC;
vsync : out STD_LOGIC
);
end damier;

architecture Behavioral of damier is


-- Constantes pour la résolution VGA 640x480 @ 60Hz
constant H_DISPLAY : integer := 640;
constant H_FP : integer := 16;
constant H_SP : integer := 96;
constant H_BP : integer := 48;
constant H_TOTAL : integer := H_DISPLAY + H_FP + H_SP + H_BP;

constant V_DISPLAY : integer := 480;


constant V_FP : integer := 10;
constant V_SP : integer := 2;
constant V_BP : integer := 33;
constant V_TOTAL : integer := V_DISPLAY + V_FP + V_SP + V_BP;

-- Signaux internes
signal h_count : integer range 0 to H_TOTAL - 1 := 0;
signal v_count : integer range 0 to V_TOTAL - 1 := 0;
signal pixel_clk : std_logic := '0';

-- Signaux pour la zone d'affichage et la couleur


signal display_area : std_logic;
signal color_reg : std_logic_vector(2 downto 0);

begin
-- Processus de division d'horloge
clock_div: process(clk100, reset)
variable count : integer range 0 to 1 := 0;
begin
if reset = '0' then
count := 0;
pixel_clk <= '0';
elsif rising_edge(clk100) then
if count = 1 then
count := 0;
pixel_clk <= not pixel_clk;
else
count := count + 1;
end if;
end if;
end process;

-- Compteur horizontal
h_counter: process(pixel_clk, reset)
begin
if reset = '0' then
h_count <= 0;
elsif rising_edge(pixel_clk) then
if h_count = H_TOTAL - 1 then
h_count <= 0;
else
h_count <= h_count + 1;
end if;
end if;
end process;

-- Compteur vertical
v_counter: process(pixel_clk, reset)

3
begin
if reset = '0' then
v_count <= 0;
elsif rising_edge(pixel_clk) then
if h_count = H_TOTAL - 1 then
if v_count = V_TOTAL - 1 then
v_count <= 0;
else
v_count <= v_count + 1;
end if;
end if;
end if;
end process;

-- Génération des signaux de synchronisation


hsync <= '0' when h_count >= H_DISPLAY + H_FP and
h_count < H_DISPLAY + H_FP + H_SP
else '1';

vsync <= '0' when v_count >= V_DISPLAY + V_FP and


v_count < V_DISPLAY + V_FP + V_SP
else '1';

-- Détermination de la zone d'affichage


display_area <= '1' when h_count < H_DISPLAY and v_count < V_DISPLAY else '0';

-- Processus de sélection de la couleur


color_select: process(h_count, v_count, bouton1, bouton2, bouton3)
begin
if display_area = '1' then
-- Division en 4 quadrants
if v_count < V_DISPLAY/2 then
if h_count < H_DISPLAY/2 then
-- Quadrant haut-gauche
color_reg <= bouton1 & bouton2 & bouton3;
else
-- Quadrant haut-droit
color_reg <= not(bouton1) & bouton2 & bouton3;
end if;
else
if h_count < H_DISPLAY/2 then
-- Quadrant bas-gauche
color_reg <= bouton1 & not(bouton2) & bouton3;
else
-- Quadrant bas-droit
color_reg <= bouton1 & bouton2 & not(bouton3);
end if;
end if;
else
color_reg <= "000"; -- Noir hors zone d'affichage
end if;
end process;

-- Sortie des couleurs


red <= color_reg(2) when display_area = '1' else '0';
green <= color_reg(1) when display_area = '1' else '0';
blue <= color_reg(0) when display_area = '1' else '0';

end Behavioral;

3.2 Testbench de Simulation


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

4
entity damier_tb is
end damier_tb;

architecture behavioral of damier_tb is


-- Composant à tester
component damier
Port (
clk100 : in STD_LOGIC;
reset : in STD_LOGIC;
bouton1 : in STD_LOGIC;
bouton2 : in STD_LOGIC;
bouton3 : in STD_LOGIC;
red : out STD_LOGIC;
green : out STD_LOGIC;
blue : out STD_LOGIC;
hsync : out STD_LOGIC;
vsync : out STD_LOGIC
);
end component;

-- Signaux de test
signal clk100_tb : STD_LOGIC := '0';
signal reset_tb : STD_LOGIC := '0';
signal bouton1_tb : STD_LOGIC := '0';
signal bouton2_tb : STD_LOGIC := '0';
signal bouton3_tb : STD_LOGIC := '0';
signal red_tb : STD_LOGIC;
signal green_tb : STD_LOGIC;
signal blue_tb : STD_LOGIC;
signal hsync_tb : STD_LOGIC;
signal vsync_tb : STD_LOGIC;

-- Constantes de simulation
constant CLK_PERIOD : time := 10 ns; -- 100 MHz

begin
-- Instanciation de l'unité sous test
UUT: damier PORT MAP (
clk100 => clk100_tb,
reset => reset_tb,
bouton1 => bouton1_tb,
bouton2 => bouton2_tb,
bouton3 => bouton3_tb,
red => red_tb,
green => green_tb,
blue => blue_tb,
hsync => hsync_tb,
vsync => vsync_tb
);

-- Processus de génération d'horloge


clk_process: process
begin
clk100_tb <= '0';
wait for CLK_PERIOD/2;
clk100_tb <= '1';
wait for CLK_PERIOD/2;
end process;

-- Processus de stimulation
stim_proc: process
begin
-- Initialisation
reset_tb <= '0'; -- Reset actif
bouton1_tb <= '0';

5
bouton2_tb <= '0';
bouton3_tb <= '0';
wait for 100 ns;

-- Libération du reset
reset_tb <= '1';
wait for 100 ns;

-- Test différentes combinaisons de couleurs


-- Quadrant 1 (haut-gauche)
bouton1_tb <= '1';
bouton2_tb <= '1';
bouton3_tb <= '1';
wait for 1 ms;

-- Quadrant 2 (haut-droit)
bouton1_tb <= '0';
bouton2_tb <= '1';
bouton3_tb <= '0';
wait for 1 ms;

-- Quadrant 3 (bas-gauche)
bouton1_tb <= '1';
bouton2_tb <= '0';
bouton3_tb <= '1';
wait for 1 ms;

-- Quadrant 4 (bas-droit)
bouton1_tb <= '0';
bouton2_tb <= '0';
bouton3_tb <= '0';
wait for 1 ms;

-- Fin de la simulation
wait;
end process;
end behavioral;

4. Détails Techniques Avancés


4.1 Gestion de l'Horloge
- Division de l'horloge système 100 MHz en horloge pixel 25 MHz
- Utilisation d'un compteur pour réduire la fréquence
- Synchronisation précise des signaux VGA
4.2 Logique de Sélection des Couleurs
- 3 interrupteurs permettant 8 combinaisons de couleurs (2³)
- Chaque quadrant utilise une combinaison unique des interrupteurs
- Modification dynamique des couleurs sans reconfiguration
4.3 Synchronisation VGA
- Gestion précise des temps de synchronisation horizontaux et verticaux
- Respect strict des spécifications 640x480 @ 60Hz
- Calcul des périodes de synchronisation, front porch, et back porch

5. Procédure de Test

6
5.1 Simulation ModelSim/EDAPlayground
- Vérification des signaux de synchronisation
- Test des différentes configurations de couleur
- Validation du comportement du reset

6. Analyse des Résultats


6.1 Performance
- Utilisation minimale des ressources FPGA
- Latence de commutation négligeable
- Stabilité de l'affichage
6.2 Limitations
- Résolution fixe (640x480)
- Nombre limité de couleurs (8)
- Dépendance à la configuration matérielle spécifique

7. Perspectives d'Amélioration
- Implémentation de résolutions variables
- Palette de couleurs étendue
- Animations ou modes d'affichage dynamiques

Exercice C : Affichage d’une brique


1. Contexte et Problématique
1.1 Objectif du Projet
Développer un contrôleur VGA capable d'afficher une brique de 100x100 pixels, avec une couleur
sélectionnable dynamiquement via des interrupteurs.

1.2 Contraintes Techniques


- Carte de développement : Nexys4
- Fréquence d'horloge : 100 MHz
- Interface VGA 640x480 @ 60Hz
- Sélection de couleur via 3 interrupteurs
- Gestion d'un reset asynchrone
- Taille fixe de la brique : 100x100 pixels
- Positionnement centré de la brique

2. Solution Technique
2.1 Approche Architecturale
- Contrôleur VGA entièrement personnalisé
- Gestion modulaire des composants
- Logique de positionnement et de coloration de la brique

2.2 Éléments Clés


- Division de l'horloge système
- Génération des signaux de synchronisation VGA

7
- Détection de la zone de la brique
- Sélection dynamique de la couleur

3. Détails Techniques
3.1 Génération de l'Horloge
- Conversion horloge système 100 MHz en horloge pixel 25 MHz
- Processus de division d'horloge synchrone
- Gestion précise des fronts d'horloge

3.2 Synchronisation VGA


- Respect des timings 640x480 @ 60Hz
- Génération des signaux hsync et vsync
- Gestion des périodes de synchronisation (front porch, back porch)

3.3 Positionnement de la Brique


- Centrage horizontal et vertical
- Calcul des coordonnées basé sur les dimensions de l'écran
- Constantes prédéfinies pour la taille et la position

3.4 Sélection de Couleur


- 3 interrupteurs permettant 8 combinaisons (2³)
- Mappage direct des interrupteurs aux composantes RGB
- Possibilité de sélectionner dynamiquement la couleur

8
4. Codes Développés
4.1 Code Principal
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity brique is
Port (
clk100 : in STD_LOGIC; -- Horloge 100MHz
reset : in STD_LOGIC; -- Reset asynchrone actif bas
bouton1 : in STD_LOGIC; -- Interrupteur 1
bouton2 : in STD_LOGIC; -- Interrupteur 2
bouton3 : in STD_LOGIC; -- Interrupteur 3
red : out STD_LOGIC; -- Sortie rouge VGA
green : out STD_LOGIC; -- Sortie verte VGA
blue : out STD_LOGIC; -- Sortie bleue VGA
hsync : out STD_LOGIC; -- Synchronisation horizontale
vsync : out STD_LOGIC -- Synchronisation verticale
);
end brique;

architecture Behavioral of brique is


-- Constantes pour la résolution VGA 640x480 @ 60Hz
constant H_DISPLAY : integer := 640;
constant H_FP : integer := 16;
constant H_SP : integer := 96;
constant H_BP : integer := 48;
constant H_TOTAL : integer := H_DISPLAY + H_FP + H_SP + H_BP;

constant V_DISPLAY : integer := 480;


constant V_FP : integer := 10;
constant V_SP : integer := 2;
constant V_BP : integer := 33;
constant V_TOTAL : integer := V_DISPLAY + V_FP + V_SP + V_BP;

-- Constantes pour la brique


constant BRICK_WIDTH : integer := 100;
constant BRICK_HEIGHT : integer := 100;
constant BRICK_X : integer := (H_DISPLAY - BRICK_WIDTH) / 2; -- Centré horizontalement
constant BRICK_Y : integer := (V_DISPLAY - BRICK_HEIGHT) / 2; -- Centré verticalement

-- Signaux internes
signal h_count : integer range 0 to H_TOTAL - 1 := 0;
signal v_count : integer range 0 to V_TOTAL - 1 := 0;
signal pixel_clk : std_logic := '0';

-- Signaux pour la zone d'affichage et la couleur


signal display_area : std_logic;
signal color_reg : std_logic_vector(2 downto 0);
signal brick_area : std_logic;

begin
-- Processus de division d'horloge
clock_div: process(clk100, reset)
variable count : integer range 0 to 1 := 0;

9
begin
if reset = '0' then
count := 0;
pixel_clk <= '0';
elsif rising_edge(clk100) then
if count = 1 then
count := 0;
pixel_clk <= not pixel_clk;
else
count := count + 1;
end if;
end if;
end process;

-- Compteur horizontal
h_counter: process(pixel_clk, reset)
begin
if reset = '0' then
h_count <= 0;
elsif rising_edge(pixel_clk) then
if h_count = H_TOTAL - 1 then
h_count <= 0;
else
h_count <= h_count + 1;
end if;
end if;
end process;

-- Compteur vertical
v_counter: process(pixel_clk, reset)
begin
if reset = '0' then
v_count <= 0;
elsif rising_edge(pixel_clk) then
if h_count = H_TOTAL - 1 then
if v_count = V_TOTAL - 1 then
v_count <= 0;
else
v_count <= v_count + 1;
end if;
end if;
end if;
end process;

-- Génération des signaux de synchronisation


hsync <= '0' when h_count >= H_DISPLAY + H_FP and
h_count < H_DISPLAY + H_FP + H_SP
else '1';

vsync <= '0' when v_count >= V_DISPLAY + V_FP and


v_count < V_DISPLAY + V_FP + V_SP
else '1';

-- Détermination de la zone d'affichage


display_area <= '1' when h_count < H_DISPLAY and v_count < V_DISPLAY else '0';

10
-- Détermination de la zone de la brique
brick_area <= '1' when
display_area = '1' and
h_count >= BRICK_X and h_count < BRICK_X + BRICK_WIDTH and
v_count >= BRICK_Y and v_count < BRICK_Y + BRICK_HEIGHT
else '0';

-- Sélection de la couleur
color_select: process(brick_area, bouton1, bouton2, bouton3)
begin
if brick_area = '1' then
-- Couleur de la brique basée sur les interrupteurs
color_reg <= bouton1 & bouton2 & bouton3;
else
-- Fond noir
color_reg <= "000";
end if;
end process;

-- Sortie des couleurs


red <= color_reg(2) when display_area = '1' else '0';
green <= color_reg(1) when display_area = '1' else '0';
blue <= color_reg(0) when display_area = '1' else '0';

end Behavioral;

4.2 Testbench
library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.NUMERIC_STD.ALL;

entity brique_tb is

end brique_tb;

architecture behavioral of brique_tb is

-- Composant à tester

component brique

Port (

clk100 : in STD_LOGIC;

reset : in STD_LOGIC;

bouton1 : in STD_LOGIC;

bouton2 : in STD_LOGIC;

bouton3 : in STD_LOGIC;

red : out STD_LOGIC;

green : out STD_LOGIC;

11
blue : out STD_LOGIC;

hsync : out STD_LOGIC;

vsync : out STD_LOGIC

);

end component;

-- Signaux de test

signal clk100_tb : STD_LOGIC := '0';

signal reset_tb : STD_LOGIC := '0';

signal bouton1_tb : STD_LOGIC := '0';

signal bouton2_tb : STD_LOGIC := '0';

signal bouton3_tb : STD_LOGIC := '0';

signal red_tb : STD_LOGIC;

signal green_tb : STD_LOGIC;

signal blue_tb : STD_LOGIC;

signal hsync_tb : STD_LOGIC;

signal vsync_tb : STD_LOGIC;

-- Constantes de simulation

constant CLK_PERIOD : time := 10 ns; -- 100 MHz

begin

-- Instanciation de l'unité sous test

UUT: brique PORT MAP (

clk100 => clk100_tb,

reset => reset_tb,

bouton1 => bouton1_tb,

bouton2 => bouton2_tb,

bouton3 => bouton3_tb,

red => red_tb,

green => green_tb,

blue => blue_tb,

hsync => hsync_tb,

vsync => vsync_tb

);

-- Processus de génération d'horloge

clk_process: process

12
begin

clk100_tb <= '0';

wait for CLK_PERIOD/2;

clk100_tb <= '1';

wait for CLK_PERIOD/2;

end process;

-- Processus de stimulation

stim_proc: process

begin

-- Initialisation

reset_tb <= '0'; -- Reset actif

bouton1_tb <= '0';

bouton2_tb <= '0';

bouton3_tb <= '0';

wait for 100 ns;

-- Libération du reset

reset_tb <= '1';

wait for 100 ns;

-- Test différentes combinaisons de couleurs

-- Couleur 1

bouton1_tb <= '1';

bouton2_tb <= '1';

bouton3_tb <= '1';

wait for 1 ms;

-- Couleur 2

bouton1_tb <= '0';

bouton2_tb <= '1';

bouton3_tb <= '0';

wait for 1 ms;

-- Couleur 3

bouton1_tb <= '1';

bouton2_tb <= '0';

bouton3_tb <= '1';

13
wait for 1 ms;

-- Couleur 4

bouton1_tb <= '0';

bouton2_tb <= '0';

bouton3_tb <= '0';

wait for 1 ms;

-- Fin de la simulation

wait;

end process;

end behavioral;

5. Procédure de Test
5.1 Simulation
- Vérification des signaux de synchronisation
- Validation du positionnement de la brique
- Test des différentes configurations de couleur

5.2 Test sur Carte Nexys4


- Validation du câblage VGA
- Test des interrupteurs physiques
- Vérification de l'affichage sur moniteur

6. Résultats et Performance
6.1 Caractéristiques
- Utilisation minimale des ressources FPGA
- Affichage stable et précis
- Flexibilité de configuration couleur

6.2 Limitations
- Taille et position de la brique fixes
- Palette de couleurs limitée (8 couleurs)

14
Exercice D : Affichage de plusieurs briques

Code principal
library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.NUMERIC_STD.ALL;

entity briqueligne is

Port (

clk100 : in STD_LOGIC; -- Horloge 100MHz

reset : in STD_LOGIC; -- Reset asynchrone actif bas

bouton1 : in STD_LOGIC; -- Interrupteur 1

bouton2 : in STD_LOGIC; -- Interrupteur 2

bouton3 : in STD_LOGIC; -- Interrupteur 3

red : out STD_LOGIC; -- Sortie rouge VGA

green : out STD_LOGIC; -- Sortie verte VGA

blue : out STD_LOGIC; -- Sortie bleue VGA

hsync : out STD_LOGIC; -- Synchronisation horizontale

vsync : out STD_LOGIC -- Synchronisation verticale

);

end briqueligne;

architecture Behavioral of briqueligne is

-- Constantes pour la résolution VGA 640x480 @ 60Hz

constant H_DISPLAY : integer := 640;

constant H_FP : integer := 16;

constant H_SP : integer := 96;

constant H_BP : integer := 48;

constant H_TOTAL : integer := H_DISPLAY + H_FP + H_SP + H_BP;

constant V_DISPLAY : integer := 480;

constant V_FP : integer := 10;

constant V_SP : integer := 2;

constant V_BP : integer := 33;

constant V_TOTAL : integer := V_DISPLAY + V_FP + V_SP + V_BP;

-- Constantes pour les briques

constant BRICK_WIDTH : integer := 50;

15
constant BRICK_HEIGHT : integer := 50;

-- Positions des briques (3 briques par ligne, 3 lignes)

constant BRICK_SPACING_X : integer := (H_DISPLAY - (3 * BRICK_WIDTH)) / 4;

-- Ligne 1 (haut)

constant BRICK1_X1 : integer := BRICK_SPACING_X;

constant BRICK1_X2 : integer := BRICK1_X1 + BRICK_WIDTH + BRICK_SPACING_X;

constant BRICK1_X3 : integer := BRICK1_X2 + BRICK_WIDTH + BRICK_SPACING_X;

constant BRICK1_Y : integer := 50;

-- Ligne 2 (milieu)

constant BRICK2_X1 : integer := BRICK1_X1;

constant BRICK2_X2 : integer := BRICK1_X2;

constant BRICK2_X3 : integer := BRICK1_X3;

constant BRICK2_Y : integer := 200;

-- Ligne 3 (bas)

constant BRICK3_X1 : integer := BRICK1_X1;

constant BRICK3_X2 : integer := BRICK1_X2;

constant BRICK3_X3 : integer := BRICK1_X3;

constant BRICK3_Y : integer := 350;

-- Signaux internes

signal h_count : integer range 0 to H_TOTAL - 1 := 0;

signal v_count : integer range 0 to V_TOTAL - 1 := 0;

signal pixel_clk : std_logic := '0';

-- Signaux pour la zone d'affichage et la couleur

signal display_area : std_logic;

signal color_reg : std_logic_vector(2 downto 0);

-- Signaux pour les zones de briques

signal brick_area1_1, brick_area1_2, brick_area1_3 : std_logic;

signal brick_area2_1, brick_area2_2, brick_area2_3 : std_logic;

signal brick_area3_1, brick_area3_2, brick_area3_3 : std_logic;

begin

16
-- Processus de division d'horloge

clock_div: process(clk100, reset)

variable count : integer range 0 to 1 := 0;

begin

if reset = '0' then

count := 0;

pixel_clk <= '0';

elsif rising_edge(clk100) then

if count = 1 then

count := 0;

pixel_clk <= not pixel_clk;

else

count := count + 1;

end if;

end if;

end process;

-- Compteur horizontal

h_counter: process(pixel_clk, reset)

begin

if reset = '0' then

h_count <= 0;

elsif rising_edge(pixel_clk) then

if h_count = H_TOTAL - 1 then

h_count <= 0;

else

h_count <= h_count + 1;

end if;

end if;

end process;

-- Compteur vertical

v_counter: process(pixel_clk, reset)

begin

if reset = '0' then

v_count <= 0;

elsif rising_edge(pixel_clk) then

if h_count = H_TOTAL - 1 then

17
if v_count = V_TOTAL - 1 then

v_count <= 0;

else

v_count <= v_count + 1;

end if;

end if;

end if;

end process;

-- Génération des signaux de synchronisation

hsync <= '0' when h_count >= H_DISPLAY + H_FP and

h_count < H_DISPLAY + H_FP + H_SP

else '1';

vsync <= '0' when v_count >= V_DISPLAY + V_FP and

v_count < V_DISPLAY + V_FP + V_SP

else '1';

-- Détermination de la zone d'affichage

display_area <= '1' when h_count < H_DISPLAY and v_count < V_DISPLAY else '0';

-- Détermination des zones de briques (Ligne 1)

brick_area1_1 <= '1' when

display_area = '1' and

h_count >= BRICK1_X1 and h_count < BRICK1_X1 + BRICK_WIDTH and

v_count >= BRICK1_Y and v_count < BRICK1_Y + BRICK_HEIGHT

else '0';

brick_area1_2 <= '1' when

display_area = '1' and

h_count >= BRICK1_X2 and h_count < BRICK1_X2 + BRICK_WIDTH and

v_count >= BRICK1_Y and v_count < BRICK1_Y + BRICK_HEIGHT

else '0';

brick_area1_3 <= '1' when

display_area = '1' and

h_count >= BRICK1_X3 and h_count < BRICK1_X3 + BRICK_WIDTH and

v_count >= BRICK1_Y and v_count < BRICK1_Y + BRICK_HEIGHT

18
else '0';

-- Détermination des zones de briques (Ligne 2)

brick_area2_1 <= '1' when

display_area = '1' and

h_count >= BRICK2_X1 and h_count < BRICK2_X1 + BRICK_WIDTH and

v_count >= BRICK2_Y and v_count < BRICK2_Y + BRICK_HEIGHT

else '0';

brick_area2_2 <= '1' when

display_area = '1' and

h_count >= BRICK2_X2 and h_count < BRICK2_X2 + BRICK_WIDTH and

v_count >= BRICK2_Y and v_count < BRICK2_Y + BRICK_HEIGHT

else '0';

brick_area2_3 <= '1' when

display_area = '1' and

h_count >= BRICK2_X3 and h_count < BRICK2_X3 + BRICK_WIDTH and

v_count >= BRICK2_Y and v_count < BRICK2_Y + BRICK_HEIGHT

else '0';

-- Détermination des zones de briques (Ligne 3)

brick_area3_1 <= '1' when

display_area = '1' and

h_count >= BRICK3_X1 and h_count < BRICK3_X1 + BRICK_WIDTH and

v_count >= BRICK3_Y and v_count < BRICK3_Y + BRICK_HEIGHT

else '0';

brick_area3_2 <= '1' when

display_area = '1' and

h_count >= BRICK3_X2 and h_count < BRICK3_X2 + BRICK_WIDTH and

v_count >= BRICK3_Y and v_count < BRICK3_Y + BRICK_HEIGHT

else '0';

brick_area3_3 <= '1' when

display_area = '1' and

h_count >= BRICK3_X3 and h_count < BRICK3_X3 + BRICK_WIDTH and

v_count >= BRICK3_Y and v_count < BRICK3_Y + BRICK_HEIGHT

19
else '0';

-- Sélection de la couleur

color_select: process(brick_area1_1, brick_area1_2, brick_area1_3,

brick_area2_1, brick_area2_2, brick_area2_3,

brick_area3_1, brick_area3_2, brick_area3_3,

bouton1, bouton2, bouton3)

begin

if brick_area1_1 = '1' or brick_area1_2 = '1' or brick_area1_3 = '1' then

-- Ligne 1 : Couleur basée sur les boutons

color_reg <= bouton1 & bouton2 & bouton3;

elsif brick_area2_1 = '1' or brick_area2_2 = '1' or brick_area2_3 = '1' then

-- Ligne 2 : Couleur alternative

color_reg <= not(bouton1) & not(bouton2) & bouton3;

elsif brick_area3_1 = '1' or brick_area3_2 = '1' or brick_area3_3 = '1' then

-- Ligne 3 : Couleur alternative différente

color_reg <= bouton1 & not(bouton2) & not(bouton3);

else

-- Fond noir

color_reg <= "000";

end if;

end process;

-- Sortie des couleurs

red <= color_reg(2) when display_area = '1' else '0';

green <= color_reg(1) when display_area = '1' else '0';

blue <= color_reg(0) when display_area = '1' else '0';

end Behavioral;

Code testbench
library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.NUMERIC_STD.ALL;

entity briqueligne_tb is

end briqueligne_tb;

architecture behavioral of briqueligne_tb is

20
-- Composant à tester

component briqueligne

Port (

clk100 : in STD_LOGIC;

reset : in STD_LOGIC;

bouton1 : in STD_LOGIC;

bouton2 : in STD_LOGIC;

bouton3 : in STD_LOGIC;

red : out STD_LOGIC;

green : out STD_LOGIC;

blue : out STD_LOGIC;

hsync : out STD_LOGIC;

vsync : out STD_LOGIC

);

end component;

-- Signaux de test

signal clk100_tb : STD_LOGIC := '0';

signal reset_tb : STD_LOGIC := '0';

signal bouton1_tb : STD_LOGIC := '0';

signal bouton2_tb : STD_LOGIC := '0';

signal bouton3_tb : STD_LOGIC := '0';

signal red_tb : STD_LOGIC;

signal green_tb : STD_LOGIC;

signal blue_tb : STD_LOGIC;

signal hsync_tb : STD_LOGIC;

signal vsync_tb : STD_LOGIC;

-- Constantes de simulation

constant CLK_PERIOD : time := 10 ns; -- 100 MHz

begin

-- Instanciation de l'unité sous test

UUT: briqueligne PORT MAP (

clk100 => clk100_tb,

reset => reset_tb,

bouton1 => bouton1_tb,

bouton2 => bouton2_tb,

21
bouton3 => bouton3_tb,

red => red_tb,

green => green_tb,

blue => blue_tb,

hsync => hsync_tb,

vsync => vsync_tb

);

-- Processus de génération d'horloge

clk_process: process

begin

clk100_tb <= '0';

wait for CLK_PERIOD/2;

clk100_tb <= '1';

wait for CLK_PERIOD/2;

end process;

-- Processus de stimulation

stim_proc: process

begin

-- Initialisation

reset_tb <= '0'; -- Reset actif

bouton1_tb <= '0';

bouton2_tb <= '0';

bouton3_tb <= '0';

wait for 100 ns;

-- Libération du reset

reset_tb <= '1';

wait for 100 ns;

-- Test différentes combinaisons de couleurs

-- Configuration 1

bouton1_tb <= '1';

bouton2_tb <= '1';

bouton3_tb <= '1';

wait for 1 ms;

22
-- Configuration 2

bouton1_tb <= '0';

bouton2_tb <= '1';

bouton3_tb <= '0';

wait for 1 ms;

-- Configuration 3

bouton1_tb <= '1';

bouton2_tb <= '0';

bouton3_tb <= '1';

wait for 1 ms;

-- Configuration 4

bouton1_tb <= '0';

bouton2_tb <= '0';

bouton3_tb <= '0';

wait for 1 ms;

-- Fin de

Conclusion
Le projet démontre une approche méthodique de la création d'un contrôleur VGA
personnalisé, illustrant les principes de conception numérique et de programmation
VHDL.

Captures d'écran de simulation


EXERCICE B

23
EXERCICE C

### Outils Utilisés


- Logiciel de développement VHDL
- EDAPlayground pour simulation
- ModelSim/Riviera Pro

24

Vous aimerez peut-être aussi