5
PWM: El PWM nos sirve para controlar la cantidad de pulsos que le ingresa al motor en su alimentación para que se regule la velocidad de dicho motor. Además, este circuito va justo después 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);

Pw Mlo Baton

Embed Size (px)

DESCRIPTION

Pw Mlo Baton

Citation preview

Page 1: Pw Mlo Baton

PWM:

El PWM nos sirve para controlar la cantidad de pulsos que le ingresa al motor en su alimentación para que se regule la velocidad de dicho motor. Además, este circuito va justo después 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;

Page 2: Pw Mlo Baton

signal addr_aux : integer range 0 to 1023 := 0;signal addr : std_logic_vector (10 downto 0);signal restart_reg : std_logic;signal dc_data_10 : std_logic_vector (10 downto 0);signal dc_data_lazo : std_logic_vector (10 downto 0);signal lazo_activo_aux : std_logic;

begin

--10 LDB de los datos de la memoriadc_data_10 <= '0' & dc_data (9 downto 0);

--Proceso para la activacion del lazoenable_lazo : process(clk,reset)beginif reset = '1' thenlazo_activo_aux <= '0';elsif clk='1' and clk'event thenif button ='1' thenlazo_activo_aux <= aux_switch;end if;end if;end process enable_lazo;

lazo_activo <= lazo_activo_aux;

data_lazo: process(clk,reset)beginif reset ='1' thendc_data_lazo <= (others =>'0');elsif clk='1' and clk'event thenif lazo_activo_aux ='1' thendc_data_lazo <= dc_data_10 + Ypwm;elsedc_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

Page 3: Pw Mlo Baton

ADDRESSING: process(clk,reset)beginif reset ='1' thenaddr_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' thenrestart_reg <='1';end if;if addr_count=998 thenaddr_count <= addr_count+1;if restart_reg='1' thenaddr_aux <=0;restart_reg <= '0';elseif addr_aux < 999 thenaddr_aux <= addr_aux +1;end if;end if;end if;

if addr_count = 999 thenswitch_per <= '1';addr_count <=0;elseaddr_count <= addr_count +1;switch_per <= '0';end if;

if limite_tension ='1' thenpwm_signal <='0';elseif dc_enable ='0' thenif addr_count < 300 thenpwm_signal <= '1';elsepwm_signal <= '0';end if;

Page 4: Pw Mlo Baton

elsif addr_count < dc_data_lazo thenpwm_signal <= '1';elsepwm_signal <= '0';end if;end if;--señal pwm auxiliar de ciclo 0.3if addr_count < 300 thenpwm_signal_aux <= '1';--end if;elsepwm_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;