-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPWM_DAC.vhd
37 lines (31 loc) · 910 Bytes
/
PWM_DAC.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
entity PWM_DAC is
Generic ( width : integer := 9);
Port ( reset : in STD_LOGIC;
clk : in STD_LOGIC;
duty_cycle : in STD_LOGIC_VECTOR (width-1 downto 0);
pwm_out : out STD_LOGIC
);
end PWM_DAC;
architecture Behavioral of PWM_DAC is
signal counter : unsigned (width-1 downto 0);
begin
count : process(clk,reset)
begin
if( reset = '1') then
counter <= (others => '0');
elsif (rising_edge(clk)) then
counter <= counter + 1;
end if;
end process;
compare : process(counter, duty_cycle)
begin
if (counter < unsigned(duty_cycle)) then
pwm_out <= '1';
else
pwm_out <= '0';
end if;
end process;
end Behavioral;