Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 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 = 499) then
  90. if (led_cnt = 3) then
  91. led_cnt <= 0;
  92. end if;
  93. led_cnt <= led_cnt + 1;
  94. end if;
  95.  
  96. if (duty_cycle > 1) then
  97. duty_cycle <= duty_cycle - 1;
  98. pol <= '1';
  99.  
  100.  
  101. else
  102. pol <= '0';
  103. end if;
  104. end if;
  105. end if;
  106. end if;
  107. end process;
  108.  
  109. ccase: process(led_cnt)
  110. begin
  111. case led_cnt is
  112. when 0 => led_0 <= pulse_pass;
  113. when 1 => led_1 <= pulse_pass;
  114. when 2 => led_2 <= pulse_pass;
  115. when 3 => led_3 <= pulse_pass;
  116. end case;
  117. end process;
  118.  
  119.  
  120. --button: process(btn_0)
  121. --begin
  122. -- if btn_0 = '1' then
  123. --
  124. -- i <= i + 1;
  125. -- case i is
  126. -- when 0 => led_1 <= pulse_pass;
  127. -- when 1 => led_2 <= pulse_pass;
  128. -- end case;
  129. -- end if;
  130. ---- for i in 0 to 1
  131. ---- loop
  132. ----
  133. ---- end loop;
  134. --end process;
  135.  
  136. pwm0: pwm
  137. generic map(
  138. max_val => 1000,
  139. val_bits => 10
  140. )
  141. port map(
  142. clk => clk,
  143. val_cur => duty_cycle,
  144. pulse => pulse_pass
  145. );
  146.  
  147. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement