Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 14:33:36 07/21/2017
  6. -- Design Name:
  7. -- Module Name: svet - 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 svet is
  34. Port( clk : in STD_LOGIC;
  35. led_0 : out std_logic;
  36. led_1 : out std_logic;
  37. led_2 : out std_logic;
  38. led_3 : out std_logic);
  39. end svet;
  40.  
  41. architecture Behavioral of svet is
  42.  
  43. signal pulse_pass, flag, pol: std_logic;
  44. signal led_cnt: integer range 0 to 3 := 0;
  45. signal clk_div: std_logic_vector(15 downto 0);
  46. signal duty_cycle: std_logic_vector(9 downto 0);
  47.  
  48. component pwm is
  49. generic( max_val: integer := 1000;
  50. val_bits: integer := 10);
  51. port( clk: in std_logic;
  52. val_cur: in std_logic_vector((val_bits -1) downto 0);
  53. pulse: out std_logic);
  54. end component;
  55.  
  56. begin
  57.  
  58.  
  59.  
  60. --led_0 <= pulse_pass;
  61.  
  62. clockDivider: process(clk) -- Clock Divide
  63. begin
  64. if(clk'event and clk = '1') then
  65. if (clk_div < 1_999) then
  66. clk_div <= clk_div + 1;
  67. flag <= '0';
  68. else
  69. clk_div <= (others => '0');
  70. flag <= '1';
  71.  
  72. end if;
  73. end if;
  74. end process;
  75.  
  76. dutyCycle: process(clk) -- Duty Cycle
  77. begin
  78. if(clk'event and clk = '1') then
  79. if (flag = '1') then -- 1ms Pulse
  80. if (pol = '0') then -- Polarity
  81. if (duty_cycle < 999) then
  82. duty_cycle <= duty_cycle + 1;
  83. pol <= '0';
  84.  
  85. else
  86. pol <= '1';
  87. end if;
  88. else
  89. if (duty_cycle = 799) then
  90. if (led_cnt = 3) then
  91. led_cnt <= 0;
  92. end if;
  93. led_cnt <= led_cnt + 1;
  94.  
  95. elsif (duty_cycle > 1) then
  96. duty_cycle <= duty_cycle - 1;
  97. pol <= '1';
  98.  
  99.  
  100. else
  101. pol <= '0';
  102. end if;
  103. end if;
  104. end if;
  105. end if;
  106. end process;
  107.  
  108. ccase: process(led_cnt)
  109. begin
  110. case led_cnt is
  111. when 0 => led_0 <= pulse_pass;
  112. when 1 => led_1 <= pulse_pass;
  113. when 2 => led_2 <= pulse_pass;
  114. when 3 => led_3 <= pulse_pass;
  115. end case;
  116. end process;
  117.  
  118.  
  119. --button: process(btn_0)
  120. --begin
  121. -- if btn_0 = '1' then
  122. --
  123. -- i <= i + 1;
  124. -- case i is
  125. -- when 0 => led_1 <= pulse_pass;
  126. -- when 1 => led_2 <= pulse_pass;
  127. -- end case;
  128. -- end if;
  129. ---- for i in 0 to 1
  130. ---- loop
  131. ----
  132. ---- end loop;
  133. --end process;
  134.  
  135. pwm0: pwm
  136. generic map(
  137. max_val => 1000,
  138. val_bits => 10
  139. )
  140. port map(
  141. clk => clk,
  142. val_cur => duty_cycle,
  143. pulse => pulse_pass
  144. );
  145.  
  146. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement