Você está na página 1de 4

PWM:

El PWM nos sirve para controlar la cantidad de pulsos que le ingresa al


motor en su alimentacin para que se regule la velocidad de dicho
motor. Adems, este circuito va justo despus del control PI.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL;
library UNISIM;
use UNISIM.VComponents.all;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity pwm is
Port ( restart : in STD_LOGIC;
clk : in STD_LOGIC;
dc_data : in STD_LOGIC_VECTOR (15 downto 0);
Ypwm : in STD_LOGIC_VECTOR (10 downto 0);
button : in STD_LOGIC;
aux_switch : in STD_LOGIC;
pwm_signal : out STD_LOGIC;
pwm_signal_aux : out STD_LOGIC;
addr_out : out STD_LOGIC_VECTOR (9 downto 0);
reset : in STD_LOGIC;
switch_per : out STD_LOGIC;
dc_enable : in STD_LOGIC;
limite_tension : in STD_LOGIC;
lazo_activo : out STD_LOGIC);
end pwm;
architecture moduloPWM of pwm is
signal addr_count : integer range 0 to 1000 := 0;
signal addr_aux : integer range 0 to 1023 := 0;
signal addr : std_logic_vector (10 downto 0);

signal
signal
signal
signal

restart_reg : std_logic;
dc_data_10 : std_logic_vector (10 downto 0);
dc_data_lazo : std_logic_vector (10 downto 0);
lazo_activo_aux : std_logic;

begin
--10 LDB de los datos de la memoria
dc_data_10 <= '0' & dc_data (9 downto 0);
--Proceso para la activacion del lazo
enable_lazo : process(clk,reset)
begin
if reset = '1' then
lazo_activo_aux <= '0';
elsif clk='1' and clk'event then
if button ='1' then
lazo_activo_aux <= aux_switch;
end if;
end if;
end process enable_lazo;
lazo_activo <= lazo_activo_aux;
data_lazo: process(clk,reset)
begin
if reset ='1' then
dc_data_lazo <= (others =>'0');
elsif clk='1' and clk'event then
if lazo_activo_aux ='1' then
dc_data_lazo <= dc_data_10 + Ypwm;
else
dc_data_lazo <= dc_data_10;
end if;
end if;
end process data_lazo;
--dc_data_lazo <= dc_data_10 + Ypwm when lazo_activo_aux ='1' else
dc_data_10;
--Proceso para direccionar la memoria cada 1000 ciclos de reloj
ADDRESSING: process(clk,reset)
begin
if reset ='1' then

addr_count <= 0;
addr_aux <= 0;
pwm_signal <= '0';
pwm_signal_aux <= '0';
restart_reg <= '1';
elsif clk ='1' and clk'event then
if restart='1' then
restart_reg <='1';
end if;
if addr_count=998 then
addr_count <= addr_count+1;
if restart_reg='1' then
addr_aux <=0;
restart_reg <= '0';
else
if addr_aux < 999 then
addr_aux <= addr_aux +1;
end if;
end if;
end if;
if addr_count = 999 then
switch_per <= '1';
addr_count <=0;
else
addr_count <= addr_count +1;
switch_per <= '0';
end if;
if limite_tension ='1' then
pwm_signal <='0';
else
if dc_enable ='0' then
if addr_count < 300 then
pwm_signal <= '1';
else
pwm_signal <= '0';
end if;
elsif addr_count < dc_data_lazo then
pwm_signal <= '1';
else
pwm_signal <= '0';
end if;

end if;
--seal pwm auxiliar de ciclo 0.3
if addr_count < 300 then
pwm_signal_aux <= '1';
--end if;
else
pwm_signal_aux <= '0';
end if;
-------end if;
end process ADDRESSING;
addr <= conv_std_logic_vector(addr_aux,11);
addr_out <= addr (9 downto 0);
end moduloPWM;

Você também pode gostar