library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity PWM is
generic(
RESOLUCION: integer:=32
);
port (
clk: in std_logic;
period: IN STD_LOGIC_VECTOR (RESOLUCION-1 downto 0);
duty_cycle: IN STD_LOGIC_VECTOR (RESOLUCION-1 downto 0);
pwm_out: out STD_LOGIC
);
end PWM;
architecture behavior of PWM is
begin
process(clk, period, duty_cycle)
variable count: std_logic_vector(RESOLUCION-1 downto 0):= (others => '0');
begin
if rising_edge(clk) then
count:= count + 1;
if(count >= period) then
count:= (others => '0');
end if;
if(count >= duty_cycle) then
pwm_out <= '0';
else
pwm_out <= '1';
end if;
end if;
end process;
end behavior;