Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------------------------
- ----------------------------------------------------------------------------------
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- use ieee.std_logic_unsigned.all;
- entity pwm is
- port (
- RESET : in STD_LOGIC;
- CLK : in STD_LOGIC;
- DATA_OUT :in STD_LOGIC_VECTOR (7 downto 0);
- ADRES : in STD_LOGIC_VECTOR (1 downto 0);
- NR_W :in STD_LOGIC;
- PWM_OUT : out STD_LOGIC;
- DATA_IN : out STD_LOGIC_VECTOR (7 downto 0)
- );
- end pwm;
- architecture Behavioral of pwm is
- SIGNAL WYPELNIENIE : STD_LOGIC_VECTOR (7 downto 0) := "00000000";
- SIGNAL OKRES : STD_LOGIC_VECTOR (7 downto 0) := "00000000" ;
- SIGNAL START : STD_LOGIC := '0' ;
- SIGNAL LICZNIK : STD_LOGIC_VECTOR (7 downto 0) := "00000000";
- SIGNAL BUFOR : STD_LOGIC_VECTOR (7 downto 0) := "00000000";
- begin
- KONFIGURATOR : PROCESS (CLK, RESET)
- begin
- if(RESET = '0') then
- WYPELNIENIE <= (others => '0');
- OKRES <= (others => '0');
- LICZNIK <= (others => '0');
- BUFOR <= (others => '0');
- elsif (CLK'EVENT AND CLK = '1') then
- if ( NR_W = '1') then
- case ADRES is
- when "00" => OKRES <= DATA_OUT;
- when "01" => WYPELNIENIE <= DATA_OUT;
- when "10" => START <= DATA_OUT(0);
- when others => BUFOR <= "00000000";
- end case;
- elsif (NR_W = '0') then
- case ADRES is
- when "00" => BUFOR <= OKRES;
- when "01" => BUFOR <= WYPELNIENIE;
- when "10" => BUFOR <= "0000000" & START;
- when others => BUFOR <= "00000000";
- end case;
- end if;
- end if;
- end process KONFIGURATOR;
- ZLICZNIK : PROCESS (CLK, RESET, START)
- begin
- if(RESET = '0') then
- LICZNIK <= (others => '0');
- elsif (CLK'event and CLK = '1') then
- if (START = '0') then
- LICZNIK <= (others => '0');
- elsif ( START = '1') then
- if ( LICZNIK >= OKRES - 1) then
- LICZNIK <= LICZNIK + "00000001" ;
- elsif( LICZNIK > OKRES ) then
- LICZNIK <= (others => '0');
- end if;
- end if;
- end if;
- end process ZLICZNIK;
- KOMPARATOR : PROCESS (CLK, RESET, LICZNIK)
- begin
- if ( START = '1') then
- if (CLK'event and CLK = '1') then
- if ( LICZNIK <= OKRES) then
- PWM_OUT <= '1';
- elsif ( LICZNIK > OKRES) then
- PWM_OUT <= '0';
- end if;
- end if;
- end if;
- end process KOMPARATOR;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement