VHDL Code Listing

July 10, 2008
IFD2303code.txt library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity LED_Driver is port ( clk: in std_logic; -- Clock input por: in std_logic; -- Power-On Reset

IFD2303code.txt

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity LED_Driver is port
(

clk: in std_logic; -- Clock input
por: in std_logic; -- Power-On Reset
a_bus: in std_logic_vector(3 downto 0); -- 4-Bit Address Bus
d_bus: inout std_logic_vector(7 downto 0); -- 8-Bit Data Bus
led_out: out std_logic); -- Output to Red LED


end LED_Driver;

architecture arch_LED_Driver of LED_Driver is

signal Count: std_logic_vector(15 downto 0); -- Internal 16-Counter
signal LedCtl: std_logic; -- LED Control
signal LedMux: std_logic_vector(3 downto 0); -- Led Mode MUX Control
signal LedOut: std_logic; -- Internal signal for Combitorial Logic

begin
counter:
process (clk, por)
begin
if por = '0' then --If POR event
Count <= "0000000000000000"; -- reset counter
elsif clk='1' and clk'event then --If clk changed and is rising edge
Count <= Count + 1; -- increment counter
end if;
end process counter;

indicate_select:
process (LedMux,Count,LedOut,LedCtl)
begin
if(LedCtl='1') then

case LedMux is
-- Governing equation for pulse width at 50% duty cycle
-- PW = 0.5 * (2^n) * (1/f)
-- Where n = Counter Bit used to drive LED, f = Clock Frequency

when "0000" =>
led_out <= LedOut and Count(0);

when "0001" =>
led_out <= LedOut and Count(1);

when "0010" =>
led_out <= LedOut and Count(2);

when "0011" =>
led_out <= LedOut and Count(3);

when "0100" =>
led_out <= LedOut and Count(4);

when "0101" =>
led_out <= LedOut and Count(5);

when "0110" =>
led_out <= LedOut and Count(6);

when "0111" =>
led_out <= LedOut and Count(7);

when "1000" =>
led_out <= LedOut and Count(8);

when "1001" =>
led_out <= LedOut and Count(9);

when "1010" =>
led_out <= LedOut and Count(10);

when "1011" =>
led_out <= LedOut and Count(11);

when "1100" =>
led_out <= LedOut and Count(12);

when "1101" =>
led_out <= LedOut and Count(13);

when "1110" =>
led_out <= LedOut and Count(14);

when "1111" =>
led_out <= LedOut and Count(15);

when others =>
led_out <= '0'; --OFF

end case;
else
led_out <= '0'; --OFF
end if;

end process indicate_select;

write_bus:
process(a_bus, por, d_bus)

begin
if (por = '0') then
LedMux <= "0000";
LedOut <= '0';
LedCtl <= '0';

else

case a_bus is

when "0001" =>
LedCtl <= d_bus(5);
LedOut <= d_bus(4);
LedMux(3) <= d_bus(3);
LedMux(2) <= d_bus(2);
LedMux(1) <= d_bus(1);
LedMux(0) <= d_bus(0);

when others =>
null;

end case;

end if;

end process write_bus;

end arch_LED_Driver;

See associated file

Sponsored Recommendations

Near- and Far-Field Measurements

April 16, 2024
In this comprehensive application note, we delve into the methods of measuring the transmission (or reception) pattern, a key determinant of antenna gain, using a vector network...

DigiKey Factory Tomorrow Season 3: Sustainable Manufacturing

April 16, 2024
Industry 4.0 is helping manufacturers develop and integrate technologies such as AI, edge computing and connectivity for the factories of tomorrow. Learn more at DigiKey today...

Connectivity – The Backbone of Sustainable Automation

April 16, 2024
Advanced interfaces for signals, data, and electrical power are essential. They help save resources and costs when networking production equipment.

Empowered by Cutting-Edge Automation Technology: The Sustainable Journey

April 16, 2024
Advanced automation is key to efficient production and is a powerful tool for optimizing infrastructure and processes in terms of sustainability.

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!