Advertisement
Guest User

Untitled

a guest
May 18th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.75 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    12:00:01 05/01/2018
  6. -- Design Name:
  7. -- Module Name:    pwm - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  23.  
  24. -- Uncomment the following library declaration if using
  25. -- arithmetic functions with Signed or Unsigned values
  26. --use IEEE.NUMERIC_STD.ALL;
  27.  
  28. -- Uncomment the following library declaration if instantiating
  29. -- any Xilinx primitives in this code.
  30. --library UNISIM;
  31. --use UNISIM.VComponents.all;
  32.  
  33. entity pwm is
  34.     Port ( clk : in  STD_LOGIC;
  35.            ref_A : in  STD_LOGIC_VECTOR (7 downto 0);
  36.            ref_B : in  STD_LOGIC_VECTOR (7 downto 0);
  37.            dir_A : in  STD_LOGIC;
  38.            dir_B : in  STD_LOGIC;
  39.            A1 : out  STD_LOGIC;
  40.            A2 : out  STD_LOGIC;
  41.            B1 : out  STD_LOGIC;
  42.            B2 : out  STD_LOGIC);
  43. end pwm;
  44.  
  45. architecture Behavioral of pwm is
  46.  
  47. signal counter : STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
  48. signal A : STD_LOGIC := '0';
  49. signal B : STD_LOGIC := '0';
  50.  
  51. begin
  52.     process(clk)
  53.     begin
  54.         if clk='1' and clk'event then
  55.             counter <= counter + 1;
  56.             if counter > ref_A then
  57.                 A <= '0';
  58.             else
  59.                 A <= '1';
  60.             end if;
  61.             if counter > ref_B then
  62.                 B <= '0';
  63.             else
  64.                 B <= '1';
  65.             end if;
  66.         end if;
  67.     end process;
  68.    
  69.     B1 <= B AND dir_B;
  70.     B2 <= B AND NOT dir_B;
  71.     A1 <= A AND dir_A;
  72.     A2 <= A AND NOT dir_A;
  73.    
  74. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement