| 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 |
251 |
jshamlet |
-- 0x0 - LED is fully off
|
| 29 |
|
|
-- 0x1 - LED is fully on
|
| 30 |
|
|
-- 0x2 - LED is dimmed to 50%
|
| 31 |
|
|
-- 0x3 - LED Toggles at 1Hz
|
| 32 |
|
|
-- 0x4 - LED fades in and out
|
| 33 |
249 |
jshamlet |
--
|
| 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 |
251 |
jshamlet |
Sys_Freq : real;
|
| 48 |
249 |
jshamlet |
Reset_Level : std_logic
|
| 49 |
|
|
);
|
| 50 |
|
|
port(
|
| 51 |
|
|
Clock : in std_logic;
|
| 52 |
|
|
Reset : in std_logic;
|
| 53 |
|
|
LED_Mode : in std_logic_vector(2 downto 0);
|
| 54 |
|
|
LED_Out : out std_logic
|
| 55 |
|
|
);
|
| 56 |
|
|
end entity;
|
| 57 |
|
|
|
| 58 |
|
|
architecture behave of status_led is
|
| 59 |
|
|
|
| 60 |
251 |
jshamlet |
-- hold the supplied integer.
|
| 61 |
|
|
function ceil_log2 (x : in natural) return natural is
|
| 62 |
|
|
variable retval : natural;
|
| 63 |
|
|
begin
|
| 64 |
|
|
retval := 1;
|
| 65 |
|
|
while ((2**retval) - 1) < x loop
|
| 66 |
|
|
retval := retval + 1;
|
| 67 |
|
|
end loop;
|
| 68 |
|
|
return retval;
|
| 69 |
|
|
end function;
|
| 70 |
249 |
jshamlet |
|
| 71 |
251 |
jshamlet |
signal Dim50Pct_Out : std_logic := '0';
|
| 72 |
249 |
jshamlet |
|
| 73 |
251 |
jshamlet |
constant TAP1 : integer := 16;
|
| 74 |
|
|
constant TAP2 : integer := 21;
|
| 75 |
|
|
constant TAP3 : integer := 22;
|
| 76 |
|
|
constant TAP4 : integer := 23;
|
| 77 |
|
|
|
| 78 |
|
|
constant Init_Seed : std_logic_vector(23 downto 0) := x"000001";
|
| 79 |
|
|
|
| 80 |
|
|
signal d0 : std_logic := '0';
|
| 81 |
|
|
signal LFSR_poly : std_logic_vector(23 downto 0) := (others => '0');
|
| 82 |
|
|
|
| 83 |
|
|
signal Cycle_Toggle : std_logic;
|
| 84 |
|
|
|
| 85 |
249 |
jshamlet |
constant TIMER_MSB : integer range 9 to 20 := 18;
|
| 86 |
|
|
|
| 87 |
251 |
jshamlet |
signal Fade_Timer1 : std_logic_vector(TIMER_MSB downto 0) :=
|
| 88 |
|
|
(others => '0');
|
| 89 |
|
|
signal Fade_Timer2 : std_logic_vector(TIMER_MSB downto 0) :=
|
| 90 |
|
|
(others => '0');
|
| 91 |
|
|
signal Fade_Out : std_logic := '0';
|
| 92 |
249 |
jshamlet |
|
| 93 |
|
|
begin
|
| 94 |
|
|
|
| 95 |
|
|
Output_FF: process( Clock, Reset )
|
| 96 |
|
|
begin
|
| 97 |
|
|
if( Reset = Reset_Level )then
|
| 98 |
|
|
LED_Out <= '0';
|
| 99 |
|
|
elsif( rising_edge(Clock) )then
|
| 100 |
|
|
LED_Out <= '0';
|
| 101 |
|
|
case( LED_Mode )is
|
| 102 |
|
|
when "001" =>
|
| 103 |
|
|
LED_Out <= '1';
|
| 104 |
|
|
when "010" =>
|
| 105 |
|
|
LED_Out <= Dim50Pct_Out;
|
| 106 |
|
|
when "011" =>
|
| 107 |
251 |
jshamlet |
LED_Out <= Cycle_Toggle;
|
| 108 |
249 |
jshamlet |
when "100" =>
|
| 109 |
|
|
LED_Out <= Fade_out;
|
| 110 |
|
|
when others => null;
|
| 111 |
|
|
end case;
|
| 112 |
|
|
end if;
|
| 113 |
|
|
end process;
|
| 114 |
|
|
|
| 115 |
251 |
jshamlet |
d0 <= LFSR_poly(TAP4) xnor LFSR_poly(TAP3) xnor
|
| 116 |
|
|
LFSR_poly(TAP2) xnor LFSR_poly(TAP1);
|
| 117 |
|
|
|
| 118 |
249 |
jshamlet |
Timer_proc: process( Clock, Reset )
|
| 119 |
|
|
begin
|
| 120 |
|
|
if( Reset = Reset_Level )then
|
| 121 |
|
|
Dim50Pct_Out <= '0';
|
| 122 |
251 |
jshamlet |
LFSR_poly <= Init_Seed;
|
| 123 |
|
|
Cycle_Toggle <= '0';
|
| 124 |
249 |
jshamlet |
Fade_Timer1 <= (others => '0');
|
| 125 |
|
|
Fade_Timer2 <= (others => '0');
|
| 126 |
|
|
Fade_out <= '0';
|
| 127 |
|
|
elsif( rising_edge(Clock) )then
|
| 128 |
|
|
Dim50Pct_Out <= not Dim50Pct_Out;
|
| 129 |
|
|
|
| 130 |
251 |
jshamlet |
LFSR_poly <= LFSR_poly(22 downto 0) & d0;
|
| 131 |
|
|
if( LFSR_poly = Init_Seed )then
|
| 132 |
|
|
Cycle_Toggle <= not Cycle_Toggle;
|
| 133 |
249 |
jshamlet |
end if;
|
| 134 |
|
|
|
| 135 |
|
|
Fade_Timer1 <= Fade_Timer1 - 1;
|
| 136 |
|
|
Fade_Timer2 <= Fade_Timer2 - 1;
|
| 137 |
|
|
if( or_reduce(Fade_Timer2) = '0' )then
|
| 138 |
|
|
Fade_Timer2(TIMER_MSB downto TIMER_MSB - 8) <= (others => '1');
|
| 139 |
|
|
Fade_Timer2(TIMER_MSB - 9 downto 0 ) <= (others => '0');
|
| 140 |
|
|
end if;
|
| 141 |
|
|
Fade_out <= Fade_Timer1(TIMER_MSB) xor
|
| 142 |
|
|
Fade_Timer2(TIMER_MSB);
|
| 143 |
|
|
end if;
|
| 144 |
|
|
end process;
|
| 145 |
|
|
|
| 146 |
|
|
end architecture;
|