步进电机控制器VHDL源代码

LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.std_logic_unsigned.ALL;
USE IEEE.std_logic_arith.ALL;

ENTITY step_motor IS
    PORT(
        f, p, d: IN    STD_LOGIC:='0';
        speed : in  STD_LOGIC_VECTOR(1 downto 0);    
        coil : OUT    STD_LOGIC_VECTOR(3 downto 0)
         );
        
END step_motor;
ARCHITECTURE behavior OF step_motor IS
    SIGNAL ind_coil: STD_LOGIC_VECTOR(3 downto 0) := "0001";
    SIGNAL clk_scan: STD_LOGIC;
    SIGNAL PHASE,DIRECTION:STD_LOGIC;
    signal t:std_logic_vector(3 downto 0);
    signal comp:integer range 0 to 2500 ;
    SIGNAL osc:STD_LOGIC;
     BEGIN
coil <= t;

process(f,osc)
variable delay:integer range 0 to 50;
begin
if (f'event and f='1') then
 if delay>=50 then delay:=0;osc<=not osc;
 else delay:=delay+1;
end if;
end if;

if (osc'event and osc='1') then 
case speed is

   when "10" => if comp<2500 then comp<=comp+1; 
                else comp<=comp; 
                end if;
   when "01" => if comp>2 then comp<=comp-1;
                else comp<=comp;
                end if;
   when others => if comp<2 then comp<=2;
                else comp<=comp;
                end if;
end case;
end if;
end process;


PROCESS
    VARIABLE d_ff: integer range 0 to 2500;
    
BEGIN

    WAIT UNTIL f = '1';
    if d_ff >= comp then
        d_ff :=0; clk_scan <= not CLK_SCAN;
    else
        d_ff := d_ff + 1;
    end if;
           END PROCESS ;
 
 PROCESS(F)
 VARIABLE B:STD_LOGIC;
 BEGIN
 IF (F'EVENT AND F='1') THEN B:=(P and (b and P) );
 IF B='1' THEN PHASE<=NOT PHASE ;B:='0';
 ELSIF P='0' THEN PHASE<=PHASE;B:='1';
 END IF;
 END IF;
 END PROCESS;

 PROCESS(F)
 VARIABLE B:STD_LOGIC;
 BEGIN
 IF (F'EVENT AND F='1') THEN B:=(D and (b and D) );
 IF B='1' THEN DIRECTION<=NOT DIRECTION ;B:='0';
 ELSIF D='0' THEN DIRECTION<=DIRECTION;B:='1';
 END IF;
 END IF;
 END PROCESS;

motor:
process
begin
--if (clk_scan'event and clk_scan='1') then
WAIT UNTIL clk_scan= '0';
    CASE phase IS
        WHEN '1' =>
            IF direction = '0' THEN
                IF ((ind_coil = "1001") or (ind_coil = "0000")) THEN
                     ind_coil <= "0001";
                ELSE
                     ind_coil <= (ind_coil(2 downto 0) & ind_coil(3));
                END IF;
            ELSE
                IF ((ind_coil = "1001") or (ind_coil = "0000")) THEN
                    ind_coil <= "1000";
                ELSE
                     ind_coil <= (ind_coil(0) & ind_coil(3 downto 1));
                END IF;
            END IF;
                    

           WHEN OTHERS => 
                         ind_coil<=IND_COIL;
           END CASE;
t<=not ind_coil;
END PROCESS motor;

END behavior;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GJZGRB

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值