Beruflich Dokumente
Kultur Dokumente
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Steprmotor is
Port ( clk,dir,rst : in STD_LOGIC;
dout : out STD_LOGIC_VECTOR (3 downto 0));
end Steprmotor;
process(clk)
begin
if(rising_edge(clk))then
clk_div<=clk_div+'1';
end if;
end process;
process(rst,clk_div(15))
begin
if(rst='1')then shift_reg<="0001";
elsif(rising_edge(clk_div(15)))then
if(dir='1')then
shift_reg<=shift_reg(0)&shift_reg(3 downto 1);
else
shift_reg<=shift_reg(2 downto 0)&shift_reg(3);
end if;
end if;
end process;
dout<=shift_reg;
end Behavioral;
DC MOTOR
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity dcmotor is
Port ( dir,clk,rst : in STD_LOGIC;
row : in STD_LOGIC_VECTOR (0 to 3);
pwm : out STD_LOGIC_VECTOR (1 downto 0);
rly : out STD_LOGIC);
end dcmotor;
ddclk<=div_reg(12);
tick<=row(0) and row(1) and row(2) and row(3);
process(tick)
begin
if Falling_edge(tick) then
case row is
when "1110" => duty_cycle<=255;
when "1101" => duty_cycle<=200;
when "1011" => duty_cycle<=150;
when "0111" => duty_cycle<=100;
when others => duty_cycle<=100;
end case;
end if;
end process;
process(ddclk, rst)
begin
if rst='0' then
countr<=(others=>'0');
pwm<="01";
elsif(ddclk'event and ddclk='1') then
countr<= countr+'1';
if countr>=duty_cycle then
pwm(1)<='1';
end if;
end if;
end process;