Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2.  
  3. ----------------------------------------------------------------------------------
  4. library IEEE;
  5. use IEEE.STD_LOGIC_1164.ALL;
  6. use ieee.std_logic_unsigned.all;
  7.  
  8. entity pwm is
  9.  
  10. port (
  11. RESET : in STD_LOGIC;
  12. CLK : in STD_LOGIC;
  13. DATA_OUT :in STD_LOGIC_VECTOR (7 downto 0);
  14. ADRES : in STD_LOGIC_VECTOR (1 downto 0);
  15. NR_W :in STD_LOGIC;
  16.  
  17. PWM_OUT : out STD_LOGIC;
  18. DATA_IN : out STD_LOGIC_VECTOR (7 downto 0)
  19. );
  20. end pwm;
  21.  
  22. architecture Behavioral of pwm is
  23. SIGNAL WYPELNIENIE : STD_LOGIC_VECTOR (7 downto 0) := "00000000";
  24. SIGNAL OKRES : STD_LOGIC_VECTOR (7 downto 0) := "00000000" ;
  25. SIGNAL START : STD_LOGIC := '0' ;
  26. SIGNAL LICZNIK : STD_LOGIC_VECTOR (7 downto 0) := "00000000";
  27. SIGNAL BUFOR : STD_LOGIC_VECTOR (7 downto 0) := "00000000";
  28. begin
  29.  
  30. KONFIGURATOR : PROCESS (CLK, RESET)
  31. begin
  32. if(RESET = '0') then
  33. WYPELNIENIE <= (others => '0');
  34. OKRES <= (others => '0');
  35. LICZNIK <= (others => '0');
  36. BUFOR <= (others => '0');
  37.  
  38. elsif (CLK'EVENT AND CLK = '1') then
  39. if ( NR_W = '1') then
  40. case ADRES is
  41. when "00" => OKRES <= DATA_OUT;
  42. when "01" => WYPELNIENIE <= DATA_OUT;
  43. when "10" => START <= DATA_OUT(0);
  44. when others => BUFOR <= "00000000";
  45. end case;
  46.  
  47. elsif (NR_W = '0') then
  48. case ADRES is
  49. when "00" => BUFOR <= OKRES;
  50. when "01" => BUFOR <= WYPELNIENIE;
  51. when "10" => BUFOR <= "0000000" & START;
  52. when others => BUFOR <= "00000000";
  53. end case;
  54. end if;
  55. end if;
  56. end process KONFIGURATOR;
  57.  
  58.  
  59. ZLICZNIK : PROCESS (CLK, RESET, START)
  60. begin
  61. if(RESET = '0') then
  62. LICZNIK <= (others => '0');
  63.  
  64. elsif (CLK'event and CLK = '1') then
  65. if (START = '0') then
  66. LICZNIK <= (others => '0');
  67. elsif ( START = '1') then
  68. if ( LICZNIK >= OKRES - 1) then
  69. LICZNIK <= LICZNIK + "00000001" ;
  70. elsif( LICZNIK > OKRES ) then
  71. LICZNIK <= (others => '0');
  72. end if;
  73. end if;
  74. end if;
  75. end process ZLICZNIK;
  76.  
  77. KOMPARATOR : PROCESS (CLK, RESET, LICZNIK)
  78. begin
  79. if ( START = '1') then
  80. if (CLK'event and CLK = '1') then
  81. if ( LICZNIK <= OKRES) then
  82. PWM_OUT <= '1';
  83. elsif ( LICZNIK > OKRES) then
  84. PWM_OUT <= '0';
  85. end if;
  86. end if;
  87. end if;
  88. end process KOMPARATOR;
  89.  
  90. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement