Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use ieee.std_logic_unsigned.all;
  4.  
  5. -- Uncomment the following library declaration if using
  6. -- arithmetic functions with Signed or Unsigned values
  7. --use IEEE.NUMERIC_STD.ALL;
  8.  
  9. -- Uncomment the following library declaration if instantiating
  10. -- any Xilinx primitives in this code.
  11. --library UNISIM;
  12. --use UNISIM.VComponents.all;
  13.  
  14. entity svet is
  15. Port( clk : in STD_LOGIC;
  16. led_0 : out std_logic;
  17. led_1 : out std_logic;
  18. led_2 : out std_logic;
  19. led_3 : out std_logic);
  20. end svet;
  21.  
  22. architecture Behavioral of svet is
  23.  
  24. signal pulse_pass, flag, pol: std_logic;
  25. signal led_cnt: integer range 0 to 3 := 0;
  26. signal clk_div: std_logic_vector(15 downto 0);
  27. signal duty_cycle: std_logic_vector(9 downto 0);
  28.  
  29. component pwm is
  30. generic( max_val: integer := 1000;
  31. val_bits: integer := 10);
  32. port( clk: in std_logic;
  33. val_cur: in std_logic_vector((val_bits -1) downto 0);
  34. pulse: out std_logic);
  35. end component;
  36.  
  37. begin
  38.  
  39.  
  40.  
  41. --led_0 <= pulse_pass;
  42.  
  43. clockDivider: process(clk) -- Clock Divide
  44. begin
  45. if(clk'event and clk = '1') then
  46. if (clk_div < 7_999) then
  47. clk_div <= clk_div + 1;
  48. flag <= '0';
  49. else
  50. clk_div <= (others => '0');
  51. flag <= '1';
  52.  
  53. end if;
  54. end if;
  55. end process;
  56.  
  57. dutyCycle: process(clk) -- Duty Cycle
  58. begin
  59. if(clk'event and clk = '1') then
  60. if (flag = '1') then -- 1ms Pulse
  61. if (pol = '0') then -- Polarity
  62. if (duty_cycle < 999) then
  63. duty_cycle <= duty_cycle + 1;
  64. pol <= '0';
  65.  
  66. else
  67. pol <= '1';
  68. end if;
  69. else
  70. if(duty_cycle<300) then
  71. if (led_cnt = 3) then
  72. led_cnt <= 0;
  73. end if;
  74. led_cnt <= led_cnt + 1;
  75. endif;
  76. if (duty_cycle > 1) then
  77. duty_cycle <= duty_cycle - 1;
  78. pol <= '1';
  79. else
  80. pol <= '0';
  81. end if;
  82. end if;
  83. end if;
  84. end if;
  85. end process;
  86.  
  87. ccase: process(led_cnt)
  88. begin
  89. case led_cnt is
  90. when 0 => led_0 <= pulse_pass;
  91. when 1 => led_1 <= pulse_pass;
  92. when 2 => led_2 <= pulse_pass;
  93. when 3 => led_3 <= pulse_pass;
  94. end case;
  95. end process;
  96.  
  97.  
  98. --button: process(btn_0)
  99. --begin
  100. -- if btn_0 = '1' then
  101. --
  102. -- i <= i + 1;
  103. -- case i is
  104. -- when 0 => led_1 <= pulse_pass;
  105. -- when 1 => led_2 <= pulse_pass;
  106. -- end case;
  107. -- end if;
  108. ---- for i in 0 to 1
  109. ---- loop
  110. ----
  111. ---- end loop;
  112. --end process;
  113.  
  114. pwm0: pwm
  115. generic map(
  116. max_val => 1000,
  117. val_bits => 10
  118. )
  119. port map(
  120. clk => clk,
  121. val_cur => duty_cycle,
  122. pulse => pulse_pass
  123. );
  124.  
  125. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement