久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2960|回復: 0
打印 上一主題 下一主題
收起左側

FPGA步進電機控制程序

[復制鏈接]
跳轉到指定樓層
樓主
ID:564791 發表于 2020-1-1 13:39 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
  1. //******模塊一:分頻器*****************//
  2. /*en1為使能端,clk為輸入頻率,outdiv(0-9)為輸出頻率,
  3. outdiv(0)為不進行分頻,outdiv(1)進行2分頻,
  4. outdiv(2)進行3分頻,outdiv(3)進行4分頻,
  5. outdiv(4)進行5分頻,outdiv(5)進行6分頻,
  6. outdiv(6)進行7分頻,outdiv(7)進行8分頻,
  7. outdiv(8)進行9分頻,outdiv(9)進行10分頻。*/
  8. library ieee;
  9. use ieee.std_logic_1164.all;
  10. entity FPQ is
  11.               port(clk,en1: in std_logic;                           
  12.                               outdiv : out std_logic_vector(9 downto 0));
  13. end FPQ;
  14. architecture bh of FPQ is
  15. begin
  16.               process(en1,clk)
  17.               variable t1 : integer range 0 to 2;
  18.               variable t2 : integer range 0 to 3;
  19.               variable t3 : integer range 0 to 4;
  20.               variable t4 : integer range 0 to 5;
  21.               variable t5 : integer range 0 to 6;
  22.               variable t6 : integer range 0 to 7;
  23.               variable t7 : integer range 0 to 8;
  24.               variable t8 : integer range 0 to 9;
  25.               variable t9 : integer range 0 to 10;
  26.               begin
  27.               outdiv(0) <= clk;
  28.               if clk'event and clk = '1' then
  29.                             if en1 = '1' then
  30.                                           if (t1 >= 2) then t1:=0;outdiv(1)<='0';
  31.                                           elsif t1<1 then outdiv(1)<='0';
  32.                                           else outdiv(1) <= '1';
  33.                                           end if;
  34.                                           t1:=t1+1;
  35.                                           if (t2 >= 3) then t2:=0;outdiv(2)<='0';
  36.                                           elsif t2<2 then outdiv(2)<='0';
  37.                                           else outdiv(2) <= '1';
  38.                                           end if;
  39.                                           t2:=t2+1;                                         
  40.                                           if (t3 >= 4) then t3:=0;outdiv(3)<='0';
  41.                                           elsif t3<2 then outdiv(3)<='0';
  42.                                           else outdiv(3) <= '1';
  43.                                           end if;
  44.                                           t3:=t3+1;                                         
  45.                                           if (t4 >= 5) then t4:=0;outdiv(4)<='0';
  46.                                           elsif t4<3 then outdiv(4)<='0';
  47.                                           else outdiv(4) <= '1';
  48.                                           end if;
  49.                                           t4:=t4+1;                           
  50.                                           if (t5 >= 6) then t5:=0;outdiv(5)<='0';
  51.                                           elsif t5<3 then outdiv(5)<='0';
  52.                                           else outdiv(5) <= '1';
  53.                                           end if;
  54.                                           t5:=t5+1;
  55.                                           if (t6 >= 7) then t6:=0;outdiv(6)<='0';
  56.                                           elsif t6<4 then outdiv(6)<='0';
  57.                                           else outdiv(6) <= '1';
  58.                                           end if;
  59.                                           t6:=t6+1;
  60.                                           if (t7 >= 8) then t7:=0;outdiv(7)<='0';
  61.                                           elsif t7<4 then outdiv(7)<='0';
  62.                                           else outdiv(7) <= '1';
  63.                                           end if;
  64.                                           t7:=t7+1;
  65.                                           if (t8 >= 9) then t8:=0;outdiv(8)<='0';
  66.                                           elsif t8<5 then outdiv(8)<='0';
  67.                                           else outdiv(8) <= '1';
  68.                                           end if;
  69.                                           t8:=t8+1;
  70.                                           if (t9 >= 10) then t9:=0;outdiv(9)<='0';
  71.                                           elsif t9<5 then outdiv(9)<='0';
  72.                                           else outdiv(9) <= '1';
  73.                                           end if;
  74.                                           t9:=t9+1;
  75.                             end if;
  76.               end if;
  77.               end process;
  78. end bh;










  79. //***********模塊二:頻率選擇器**************//
  80. /*P0、P1、P2、P3為頻率選擇信號,indiv(0-9)為分頻器分頻之后的頻率信號,
  81. outclk為要選擇的頻率。
  82. 當p(3-0)為"0000"時,outclk為indiv(0);當p(3-0)為"0001"時,outclk為indiv(1);
  83. 當p(3-0)為"0010"時,outclk為indiv(2);當p(3-0)為"0011"時,outclk為indiv(3);
  84. 當p(3-0)為"0100"時,outclk為indiv(4);當p(3-0)為"0101"時,outclk為indiv(5);
  85. 當p(3-0)為"0110"時,outclk為indiv(6);當p(3-0)為"0111"時,outclk為indiv(7);
  86. 當p(3-0)為"1000"時,outclk為indiv(8);當p(3-0)為"1001"時,outclk為indiv(9);
  87. 當p(3-0)為其它時,outclk為indiv(0)。*/
  88. library ieee;
  89. use ieee.std_logic_1164.all;
  90. entity PLXZQ is
  91.               port(p: in std_logic_vector(3 downto 0);
  92.                             indiv : in std_logic_vector(9 downto 0);
  93.                             outclk : out std_logic);
  94. end PLXZQ;
  95. architecture bh1 of PLXZQ is
  96. begin
  97.               process(p,indiv)
  98.               begin
  99.                             case p is
  100.                                           when "0000" => outclk <= indiv(0);
  101.                                           when "0001" => outclk <= indiv(1);
  102.                                           when "0010" => outclk <= indiv(2);
  103.                                           when "0011" => outclk <= indiv(3);
  104.                                           when "0100" => outclk <= indiv(4);
  105.                                           when "0101" => outclk <= indiv(5);
  106.                                           when "0110" => outclk <= indiv(6);
  107.                                           when "0111" => outclk <= indiv(7);
  108.                                           when "1000" => outclk <= indiv(8);
  109.                                           when "1001" => outclk <= indiv(9);
  110.                                           when others => outclk <= indiv(0);
  111.                             end case;
  112.               end process;
  113. end bh1;











  114. //***********模塊三:方向鎖存器**************//
  115. /*Zz、Fz、Tz為方向和開關信號,Modxz為六拍和三拍選擇切換信號,
  116. outctrl為輸出的控制信號。
  117. 當Modxz為1時,為六拍;當Modxz為0時,為雙三拍。
  118. 當Tz為1時,為停止電機,當Tz為0時,為啟動電機。
  119. 當Zz為1、Fz為0時,為電機正轉,
  120. 當Zz為0、Fz為1時,為電機反轉,
  121. 當Zz為1、Fz為1時,為電機停止,
  122. 當Zz為0、Fz為0時,為電機停止。
  123. outctrl(0)對應Tz;outctrl(1)對應Fz;
  124. outctrl(2)對應Zz;outctrl(3)對應Modxz。*/
  125. library ieee;
  126. use ieee.std_logic_1164.all;
  127. entity FXSCQ is
  128.               port(modxz,zz,fz,tz: in std_logic;
  129.                             outctrl: out std_logic_vector(3 downto 0));
  130. end FXSCQ;
  131. architecture bh2 of FXSCQ is
  132. begin
  133.               process(modxz,zz,fz,tz)
  134.               begin
  135.                             outctrl(0) <= tz;
  136.                             outctrl(1) <= fz;
  137.                             outctrl(2) <= zz;
  138.                             outctrl(3) <= modxz;
  139.                             if zz = '1' and fz = '1' then
  140.                                           outctrl(0) <= '1';
  141.                             elsif zz = '0' and fz = '0' then
  142.                                           outctrl(0) <= '1';
  143.                             end if;
  144.               end process;
  145. end bh2;






  146. //***********模塊四:中央控制器**************//
  147. /*inclk為經過頻率選擇器選擇之后的輸入頻率,
  148. inctrl為經過方向鎖存器之后的輸入控制信號,
  149. outDj為三相電機的的三相電壓,
  150. 當inctrl為“0100”時,電機為雙三相正轉;
  151. 當inctrl為“0010”時,電機為雙三相反轉;
  152. 當inctrl為“1100”時,電機為單六相正轉;
  153. 當inctrl為“1010”時,電機為單六相正轉;
  154. 當inctrl為“xxx1”時,電機停止。*/
  155. library ieee;
  156. use ieee.std_logic_1164.all;
  157. use ieee.std_logic_unsigned.all;
  158. entity CPU is
  159.               port(inclk: in std_logic;
  160.                             inctrl: in std_logic_vector(3 downto 0);
  161.                             outDJ: out std_logic_vector(2 downto 0));
  162. end CPU;
  163. architecture bh3 of CPU is
  164.               signal Tmp : std_logic_vector(2 downto 0);
  165. begin
  166.               process(inclk,inctrl)
  167.               begin
  168.                             if inclk'event and inclk = '1' then
  169.                             if inctrl = "1100" then
  170.                                           if Tmp = 6 then
  171.                                                         Tmp <= "001";
  172.                                           else
  173.                                           Tmp <= Tmp+1;
  174.                                           end if;
  175.                             elsif inctrl = "1010" then
  176.                                           if Tmp = 1 then
  177.                                                         Tmp <= "110";
  178.                                           else
  179.                                                         Tmp <= Tmp-1;
  180.                                           end if;
  181.                             elsif inctrl = "1000" then            
  182.                                           Tmp <= "000";
  183.                             elsif inctrl = "0100" then
  184.                                           if Tmp = 6 then
  185.                                                         Tmp <= "010";
  186.                                           else
  187.                                                         Tmp <= Tmp+2;
  188.                                           end if;
  189.                             elsif inctrl = "0010" then
  190.                                           if Tmp = 2 then
  191.                                                         Tmp <="110";
  192.                                           else
  193.                                                         Tmp <= Tmp-2;
  194.                                           end if;
  195.                             elsif inctrl = "0000" then
  196.                                           Tmp <= "000";
  197.                             end if;
  198.                             end if;
  199.               end process;
  200.               with Tmp select
  201.               outDJ <= "001" when "001",
  202.                                             "011" when "010",
  203.                                             "010" when "011",
  204.                                             "110" when "100",
  205.                                             "100" when "101",
  206.                                             "101" when "110",
  207.                                             "000" when others;
  208. end bh3;



  209. //***********模塊五:譯碼器**************//
  210. /*xyk(3-0)為輸入信號,輸入數值,dnf(8-0)為輸出控制數碼管信號。
  211. //dnf(8)為數碼管的位選信號。
  212. 當xyk為“0000”時,dnf輸出為“100111111”, 數碼管顯示‘0’;
  213. 當xyk為“0001”時,dnf輸出為“100000110”, 數碼管顯示‘1’;
  214. 當xyk為“0010”時,dnf輸出為“101011011”, 數碼管顯示‘2’;
  215. 當xyk為“0011”時,dnf輸出為“101001111”, 數碼管顯示‘3’;
  216. 當xyk為“0100”時,dnf輸出為“101100110”, 數碼管顯示‘4’;
  217. 當xyk為“0101”時,dnf輸出為“100101001”, 數碼管顯示‘5’;
  218. 當xyk為“0110”時,dnf輸出為“101111101”, 數碼管顯示‘6’;
  219. 當xyk為“0111”時,dnf輸出為“100000111”, 數碼管顯示‘7’;
  220. 當xyk為“1000”時,dnf輸出為“101111111”, 數碼管顯示‘8’;
  221. 當xyk為“1001”時,dnf輸出為“101100111”, 數碼管顯示‘9’;
  222. 當xyk為其它時,dnf輸出為“100111111”, 數碼管顯示‘0’。*/
  223. library ieee;
  224. use ieee.std_logic_1164.all;
  225. entity YMQ is
  226.               port(xyk: in std_logic_vector(3 downto 0);
  227.                             dnf: out std_logic_vector(8 downto 0));
  228. end YMQ;
  229. architecture bh4 of YMQ is
  230. begin
  231.               process(xyk)
  232.               begin
  233.                             case xyk is
  234.                             when "0000" => dnf <= "100111111";
  235.                             when "0001" => dnf <= "100000110";
  236.                             when "0010" => dnf <= "101011011";
  237.                             when "0011" => dnf <= "101001111";
  238.                             when "0100" => dnf <= "101100110";
  239.                             when "0101" => dnf <= "100101001";
  240.                             when "0110" => dnf <= "101111101";
  241.                             when "0111" => dnf <= "100000111";
  242.                             when "1000" => dnf <= "101111111";
  243.                             when "1001" => dnf <= "101100111";
  244.                             when others => dnf <= "100111111";
  245.                             end case;
  246.               end process;
  247. end bh4;




  248. //********總體:模塊的例化*************//
  249. library ieee;
  250. use ieee.std_logic_1164.all;
  251. entity zong is
  252.               port(clk0,en0,Modxz0,Zz0,Fz0,Tz0 : in std_logic;
  253.                             P0 : in std_logic_vector(3 downto 0);
  254.                             DNF0 : out std_logic_vector(8 downto 0);
  255.                             OutDJ0 : out std_logic_vector(2 downto 0));
  256. end zong;
  257. architecture bh0 of zong is
  258. component FPQ
  259. port(clk,en1: in std_logic;                           
  260.               outdiv : out std_logic_vector(9 downto 0));
  261. end component;
  262. component PLXZQ
  263. port(p: in std_logic_vector(3 downto 0);
  264.               indiv : in std_logic_vector(9 downto 0);
  265.               outclk : out std_logic);
  266. end component;
  267. component YMQ
  268. port(xyk: in std_logic_vector(3 downto 0);
  269.               dnf: out std_logic_vector(8 downto 0));
  270. end component;
  271. component CPU
  272. port(inclk: in std_logic;
  273.               inctrl: in std_logic_vector(3 downto 0);
  274.               outDJ: out std_logic_vector(2 downto 0));
  275. end component;
  276. component FXSCQ
  277. port(modxz,zz,fz,tz: in std_logic;
  278.               outctrl: out std_logic_vector(3 downto 0));
  279. end component;
  280. signal DX1 :std_logic;
  281. signal DX2 :std_logic_vector(9 downto 0);
  282. signal DX3 :std_logic_vector(3 downto 0);
  283. begin
  284. U0 : FPQ port map (clk0,en0,DX2);
  285. U1 : PLXZQ port map (p0,DX2,DX1);
  286. U2 : YMQ port map (p0,dnf0);
  287. U3 : CPU port map (DX1,DX3,OutDJ0);
  288. U4 : FXSCQ port map (Modxz0,Zz0,Fz0,Tz0,DX3);
  289. end bh0;
