Cours:TP M1102 TP 5 Corr : Différence entre versions

De troyesGEII
Aller à : navigation, rechercher
m (Deuxième façon : on utilise les LPM)
m (Deuxième façon : on utilise les LPM)
Ligne 92 : Ligne 92 :
 
USE lpm.lpm_components.ALL;
 
USE lpm.lpm_components.ALL;
  
 +
ENTITY compteur IS PORT (
 +
  clk: IN std_logic;
 +
  Leds8: OUT std_logic_vector(7 downto 0));
 +
END compteur;
  
----------------------------------
+
ARCHITECTURE arch_compteur OF compteur IS
-- a mettre dans l'architecture --
+
 
--    apres le begin            --
+
  -- LE FIL INTENE
----------------------------------
+
  SIGNAL s_horloge_lente : std_logic;
ic2: lpm_counter GENERIC MAP (
+
 
    LPM_WIDTH => 8
+
BEGIN
 +
  -- compteur 24 bits
 +
  ic1: lpm_counter GENERIC MAP (
 +
            LPM_WIDTH => 24
 +
  )
 +
  PORT MAP (CLOCK => clk,
 +
            q(23) => s_horloge_lente);
 +
  -- compteur 8 bits
 +
  ic2: lpm_counter GENERIC MAP (
 +
            LPM_WIDTH => 8
 
   )
 
   )
   PORT MAP (CLOCK => s_clk_slow,
+
   PORT MAP (CLOCK => clk,
    q(7 downto 4) => s_transcod1,
+
            q => Leds8);
    q(3 downto 0) => s_transcod0);
 
 
 
 
</source>
 
</source>
  

Version du 29 septembre 2020 à 14:49

TP 5

Exercice 1

L'exercice 1 a déjà été corrigé dans Corrigé du TP4 (Exercice 4). Il ne sera donc réalisé en TP5 que s'il ne l'a pas été en TP 4.

Exercice 2

Question 1

On vous présente plusieurs corrections de cet exercice. L'enseignant les présentera toutes ou en choisira quelques unes.

Première façon : on fait tout soi-même

Le compteur 8 bits utilisé ici était donné dans le TP4. On a simplement modifié le nom de son horloge.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
ENTITY compteur IS PORT (
  clk: IN std_logic;
  Leds8: OUT std_logic_vector(7 downto 0));
END compteur;

ARCHITECTURE arch_compteur OF compteur IS
-- les composants :
COMPONENT cmpt8bits IS
  PORT(clk : IN STD_LOGIC;
    cnt : OUT STD_LOGIC_VECTOR(7 DOWNTO 0));
END COMPONENT cmpt8bits;

COMPONENT cmpt24bits IS
  PORT(clk_50MHz : IN STD_LOGIC; -- une seule entrée
    clk_slow : OUT STD_LOGIC); -- une seule sortie
END COMPONENT cmpt24bits;
-- LE FIL INTENE
SIGNAL s_hologe_lente : std_logic;
BEGIN
  i1 : cmpt24bits PORT MAP(
      clk_50MHz => clk,
      clk_slow => s_hologe_lente);
	 
  i2 : cmpt8bits PORT MAP (
         clk => s_hologe_lente,
	 cnt => leds8);
END arch_compteur;

-- Compteur 8 bits
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
ENTITY cmpt8bits IS
  PORT(clk : IN STD_LOGIC;
    cnt : OUT STD_LOGIC_VECTOR(7 DOWNTO 0));
END cmpt8bits;
 
ARCHITECTURE arch_cmpt8bits OF cmpt8bits IS
  signal cmpt : std_logic_vector(7 downto 0);
BEGIN
  process(clk_50) begin
    if rising_edge(clk_50) then
      cmpt <= cmpt + 1;
    end if;
  end process;
  cnt <= cmpt;  
END arch_cmpt8bits;

-- horloge lente 3 Hz
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
ENTITY cmpt24bits IS
  PORT(clk_50MHz : IN STD_LOGIC; -- une seule entrée
    clk_slow : OUT STD_LOGIC); -- une seule sortie
END cmpt24bits;
 
ARCHITECTURE arch_cmpt24bits OF cmpt24bits IS
  signal cmpt : std_logic_vector(23 downto 0);
BEGIN
  process(clk_50MHz) begin
    if rising_edge(clk_50MHz) then
      cmpt <= cmpt + 1;
    end if;
  end process;
  clk_slow <= cmpt(23);  -- partie combinatoire de construction de l'horloge lente
END arch_cmpt24bits;

Deuxième façon : on utilise les LPM

-- a mettre dans la partie entête
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
LIBRARY lpm; -- for LPM
USE lpm.lpm_components.ALL;

ENTITY compteur IS PORT (
  clk: IN std_logic;
  Leds8: OUT std_logic_vector(7 downto 0));
END compteur;

ARCHITECTURE arch_compteur OF compteur IS

  -- LE FIL INTENE
  SIGNAL s_horloge_lente : std_logic;

BEGIN
  -- compteur 24 bits
  ic1: lpm_counter GENERIC MAP (
            LPM_WIDTH => 24
  )
  PORT MAP (CLOCK => clk,
            q(23) => s_horloge_lente);
  -- compteur 8 bits
  ic2: lpm_counter GENERIC MAP (
            LPM_WIDTH => 8
  )
  PORT MAP (CLOCK => clk,
            q => Leds8);

Troisième façon : on remarque que le problème est de créer deux compteurs cascdés que l'on peut regrouper

Question 2

Question 3

Exercice 3

Exercice 4