1 |
249 |
jshamlet |
-- Copyright (c)2020 Jeremy Seth Henry
|
2 |
|
|
-- All rights reserved.
|
3 |
|
|
--
|
4 |
|
|
-- Redistribution and use in source and binary forms, with or without
|
5 |
|
|
-- modification, are permitted provided that the following conditions are met:
|
6 |
|
|
-- * Redistributions of source code must retain the above copyright
|
7 |
|
|
-- notice, this list of conditions and the following disclaimer.
|
8 |
|
|
-- * Redistributions in binary form must reproduce the above copyright
|
9 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
10 |
|
|
-- documentation and/or other materials provided with the distribution,
|
11 |
|
|
-- where applicable (as part of a user interface, debugging port, etc.)
|
12 |
|
|
--
|
13 |
|
|
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
|
14 |
|
|
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15 |
|
|
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16 |
|
|
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
|
17 |
|
|
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18 |
|
|
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19 |
|
|
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
20 |
|
|
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21 |
|
|
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
22 |
|
|
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23 |
|
|
--
|
24 |
|
|
-- VHDL Units : status_led
|
25 |
|
|
-- Description: Provides a multi-state status LED controller
|
26 |
|
|
--
|
27 |
|
|
-- LED Modes:
|
28 |
|
|
-- 0x00 - LED is fully off
|
29 |
|
|
-- 0x01 - LED is fully on
|
30 |
|
|
-- 0x02 - LED is dimmed to 50%
|
31 |
|
|
-- 0x03 - LED Toggles at 1Hz
|
32 |
|
|
-- 0x04 - LED fades in and out
|
33 |
|
|
--
|
34 |
|
|
-- Revision History
|
35 |
|
|
-- Author Date Change
|
36 |
|
|
------------------ -------- ---------------------------------------------------
|
37 |
|
|
-- Seth Henry 05/24/20 Created as a separate sub-component
|
38 |
|
|
|
39 |
|
|
library ieee;
|
40 |
|
|
use ieee.std_logic_1164.all;
|
41 |
|
|
use ieee.std_logic_unsigned.all;
|
42 |
|
|
use ieee.std_logic_arith.all;
|
43 |
|
|
use ieee.std_logic_misc.all;
|
44 |
|
|
|
45 |
|
|
entity status_led is
|
46 |
|
|
generic(
|
47 |
|
|
Reset_Level : std_logic
|
48 |
|
|
);
|
49 |
|
|
port(
|
50 |
|
|
Clock : in std_logic;
|
51 |
|
|
Reset : in std_logic;
|
52 |
|
|
LED_Mode : in std_logic_vector(2 downto 0);
|
53 |
|
|
LED_Out : out std_logic
|
54 |
|
|
);
|
55 |
|
|
end entity;
|
56 |
|
|
|
57 |
|
|
architecture behave of status_led is
|
58 |
|
|
|
59 |
|
|
signal Dim50Pct_Out : std_logic;
|
60 |
|
|
|
61 |
|
|
signal Half_Hz_Timer : std_logic_vector(15 downto 0);
|
62 |
|
|
constant HALF_HZ_PRD : std_logic_vector(15 downto 0) :=
|
63 |
|
|
conv_std_logic_vector(500000,16);
|
64 |
|
|
signal One_Hz_Out : std_logic;
|
65 |
|
|
|
66 |
|
|
constant TIMER_MSB : integer range 9 to 20 := 18;
|
67 |
|
|
|
68 |
|
|
signal Fade_Timer1 : std_logic_vector(TIMER_MSB downto 0);
|
69 |
|
|
signal Fade_Timer2 : std_logic_vector(TIMER_MSB downto 0);
|
70 |
|
|
signal Fade_Out : std_logic;
|
71 |
|
|
|
72 |
|
|
begin
|
73 |
|
|
|
74 |
|
|
Output_FF: process( Clock, Reset )
|
75 |
|
|
begin
|
76 |
|
|
if( Reset = Reset_Level )then
|
77 |
|
|
LED_Out <= '0';
|
78 |
|
|
elsif( rising_edge(Clock) )then
|
79 |
|
|
LED_Out <= '0';
|
80 |
|
|
case( LED_Mode )is
|
81 |
|
|
when "001" =>
|
82 |
|
|
LED_Out <= '1';
|
83 |
|
|
when "010" =>
|
84 |
|
|
LED_Out <= Dim50Pct_Out;
|
85 |
|
|
when "011" =>
|
86 |
|
|
LED_Out <= One_Hz_Out;
|
87 |
|
|
when "100" =>
|
88 |
|
|
LED_Out <= Fade_out;
|
89 |
|
|
when others => null;
|
90 |
|
|
end case;
|
91 |
|
|
end if;
|
92 |
|
|
end process;
|
93 |
|
|
|
94 |
|
|
Timer_proc: process( Clock, Reset )
|
95 |
|
|
begin
|
96 |
|
|
if( Reset = Reset_Level )then
|
97 |
|
|
Dim50Pct_Out <= '0';
|
98 |
|
|
Half_Hz_Timer <= (others => '0');
|
99 |
|
|
One_Hz_Out <= '0';
|
100 |
|
|
Fade_Timer1 <= (others => '0');
|
101 |
|
|
Fade_Timer2 <= (others => '0');
|
102 |
|
|
Fade_out <= '0';
|
103 |
|
|
elsif( rising_edge(Clock) )then
|
104 |
|
|
Dim50Pct_Out <= not Dim50Pct_Out;
|
105 |
|
|
|
106 |
|
|
Half_Hz_Timer <= Half_Hz_Timer - 1;
|
107 |
|
|
if( Half_Hz_Timer = 0 )then
|
108 |
|
|
Half_Hz_Timer <= HALF_HZ_PRD;
|
109 |
|
|
One_Hz_Out <= not One_Hz_Out;
|
110 |
|
|
end if;
|
111 |
|
|
|
112 |
|
|
Fade_Timer1 <= Fade_Timer1 - 1;
|
113 |
|
|
Fade_Timer2 <= Fade_Timer2 - 1;
|
114 |
|
|
if( or_reduce(Fade_Timer2) = '0' )then
|
115 |
|
|
Fade_Timer2(TIMER_MSB downto TIMER_MSB - 8) <= (others => '1');
|
116 |
|
|
Fade_Timer2(TIMER_MSB - 9 downto 0 ) <= (others => '0');
|
117 |
|
|
end if;
|
118 |
|
|
Fade_out <= Fade_Timer1(TIMER_MSB) xor
|
119 |
|
|
Fade_Timer2(TIMER_MSB);
|
120 |
|
|
end if;
|
121 |
|
|
end process;
|
122 |
|
|
|
123 |
|
|
end architecture;
|