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

Highly Integrated 20A Digital Power Module for High Current Applications

March 20, 2024
Renesas latest power module delivers the highest efficiency (up to 94% peak) and fast time-to-market solution in an extremely small footprint. The RRM12120 is ideal for space...

Empowering Innovation: Your Power Partner for Tomorrow's Challenges

March 20, 2024
Discover how innovation, quality, and reliability are embedded into every aspect of Renesas' power products.

Article: Meeting the challenges of power conversion in e-bikes

March 18, 2024
Managing electrical noise in a compact and lightweight vehicle is a perpetual obstacle

Power modules provide high-efficiency conversion between 400V and 800V systems for electric vehicles

March 18, 2024
Porsche, Hyundai and GMC all are converting 400 – 800V today in very different ways. Learn more about how power modules stack up to these discrete designs.

Comments

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