Un circuit générateur PWM comprend par exemple :
Un compteur libre sur N bits piloté par une horloge de référence clk avec un comparateur sur N bits qui compare la sortie du compteur avec son modulo (FREQ : ce qui permet de fixer la fréquence de la PWM).
Un comparateur sur N bits qui compare la sortie du compteur avec le rapport cyclique désiré (DUTY). La sortie de ce comparateur génère la sortie pwm_out.
Une entrée reset_n RAZ asynchrone active à 0.
Pour le TP nous prendrons N=4 (4 bits pour FREQ et 4 bits pour duty)
4 inters pour fixer la fréquence et 4 inters pour fixer le rapport cyclique
Chercher les 2 programmes VHDL des 2 blocs ci-dessous (Compteur et Comparateur)
library ieee;
use ieee.std_logic_1164.all;
--use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Compteur_4N is port (
clk: in std_logic;
reset_n: in std_logic;
FREQ : in std_logic_vector (3 downto 0);
sortie1 : out std_logic_vector( 3 downto 0));
end Compteur_4N;
architecture description_Compteur_4N of Compteur_4N is
signal cmt:std_logic_vector(3 downto 0);
begin
process (clk,reset_n) begin
if (reset_n ='0') then cmt <="0000";
elsif (clk'event and clk='1') then
if (cmt<FREQ) then
cmt <= cmt + '1';
else
cmt<= "0000";
end if;
end if;
end process;
sortie1 <= cmt;
end description_Compteur_4N;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
entity comparateur_4N is port (
clk,reset_n : in std_logic;
FREQ : in std_logic_vector (3 downto 0);
DUTY : in std_logic_vector (3 downto 0);
sortie1 : in std_logic_vector (3 downto 0);
s : out std_logic);
end comparateur_4N;
architecture description_comparateur_4N of comparateur_4N is
begin
process(clk,reset_n)
begin
if reset_n = '0' then s <= '0' ;
elsif clk='1'and clk'event then
if (DUTY<FREQ) then
if (sortie1 < DUTY ) then s <= '1';
else s<='0';
end if;
end if;
end if;
end process;
end description_comparateur_4N;