发布网友 发布时间:2022-04-20 10:30
共1个回答
热心网友 时间:2023-05-21 00:57
下面是一个4相4拍的步进电机顺序脉冲发生器的VHDL描述,你可以改成4相8拍的,每一步的转角可以小一半。改变输入信号clk的频率就可以改变转速:
LIBRARY IEEE;
USE IEEE.Std_logic_11.ALL;
ENTITY sequencer_4 IS
PORT(clk,en,dir:IN Std_logic;
a,b,c,d:OUT Std_logic);
END sequencer_4;
ARCHITECTURE behavl_seq OF sequencer_4 IS
SIGNAL x:Std_logic_vector(3 DOWNTO 0);
BEGIN
PROCESS(clk,en)
BEGIN
IF en= '1' THEN
x<= (OTHERS => '0');
ELSIFclk'Event AND clk = '1' AND Clock'Last_Value = '0' THEN
CASE x IS
WHEN"0001" => IF dir = '0' THEN x <= "0010";ELSE x <= "1000";END IF;
WHEN"0010" => IF dir = '0' THEN x <= "0100";ELSE x <= "0001";END IF;
WHEN"0100" => IF dir = '0' THEN x <= "1000";ELSE x <= "0010";END IF;
WHEN"1000" => IF dir = '0' THEN x <= "0001";ELSE x <= "0100";END IF;
WHENOTHERS=> x <= "0001";
END CASE;
END IF;
END PROCESS;
a <= x(0);
b <= x(1);
c <= x(2);
d <= x(3);
END behavl_seq;
上面有些符号是全角的,你需要改成半角字符才能通过编译。
a、b、c、d对应28BYJ48的1、2、3、4号线。