Advertisement
Guest User

Untitled

a guest
May 6th, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.93 KB | None | 0 0
  1. HelloWorld.vhd:
  2.  
  3. library ieee;
  4.     use ieee.std_logic_1164.ALL;
  5.     use ieee.numeric_std.ALL;
  6.        
  7. -- Jednostka główna
  8. entity HelloWorld is
  9.     port(
  10.         clk_in: IN STD_LOGIC;
  11.         input0: IN STD_LOGIC;
  12.         input1: IN STD_LOGIC;
  13.         input2: IN STD_LOGIC;
  14.         input3: IN STD_LOGIC;
  15.         led0: OUT STD_LOGIC;
  16.         led1: OUT STD_LOGIC;
  17.         led2: OUT STD_LOGIC;
  18.         led3: OUT STD_LOGIC
  19.     );
  20. end entity;
  21.  
  22. -- Architektura jednostki głównej
  23. architecture HelloWorldImpl of HelloWorld is
  24. begin
  25.     u1: work.DelayedInputDebouncer
  26.         generic map (clkCyclesDelay => 1000000)
  27.         port map (clk_in, input0, led0);
  28.        
  29.     u2: work.DelayedInputDebouncer
  30.         generic map (clkCyclesDelay => 5000000)
  31.         port map (clk_in, input1, led1);
  32.        
  33.     u3: work.DelayedInputDebouncer
  34.         generic map (clkCyclesDelay => 10000000)
  35.         port map (clk_in, input2, led2);
  36.        
  37.     u4: work.DelayedInputDebouncer
  38.         generic map (clkCyclesDelay => 20000000)
  39.         port map (clk_in, input3, led3);
  40.        
  41. end architecture;
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. DelayedInputDebouncer.vhd:
  49.  
  50. library ieee;
  51.     use ieee.std_logic_1164.ALL;
  52.     use ieee.numeric_std.ALL;
  53.        
  54. -- Jednostka główna
  55. entity DelayedInputDebouncer is
  56.     generic (
  57.         clkCyclesDelay: positive := 1000000
  58.     );
  59.    
  60.     port (
  61.         clk_in: IN STD_LOGIC;
  62.         input: IN STD_LOGIC;
  63.         output: OUT STD_LOGIC
  64.     );
  65. end entity;
  66.  
  67. -- Architektura jednostki głównej
  68. architecture DelayedInputDebouncerImpl of DelayedInputDebouncer is
  69.     signal counterReset : STD_LOGIC := '0';
  70.     signal counterEnabled : STD_LOGIC := '0';
  71.     signal counterQ : STD_LOGIC;
  72. begin
  73.     u1: work.PositiveCounter
  74.         generic map (target => clkCyclesDelay)
  75.         port map (clk_in, counterEnabled, counterQ, counterReset);
  76.  
  77.     process (clk_in)
  78.         variable prevInputState : STD_LOGIC := '0';
  79.     begin  
  80.         if (rising_edge(clk_in)) then
  81.             if ((input xor prevInputState) = '1') then
  82.                 if (counterQ = '1') then               
  83.                     prevInputState := not prevInputState;
  84.                     counterReset <= '1';
  85.                 else
  86.                     counterEnabled <= '1';
  87.                     counterReset <= '0';
  88.                 end if;
  89.             elsif (counterQ = '1') then
  90.                 counterReset <= '1';
  91.             end if;
  92.         end if;
  93.        
  94.         output <= prevInputState;
  95.     end process;   
  96. end architecture;
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. PositiveCounter.vhd:
  104.  
  105.  
  106. library ieee;
  107.     use ieee.std_logic_1164.ALL;
  108.     use ieee.numeric_std.ALL;
  109.    
  110.        
  111. -- Jednostka licznika od 0 do target   
  112. entity PositiveCounter is
  113.     generic (
  114.         target: positive := 1000000
  115.     );
  116.    
  117.     port (
  118.         clk_in: IN STD_LOGIC;
  119.         enabled: IN STD_LOGIC;
  120.         Q: OUT STD_LOGIC;
  121.         reset: IN STD_LOGIC
  122.     );
  123. end entity;
  124.  
  125. -- Implementacja licznika
  126. architecture PositiveCounterImpl of PositiveCounter is
  127. begin
  128.     process (clk_in)
  129.         variable clkCounter : integer range 0 to target;
  130.     begin
  131.         if (rising_edge(clk_in)) then
  132.             if (reset = '1') then
  133.                 clkCounter := 0;
  134.                 Q <= '0';
  135.             elsif (enabled = '1' and clkCounter < target) then
  136.                 clkCounter := clkCounter + 1;
  137.                 Q <= '0';
  138.             elsif (clkCounter = target) then
  139.                 Q <= '1';
  140.             end if;
  141.         end if;
  142.     end process;
  143. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement