?? pwm_control.vhd
字號:
library ieee ;
use ieee.STD_LOGIC_1164.ALL ;
use ieee.STD_LOGIC_unsigned.ALL ;
ENTITY PWM_CONTROL IS
PORT(
rst,Level,clk,Z_F : IN STD_LOGIC ;
z,f,level_display0,level_display1 : OUT STD_LOGIC
);
end PWM_CONTROL ;
architecture lqy of PWM_CONTROL is
signal cnt4 : std_logic_vector(1 downto 0) ;
signal cnt16 :std_logic_vector(3 downto 0) ;
signal agb :std_logic ;
signal speed :std_logic_vector(3 downto 0) ;
begin
--速度等級設(shè)置模塊
process(rst,level)
begin
if rst='1' then
cnt4<=(others=>'0');
elsif level='1' and level'event then
cnt4<=cnt4+1;
end if;
end process;
process(rst,clk)
begin
if rst='1' then
speed<=(others=>'0');
elsif clk'event and clk='1' then
case cnt4 is
WHEN "00" => speed <= "0011" ;
WHEN "01" => speed <= "0100" ;
WHEN "10" => speed <= "0101" ;
WHEN "11" => speed <= "0111" ;
WHEN OTHERS => NULL ;
END CASE ;
end if;
END PROCESS;
--數(shù)字比較器模塊
process(clk,rst)
begin
if rst='1' then
agb<='0';
elsif clk'event and clk='1' then
if cnt16>speed then
agb<='1';
else
agb<='0';
end if;
end if;
end process;
--鋸齒波發(fā)生器
process(rst,clk)
begin
if rst='1' then
cnt16<=(others=>'0');
elsif clk='1' and clk'event then
cnt16<=cnt16+1 ;
end if;
end process;
--旋轉(zhuǎn)方向控制模塊
process(rst,clk)
begin
if rst='1' then
z<='0';
f<='0';
elsif clk'event and clk='1' then
if z_f='1' then
z<=agb;
f<='0';
else
z<='0';
f<=agb;
end if;
end if;
end process;
level_display0 <= cnt4(0);
level_display1 <= cnt4(1);
end ;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -