OtavioMonteiro

RelogiosP2

Jul 22nd, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.24 KB | None | 0 0
  1.     library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_ARITH.ALL;
  4. entity relogios is
  5. port (
  6.     clk50mhz:   in STD_LOGIC;
  7.     clk2e1, clk2e2, clk2e3, clk2e4: out STD_LOGIC
  8. );
  9. end relogios;
  10.  
  11. architecture rtl of relogios is
  12.     signal count2e4: INTEGER :=1250 - 1 ; -- para 20000Hz 5e7/2e4 * 1/2 = 2500/2  ; o um garante que a contagem não ultrapasse o valor desejado
  13.     signal count10: INTEGER :=5 - 1; -- Para dividir o clock em 10, implementado de forma a cada 5 passagens do original alternar o valor
  14.    
  15.     signal value2e1: INTEGER range 0 to 5;
  16.     signal value2e2: INTEGER range 0 to 5;
  17.     signal value2e3: INTEGER range 0 to 5;
  18.     signal value2e4: INTEGER range 0 to 1250;
  19.    
  20.     signal clk_state2e1: STD_LOGIC := '0';
  21.     signal clk_state2e2: STD_LOGIC := '0';
  22.     signal clk_state2e3: STD_LOGIC := '0';
  23.     signal clk_state2e4: STD_LOGIC := '0';
  24.    
  25. begin
  26.        
  27.     -- Gerando clock de 20000Hz a partir do clock original de 50MHz
  28.     gen_clock2e4: process(clk50mhz, clk_state2e4)
  29.     begin
  30.         if clk50mhz'event and clk50mhz='1' then
  31.             if value2e4 < count2e4 then
  32.                 value2e4 <= value2e4+1;
  33.             else
  34.                 clk_state2e4 <= not clk_state2e4;
  35.                 value2e4 <= 0;
  36.             end if;
  37.         end if;
  38.     end process;
  39.    
  40.    
  41.     --Gerando clock de 2000Hz a partir do clock de 20000Hz
  42.     gen_clock2e3: process(clk_state2e4)
  43.     begin
  44.         if clk_state2e4'event and clk_state2e4='1' then
  45.             if value2e3 < count10 then
  46.                 value2e3 <= value2e3+1;
  47.             else
  48.                 clk_state2e3 <= not clk_state2e3;
  49.                 value2e3 <= 0;
  50.             end if;
  51.         end if;
  52.     end process;
  53.    
  54.    
  55.     --Gerando clock de 200Hz a partir do clock de 2000Hz
  56.     gen_clock2e2: process(clk_state2e3)
  57.     begin
  58.         if clk_state2e3'event and clk_state2e3='1' then
  59.             if value2e2 < count10 then
  60.                 value2e2 <= value2e2+1;
  61.             else
  62.                 clk_state2e2 <= not clk_state2e2;
  63.                 value2e2 <= 0;
  64.             end if;
  65.         end if;
  66.     end process;
  67.    
  68.     --Gerando clock de 20Hz a partir do clock de 200Hz
  69.     gen_clock2e1: process(clk_state2e2)
  70.     begin
  71.         if clk_state2e2'event and clk_state2e2='1' then
  72.             if value2e1 < count10 then
  73.                 value2e1 <= value2e1+1;
  74.             else
  75.                 clk_state2e1 <= not clk_state2e1;
  76.                 value2e1 <= 0;
  77.             end if;
  78.         end if;
  79.     end process;
  80.    
  81.    
  82.    
  83.     clk2e1 <= clk_state2e1;
  84.     clk2e2 <= clk_state2e2;
  85.     clk2e3 <= clk_state2e3;
  86.     clk2e4 <= clk_state2e4;
  87.  
  88. end rtl;
Add Comment
Please, Sign In to add comment