直流电机VHDL源代码

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity dccount is
port (
clk : in std_logic;
ai : in std_logic_vector(3 downto 0);
co : out std_logic_vector(3 downto 0);
pulse: in std_logic;
drivera,driverb: out std_logic;
s : out std_logic_vector(6 downto 0);
p : out std_logic_vector(5 downto 0);
sp : out std_logic);
end dccount;
architecture a of dccount is
signal f: std_logic_vector(5 downto 0);
signal f_hz: std_logic;
signal osc: std_logic;
signal osc1: std_logic;
signal c: std_logic_vector(3 downto 0);
signal a: std_logic_vector(3 downto 0);
signal code: std_logic_vector(2 downto 0);
signal bcd:std_logic_vector(23 downto 0);
signal count:std_logic_vector(23 downto 0);
signal sum: std_logic_vector(4 downto 0);
signal d: std_logic_vector(3 downto 0):=“0000”;
signal ind_coil: std_logic_vector(3 downto 0) := “0001”;
signal hz:std_logic;
signal spo: std_logic;
signal sw:std_logic;
signal key:std_logic;
signal dra,drb:std_logic;
begin
drivera《=dra;
driverb《=drb;
p(5 downto 0) 《= f(5 downto 0);
co(3 downto 0) 《=c(3 downto 0);
a (3 downto 0)《=ai(3 downto 0);
sp《=spo;
-----------------div------------------------
process(osc)
variable d_ff: std_logic_vector(20 downto 0);
variable delay: std_logic_vector(23 downto 0);
begin
wait until clk = ‘’1‘’;
if d_ff(20 downto 0) 》= 2e6 then
d_ff(20 downto 0) := “000000000000000000000”;
else
d_ff(20 downto 0) := d_ff + 1;
end if;
f_hz 《= not d_ff(6);
osc 《= not d_ff(10);
osc1 《= not d_ff(17);
if delay》=500000 then
delay:=“000000000000000000000000”;hz《=not hz;
else delay:=delay+1;
end if;
end process ;
----------------------------------------------
process (f_hz,osc,osc1,hz,pulse)
variable b: std_logic;
variable int: std_logic;
variable data: std_logic_vector(3 downto 0);
variable up: std_logic_vector(2 downto 0);
variable st:std_logic_vector(2 downto 0);
variable seq: std_logic_vector(1 downto 0);
variable sound: std_logic_vector(1 downto 0);
variable stop: std_logic;
variable direction: std_logic;
begin
---------------7seg scan-------------------------------
if (f_hz=‘’1‘’ and f_hz‘’event) then
if st(2 downto 0)= “101” then
st(2 downto 0):=“000” ;
else st(2 downto 0):=st(2 downto 0)+1;
end if;
end if;
-----------------------------------------------
if (osc = ‘’1‘’ and osc‘’event) then
if a=“1111” then
if seq=“11” then seq:=“00” ;
else seq:=seq+1;
end if;
else seq:=seq;
end if;
if seq=“00” then c(3 downto 0)《=“1110” ;
elsif seq=“01” then c(3 downto 0)《=“1101” ;
elsif seq=“10” then c(3 downto 0)《=“1011” ;
elsif seq=“11” then c(3 downto 0)《=“0111” ;
end if;
end if;
if a=“1111” then int:=‘’0‘’;
else int:=‘’1‘’;
end if;
if (hz‘’event and hz=‘’1‘’) then
if stop=‘’1‘’ then up:=up+1;
else up:=“000”;
end if;
end if;
if key=‘’1‘’ and count/=0 then
if direction=‘’0‘’ then dra《=‘’1‘’;drb《=‘’0‘’;stop:=‘’0‘’;
else dra《=‘’0‘’;drb《=‘’1‘’;stop:=‘’0‘’;
end if;
elsif key=‘’1‘’ and count=0 then stop:=‘’1‘’;
elsif stop=‘’1‘’ and up《“110” then dra《=not dra ;drb《=not drb;
else dra《=‘’0‘’;drb《=‘’0‘’;stop:=‘’0‘’;
end if;
if (osc1‘’event and osc1=‘’1‘’) then b:=(int and (b and int) );
----------------direction choice-----------------------
if sw=‘’0‘’ and b=‘’1‘’ and data(3 downto 0)=“1010” then
bcd(23 downto 0)《=bcd(23 downto 0);b:=‘’0‘’;direction:=‘’1‘’;
elsif sw=‘’0‘’ and b=‘’1‘’ and data(3 downto 0)=“1011” then
bcd(23 downto 0)《=bcd(23 downto 0);b:=‘’0‘’;direction:=‘’0‘’;
------------------key lock on/off------------------------------------
elsif b=‘’1‘’ and data(3 downto 0)=“1100” then
bcd《=bcd;b:=‘’0‘’;sw《=not sw;
-------------------back-------------------------------
elsif sw=‘’0‘’ and b=‘’1‘’ and data(3 downto 0)=“1101” then
bcd(23 downto 0)《=(“0000” & bcd(23 downto 4) );b:=‘’0‘’;
-------------------clear---------------------------------
elsif b=‘’1‘’ and data(3 downto 0)=“1110” then
bcd《=“000000000000000000000000” ;b:=‘’0‘’;sw《=‘’0‘’;
------------------downcount 0 ------------------------------------
elsif bcd=0 and key=‘’1‘’ then sw《=‘’0‘’;key《=‘’0‘’;bcd《=bcd;
------------------------------------------------------------------
elsif sw=‘’1‘’ and key=‘’1‘’ and data(3 downto 0)/=“1110” then bcd《=count;
elsif sw=‘’1‘’ and data(3 downto 0)=“1110” then sw《=‘’0‘’;
bcd《=“000000000000000000000000”;key《=‘’0‘’;
-------------------enter------------------------------
elsif sw=‘’0‘’ and b=‘’1‘’ and data(3 downto 0)=“1111” and bcd/=0 then
b:=‘’0‘’;sw《=‘’1‘’;key《=‘’1‘’;
elsif sw=‘’0‘’ and b=‘’1‘’ and data(3 downto 0)=“1111” and bcd=0 then
bcd《=bcd;b:=‘’0‘’;sw《=‘’0‘’;key《=‘’0‘’;
----------------------number shift---------------------------
elsif sw=‘’0‘’ and b=‘’1‘’ then bcd(23 downto 0)《= bcd(19 downto 0) & data(3 downto 0);b:=‘’0‘’;
elsif int=‘’0‘’ then bcd《=bcd;
b:=‘’1‘’;
end if;
end if;
------------------------------------------------------
sum(1 downto 0)《= seq;
sum(4 downto 2)《=code;
---------------------sound-----------------------------
if (osc‘’event and osc=‘’1‘’) then
if int=‘’1‘’ and sw=‘’0‘’ then sound:=sound+1;spo《=sound(1) ;
else spo《=‘’0‘’;
end if;
end if;
-------------------------------------------------------
---------------------------downcount--------------------
if sw=‘’0‘’ then count《=bcd;
else
if (pulse = ‘’1‘’ and pulse‘’event) then
if key=‘’1‘’ and count/=0 then
----------------------------1---------------------------------------------------
if count(3 downto 0)= 0 and count(23 downto 4)》=1 then
count(3 downto 0) 《=“1001” ;
else count(3 downto 0) 《= count(3 downto 0)-1;
end if;
----------------------------2---------------------------------------------------------
if count(7 downto 4)= 0 and count(23 downto 8)》=1 and count(3 downto 0)=0 then
count(7 downto 4) 《= “1001” ;
elsif count(3 downto 0)=0 and count(23 downto 4)》=1 then
count(7 downto 4) 《=count(7 downto 4 )-1;
end if;
----------------------------3-------------------------------------------------------
if count(11 downto 8)= 0 and count(23 downto 12)》=1 and count(7 downto 0)=0 then
count(11 downto 8) 《=“1001”;
elsif count(7 downto 0)=0 and count(23 downto 8)》=1 then
count(11 downto 8) 《=count(11 downto 8 )-1;
end if;
---------------------------4--------------------------------------------------------------
if count(15 downto 12)= 0 and count(23 downto 16)》=1 and count(11 downto 0)=0 then
count(15 downto 12) 《=“1001”;
elsif count(11 downto 8)=0 and count(23 downto 12)》=1 and count(7 downto 0)=0 then
count(15 downto 12) 《=count(15 downto 12 )-1;
end if;
-------------------------5------------------------------------------------------------
if count(19 downto 16)= 0 and count(23 downto 20)》=1 and count(15 downto 0)=0 then
count(19 downto 16) 《=“1001”;
elsif count(15 downto 12)=0 and count(23 downto 16)》=1 and count(11 downto 0)=0 then
count(19 downto 16) 《=count(19 downto 16 )-1;
end if;
-------------------------6-------------------------------------------------
if count(23 downto 20)= 0 then
count(23 downto 20) 《=“0000”;
elsif count(19 downto 16)=0 and count(23 downto 20 )》=1 and count(15 downto 0)=0 then
count(23 downto 20) 《=count(23 downto 20 )-1;
end if;
end if;
end if;
end if;
------------------7seg scan---------------------------
case st is --?@潮
when “000”=》 d(3 downto 0) 《= bcd(3 downto 0) ; f(5 downto 0)《=“111110”;
when “001”=》 d(3 downto 0) 《= bcd(7 downto 4) ; f(5 downto 0)《=“111101”;
when “010”=》 d(3 downto 0) 《= bcd(11 downto 8) ; f(5 downto 0)《=“111011”;
when “011”=》 d(3 downto 0) 《= bcd(15 downto 12) ; f(5 downto 0)《=“110111”;
when “100”=》 d(3 downto 0) 《= bcd(19 downto 16) ; f(5 downto 0)《=“101111”;
when “101”=》 d(3 downto 0) 《= bcd(23 downto 20) ; f(5 downto 0)《=“011111”;
when others =》 d(3 downto 0) 《= “1100” ; f(5 downto 0)《=“111111”;
end case;
------------------key scan-------------------------
case a(3 downto 0) is
when“1110” =》 code《=“100”;
when“1101” =》 code《=“101”;
when“1011” =》 code《=“110”;
when“0111” =》 code《=“111”;
when others =》 code《=“000”;
end case;
---------------------key table------------------------
case sum(4 downto 0) is
when“10000”=》 data:=“0001”;--0
when“10001”=》 data:=“0101”;--1
when“10010”=》 data:=“1001”;--2
when“10011”=》 data:=“1100”;--3

用户体验决定移动IM成败
分享拥有指数调光和Flash的MPS公司的MP3313产品的性能介绍和应用
理想汽车计划到2035年将成为全球最大的自动驾驶运营商
区块链技术应用,七大领域不可不知
2011年GaN LED市场仅增长1%,多数企业多数利润甚低
直流电机VHDL源代码
区块链的作用是什么
凌华科技发布SATA 6 Gb/s固态硬盘
集成电路驱蚊器电路图
2019年十大热门技术盘点:5G排名第一,区块链、机器人技术上榜
有什么办法能解决标准FPGA资源丰富却浪费的问题吗?嵌入式FPGA可以
单片机知识介绍
小米高管称 小米销量下滑对公司影响不大 这是为什么?
蒸汽回收机是如何节能并实现绿色低碳发展的
消费电子产品智能化达到新的高度
高昂人工成本提高了对工业机器人的需求,市场近期或实现显著增长
如何利用PIC16F877A单片机读写AT24C系列储存器
传感器的主要分类和选型原则
一种用槽和同轴线馈电的三极化共形天线详细教程
如何聚集磁感线?