Nalyd1002

fpga clock

Sep 22nd, 2023
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. library IEEE;
  2.  
  3. use IEEE.STD_LOGIC_1164.ALL;
  4. use IEEE.STD_LOGIC_ARITH.ALL;
  5. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  6.  
  7. entity I2C_Controller is
  8. Port (
  9. clk : in STD_LOGIC;
  10. scl : out STD_LOGIC;
  11. );
  12. end I2C_Controller;
  13.  
  14. architecture Behavioral of I2C_Controller is
  15. signal time_counter : integer := 0;
  16. signal scl_internal : STD_LOGIC := '0';
  17.  
  18. begin
  19. process (clk)
  20. begin
  21. if rising_edge(clk) then
  22. if time_counter = 120 then -- scl 100 kHz/ fpga clock is 12MHz
  23. time_counter <= 0;
  24. scl_internal <= not scl_internal;
  25. else
  26. time_counter <= time_counter + 1;
  27. end if;
  28. end if;
  29. end process;
  30. scl <= scl_internal;
  31. end architecture Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment