Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 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. ccase: process(led_cnt)
  40. case led_cnt is
  41. when 0 => led_0 <= pulse_pass;
  42. when 1 => led_1 <= pulse_pass;
  43. when 2 => led_2 <= pulse_pass;
  44. when 3 => led_3 <= pulse_pass;
  45. end case;
  46. end process;
  47.  
  48. --led_0 <= pulse_pass;
  49.  
  50. clockDivider: process(clk) -- Clock Divide
  51. begin
  52. if(clk'event and clk = '1') then
  53. if (clk_div < 7_999) then
  54. clk_div <= clk_div + 1;
  55. flag <= '0';
  56. else
  57. clk_div <= (others => '0');
  58. flag <= '1';
  59. if (led_cnt = 3) then
  60. led_cnt <= 0;
  61. end if;
  62. led_cnt <= led_cnt + 1;
  63. end if;
  64. end if;
  65. end process;
  66.  
  67. dutyCycle: process(clk) -- Duty Cycle
  68. begin
  69. if(clk'event and clk = '1') then
  70. if (flag = '1') then -- 1ms Pulse
  71. if (pol = '0') then -- Polarity
  72. if (duty_cycle < 999) then
  73. duty_cycle <= duty_cycle + 1;
  74. pol <= '0';
  75. else
  76. pol <= '1';
  77. end if;
  78. else
  79. if (duty_cycle > 1) then
  80. duty_cycle <= duty_cycle - 1;
  81. pol <= '1';
  82. else
  83. pol <= '0';
  84. end if;
  85. end if;
  86. end if;
  87. end if;
  88. end process;
  89.  
  90. --case i is
  91. -- when 0 => led_0 <= pulse_pass;
  92. -- when 1 => led_1 <= pulse_pass;
  93. -- when 2 => led_2 <= pulse_pass;
  94. -- when 3 => led_3 <= pulse_pass;
  95. --end case;
  96.  
  97. --button: process(btn_0)
  98. --begin
  99. -- if btn_0 = '1' then
  100. --
  101. -- i <= i + 1;
  102. -- case i is
  103. -- when 0 => led_1 <= pulse_pass;
  104. -- when 1 => led_2 <= pulse_pass;
  105. -- end case;
  106. -- end if;
  107. ---- for i in 0 to 1
  108. ---- loop
  109. ----
  110. ---- end loop;
  111. --end process;
  112.  
  113. pwm0: pwm
  114. generic map(
  115. max_val => 1000,
  116. val_bits => 10
  117. )
  118. port map(
  119. clk => clk,
  120. val_cur => duty_cycle,
  121. pulse => pulse_pass
  122. );
  123.  
  124. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement