您的位置 首页 新能源

步进电机定位控制系统的VHDL程序设计

本文给出了步进电机定位控制系统的VHDL程序。

步进电机定位操控体系VHDL程序与仿真

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
entity step_motor is
port (reset:in STD_LOGIC; –体系复位信号
dir: in STD_LOGIC; –方向操控信号
clk: in STD_LOGIC; –体系时钟信号
ini: in STD_LOGIC; –初始化使能信号
manner: in STD_LOGIC_VECTOR (1 downto 0); –激磁方法的选择开关
angle: in INTEGER range 255 downto 0; —步进角的倍数设定输入
baBA: out STD_LOGIC_VECTOR (3 downto 0)); —步进电机状况输出
end step_motor;
architecture stepmotor_arch of step_motor is
signal count: INTEGER range 0 to 7; –计数器
signal cntInc: INTEGER range -2 to 2; –设定累加器所需的累(加/减)计数值
signal cc : integer range 0 to 3;
signal cntIni: INTEGER range -1 to 0; –设定累加器所需的计数初值
signal angleDnCount: INTEGER range 255 downto 0; –核算现已转过的步进角
signal angleDnCntDec: INTEGER range 2 downto 1;
begin
process(dir, manner, angle)–, ini)
begin
–if ini=’1′ then
cc=conv_integer(manner);
if dir=’0′ then
case cc is
when 1 => — 1-?相鼓励
–count=0;
cntIni=0;
cntInc=2;
angleDnCntDec=2;–10;
when 2 => — 2-?相鼓励
–count=7;
cntIni=-1;
cntInc=2;
angleDnCntDec=2;–10;
when 3 => — 1-2?相鼓励
–count=0;
cntIni=0;
cntInc=1;
angleDnCntDec=1;–01;
when 0 => –manner=00 autodetect
if (angle rem 2) =1 then — 2-?相鼓励
–count=7;
cntIni=-1;
cntInc=2;
angleDnCntDec=2;–10;
else — 1-?相鼓励
–count=0;
cntIni=0;
cntInc=2;
angleDnCntDec=2;–10;
end if; –angle
end case; –manner
else — if dir=’1′
case cc is
when 1 => — 1-?相鼓励
–count=0;
cntIni=0;
cntInc=-2;
angleDnCntDec=2;–10;
when 2 => — 2-?相鼓励
–count=7;
cntIni=-1;
cntInc=-2;
angleDnCntDec=2;–10;
when 3 => — 1-2?相鼓励
–count=0;
cntIni=0;
cntInc=-1;
angleDnCntDec=1;–01;
when 0 => –manner=00 autodetect
if (angle rem 2) = 1 then — 2-?相鼓励
cntIni=-1;
cntInc=-2;
angleDnCntDec=2;–10;
else — 1-?相鼓励
cntIni=0;
cntInc=-2;
angleDnCntDec=2;–10;
end if; –angle
end case; –manner
end if; — else dir=0
–end if; — ini
end process;
counting_reset: process(reset,ini, angle, clk)
begin
if reset=’1′ then
count=0;
angleDnCount=0;
elsif clk’event and clk=’1′ then
if ini=’0′ then
count=0+cntIni;
angleDnCount=angle;
else
count = count+cntInc;
if angleDnCount > angleDnCntDec then
angleDnCount = angleDnCount-angleDnCntDec;
else
angleDnCount = 0;
end if;
end if;
end if;
end process;
baBA =0000 when angleDnCount=0 else
0001 when count=0 else
0011 when count=1 else
0010 when count=2 else
0110 when count=3 else
0100 when count=4 else
1100 when count=5 else
1000 when count=6 else
1001;– when count>=7;
end stepmotor_arch;

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/xinnengyuan/195144.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部