Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 0.79 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. USE ieee.std_logic_unsigned.all;
  4. USE ieee.numeric_std.ALL;
  5. --50MHz clk, 2.5kHz f_pwm, 44% duty cycle und offset um 25%
  6. --50MHz/(2.5/1000)MHz=20000 mal zaehlen = x"4E20"
  7. --25%=20000*0.25=5000 = x"1388"
  8. --44% high: 20000*0.44=8800 = x"2260"
  9. --56% low:  20000*0.56=11200 = x"2BC0"
  10. architecture behavior of pwm is
  11.     signal pout: std_logic:='0';
  12. begin
  13.    
  14.     p1: process(CLK)
  15.         variable cnt: std_logic_vector(15 downto 0):=x"3A98";--beginnt bei 15000=x"3A98"
  16.         variable offset_flag: std_logic:='1';
  17.     begin
  18.         if(rising_edge(CLK)) then
  19.                 if(cnt=x"4E1F") then
  20.                     cnt:=x"0000";
  21.                     pout<='1';
  22.                 else
  23.                     cnt:=cnt+1;
  24.                 end if;
  25.                
  26.                 if(cnt=x"2260") then
  27.                     pout<='0';
  28.                 end if;
  29.         end if;
  30.     end process;
  31.    
  32.     O<=pout;
  33.    
  34. end behavior;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement