forked from gregani/la16fw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
led.vhd
71 lines (61 loc) · 2.2 KB
/
led.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
--
-- This file is part of the la16fw project.
--
-- Copyright (C) 2014-2015 Gregor Anich
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
----------------------------------------------------------------------------------
--
-- makes the led blink according to the led_brightness value
--
----------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity led is
port(
clk : in std_logic; -- system clock (48MHz)
tick_1M : in std_logic; -- 1MHz tick
reset : in std_logic; -- reset (sync)
brightness : in std_logic_vector(7 downto 0); -- led pwm value
invert : in std_logic; -- invert output
led : out std_logic -- led output
);
end led;
architecture behavioral of led is
signal count : unsigned(7 downto 0); --pwm counter
signal led_int : std_logic;
begin
process(clk)
begin
if (rising_edge(clk)) then
if (reset = '1') then
count <= (others=>'0'); --clear counter
led_int <= '0'; --turn off led
elsif (tick_1M = '1') then
--increment counter
count <= count + 1;
--update led
if (count = unsigned(brightness)) then
led_int <= '1';
elsif (count = 0) then
led_int <= '0';
end if;
end if;
end if;
end process;
led <= led_int xor invert;
end behavioral;