1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-11-21 23:56:04 +01:00
cdf2018-principal/fpga/pwm.vhd

31 lines
665 B
VHDL
Raw Normal View History

2018-05-01 08:45:02 +02:00
-- Inspiré de http://www.fpga4fun.com/PWM_DAC_2.html
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.ALL;
entity PWM is
port (
clk : in std_logic;
data : in std_logic_vector (7 downto 0) := "00000000";
pulse : out std_logic
);
end PWM;
architecture Behavioral of PWM is
2018-05-02 05:50:33 +02:00
signal accuI : integer := 0;
signal dataI : integer := 0;
2018-05-01 08:45:02 +02:00
begin
dataI <= to_integer(unsigned(data));
process(clk, data)
begin
if rising_edge(clk) then
2018-05-02 05:50:33 +02:00
accuI <= accuI mod 256 + dataI;
2018-05-01 08:45:02 +02:00
end if;
end process;
2018-05-02 05:50:33 +02:00
pulse <= '1' when accuI > 256 else '0';
2018-05-01 08:45:02 +02:00
end Behavioral;