復制代碼

文檔.doc

684.99 KB, 下載次數: 27, 下載積分: 黑幣 -5

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 精品国产精品国产偷麻豆 | av三级 | 91香蕉嫩草| 国产一区视频在线 | 黄色一级免费 | 亚洲高清视频在线 | 日韩高清国产一区在线 | 日本成人在线播放 | 日韩 欧美 综合 | 精品一二三区视频 | 精品一区二区三区视频在线观看 | 午夜影院在线 | 黄色在线免费观看视频网站 | 国产精品久久久久久久免费大片 | 99久久影院| 亚洲成人国产综合 | 美女久久久久久久 | 亚洲精品一区二区三区中文字幕 | 精品国产乱码久久久久久牛牛 | 一区二区三区在线 | 91久久网站 | 国产精品日韩在线 | 国产成人综合一区二区三区 | 九九热在线免费视频 | 日韩在线看片 | 亚洲一区二区三区免费视频 | 91精品国产综合久久精品 | 国产成人精品久久二区二区91 | 欧美中文字幕一区二区三区亚洲 | 欧美亚洲免费 | 毛片免费观看 | 日日日操 | av黄色在线 | 日本精品免费在线观看 | 国产精品久久九九 | 色综合99| 国产 日韩 欧美 在线 | 国产精品久久久久久久久久东京 | 欧美a在线 | 中文字幕在线看人 | 日韩一区二区在线视频 |