⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 motorcontrolvhdl.txt

📁 基于FPGA的步进电机控制电路的VHDL语言
💻 TXT
字号:
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;


ptocess(f,osc)
variable delay:integer range 0 to50;
begin
if(f'event and f='1')then
  if delay >=50 then 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;
end case;
end if;
end process;



PROCESS
    VSRIABLE d_ff:integer range 0to 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
VARIABLE B:STD_LOGIC;
BEGIN
IF(F'EVENT AND F='1')THEN B:=(P and(andp));
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="0001")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<=(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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -