Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.38 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 09.04.2018 08:30:38
  6. -- Design Name:
  7. -- Module Name: PWM_driver - 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.  
  21.  
  22. library IEEE;
  23. use IEEE.STD_LOGIC_1164.ALL;
  24.  
  25. -- Uncomment the following library declaration if using
  26. -- arithmetic functions with Signed or Unsigned values
  27. use IEEE.NUMERIC_STD.ALL;
  28.  
  29. -- Uncomment the following library declaration if instantiating
  30. -- any Xilinx leaf cells in this code.
  31. --library UNISIM;
  32. --use UNISIM.VComponents.all;
  33.  
  34. entity PWM_driver is
  35.     Generic ( CNT_WIDTH   : INTEGER := 256
  36.              -- NUM_OUTPUTS : INTEGER
  37.               );
  38.     Port    ( clk    : in STD_LOGIC;
  39.               ce     : in STD_LOGIC;
  40.               --duty_i : in UNSIGNED (6 DOWNTO 0); --STD_LOGIC_VECTOR (6 DOWNTO 0);
  41.               pwm_o  : out STD_LOGIC--_VECTOR ((NUM_OUTPUTS-1) TO 0)
  42.               );
  43. end PWM_driver;
  44.  
  45. architecture Behavioral of PWM_driver is
  46.  
  47.     constant duty : UNSIGNED(6 DOWNTO 0) := TO_UNSIGNED(50,7);
  48.  
  49.     signal counter  : UNSIGNED (31 downto 0):= X"00000000";
  50.     signal pwm      : STD_LOGIC;
  51.     signal pwm_v    : STD_LOGIC_VECTOR (0 DOWNTO 0);
  52.     signal duty_i : UNSIGNED (6 DOWNTO 0);
  53.     COMPONENT ila_0
  54.     PORT (
  55.         clk : IN STD_LOGIC;
  56.         probe0 : IN STD_LOGIC_VECTOR(0 DOWNTO 0)
  57.     );
  58.     END COMPONENT  ;
  59.    
  60. begin
  61.  
  62.     duty_i <= duty;
  63.  
  64.     process(clk) begin
  65.         if rising_edge(clk) then
  66.             if ce = '1' then
  67.                 if counter < CNT_WIDTH then
  68.                     counter <= counter + 1;
  69.                     if counter < (CNT_WIDTH*TO_INTEGER(duty_i)/100) then
  70.                         pwm <= '1';
  71.                     else
  72.                         pwm <= '0';
  73.                     end if;
  74.                 else
  75.                     counter <= X"00000000";
  76.                     pwm <= '1';
  77.                 end if;
  78.             end if;
  79.         end if;    
  80.     end process;
  81.    
  82.    
  83.     pwm_v(0) <= pwm;
  84.     your_instance_name : ila_0
  85.     PORT MAP (
  86.         clk => clk,
  87.         probe0 => pwm_v
  88.     );
  89.    
  90.    
  91. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement