我在线等:求一个FPGA控制步进电机28BYJ48的程序。

发布网友 发布时间: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号线。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com