1.?秒脉秒脉描述??????vhdlԴ??
2.基于vhdl电子秒表的系统设计怎么做?
3.EDA课ç¨è®¾è®¡ï¼ç¨VHDLç¼ç¨ååºç§è½¦è®¡è´¹å¨
???????vhdlԴ??
举个例子:对应的顶层文件:
U3的输入不就是U2和U1的输出啊。推理,冲的冲你的源码设计里面时钟(进制计数器)的输入是分钟(进制计数器)的输出,分钟计数器的秒脉秒脉描述输入是秒钟计数器的输出,秒钟计数器的冲的冲输入是分频器秒脉冲模块的输出。如果再实在是源码cryengine3.8 源码弄不明白,建议你的秒脉秒脉描述顶层文件使用图形化编程,直接画电路连线就好了阿!冲的冲希望能够采纳!源码
基于vhdl电子秒表的秒脉秒脉描述系统设计怎么做?
一、实验原理 :
用层次化设计的冲的冲方法以VHDL语言编程实现以下功能:
1 具有“时”、“分”、源码“秒”计时功能;时为进制,秒脉秒脉描述分和秒都为进制。冲的冲
2 具有消抖功能:手工按下键盘到是源码否这个过程大概ms左右,在按下开始到弹簧片稳,定接触这段时间为5-ms,从释放到弹片完全分开也是jdk 源码查看5-ms,在达到稳定接触和完全分开的微观过程中,电平是时高时低的,因此如果在首次检测到键盘按下时延时ms再检测就不会检测到抖动的毛刺电平了。Hz的信号周期为.6ms,正适合做消抖信号。
3 具有校时和清零功能,能够用4Hz脉冲对“小时”和“分”进行调整,并可进行秒零;
4 具有整点报时功能。在分秒、秒、秒、秒发出低音Hz信号,在分秒发出一次高音Hz信号,音响持续1秒钟,在Hz音响结束时刻为整点。
5 具有一键设定闹铃及正常计时与闹铃时间的显示转换。闹时时间为一分钟。
二、程序流程:
1、秒计数器模块设计:
模块图如图1。六十进制带进位计数器,seafile 源码 安装可清零,clk输入信号为1Hz脉冲,当q0计满9后q1增加1,当q0满9且q1记满5,q1、q0同时归零,co输出为高电平。q1为十位q0为个位。
图1
程序如下:
library IEEE;
use IEEE.STD_LOGIC_.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity c is
Port ( clk,clr : in std_logic;
co :out std_logic;
q1,q0 : out std_logic_vector(3 downto 0));
end c;
architecture one of c is
begin
process (clk,clr)
variable cq1,cq0:std_logic_vector(3 downto 0);
begin
if clr='1' then cq1:=(others=>'0');cq0:=(others=>'0');
elsif (clk'event and clk='1') then
if cq0<9 then cq0:=cq0 +1;co<='0';
elsif cq1<5 then cq1:=cq1+1;cq0:=(others=>'0');
elsif cq1=5 and cq0=9
then co<='1';cq1:=(others=>'0'); cq0:=(others=>'0');
else co<='0';
end if;
end if;
q1<=cq1;
q0<=cq0;
end process;
end one;
仿真结果如下图2
2、分计数器同上。注:不同之处为分的clk输入信号为秒的进位信号。
3、时计数器:
模块图如图3。进制无进位计数器,当计数信号计到后再检测到计数信号时会自动零。带清零,clk输入为分秒进位相与的notepad 1.0源码结果。q1为十位,q0为个位。
图3
程序如下:
library IEEE;
use IEEE.STD_LOGIC_.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity c is
Port ( clk : in std_logic;
q1,q0 : out std_logic_vector(3 downto 0));
end c;
architecture one of c is
begin
process (clk)
variable cq1,cq0:std_logic_vector(3 downto 0);
begin
if (clk'event and clk='1') then
if cq1="" and cq0="" then
cq1:=""; cq0:="";
elsif cq0<"" then
cq0:=cq0+1;
else cq0:=""; cq1:=cq1+1;
end if;
end if;
q1<=cq1;q0<=cq0;
end process;
end one;
仿真波形如下图4:
图4
4、分频器:
模块图如图5。由四个分频器构成,输入信号in_clk为Hz脉冲信号。把输入的Hz信号分频为四个脉冲信号,即1Hz的秒脉冲,4Hz的校时、校分脉冲,Hz的消抖脉冲以及Hz的蜂鸣器低音输入。
图5
程序如下:
library IEEE;
use IEEE.STD_LOGIC_.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity div is
Port ( in_clk : in std_logic;
clk_, clk_1,clk_4 ,clk_:out std_logic);
end div;
architecture one of div is
signal q,a,b,c:std_logic;
signal c1,c4,c:integer range downto 0;
begin
process(in_clk)
begin
if in_clk'event and in_clk='1' then
q<=not q;
if c>=7 then c<=0;c<=not c;else c<=c+1;end if;
if c4>= then c4<=0;b<=not b;else c4<=c4+1;end if;
if c1>= then c1<=0;a<=not a;else c1<=c1+1;end if;
end if;
end process;
clk_<=q;
clk_1<=a;
clk_4<=b;
clk_<=c;
end one;
仿真波形如下图6:
图6
5、消抖:
模块图如图7。分频出的用Hz信号对sa校时信号、sb校分信号、sc秒清零信号、sd闹时设置信号进行防抖动处理。心里fm源码是由四个两级d触发器构成的,分别对输入的sa、sb、sc、sd
信号的相邻两个上升沿进行比较以确定按键的按下,从而达到消抖的目的。
图7
程序如下:
library IEEE;
use IEEE.STD_LOGIC_.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity xd is
Port ( clk_ : in std_logic;
hj,mj,sclr,sdo :out std_logic;
sa,sb,sc,sd : in std_logic);
end xd;
architecture one of xd is
begin
process(clk_)
variable sa_n,sa_p,sb_n,sd_n,sb_p,sc_n,sc_p,sd_p:std_logic;
begin
if clk_'event and clk_='1' then
sa_p:=sa_n;sa_n:=sa;
sb_p:=sb_n;sb_n:=sb;
sc_p:=sc_n;sc_n:=sc;
sd_p:=sd_n;sd_n:=sd;
if sa_p= sa_n then hj<=sa;end if;
if sb_p= sb_n then mj<=sb;end if;
if sc_p= sc_n then sclr<=sc;end if;
if sd_p= sd_n then sdo<=sd;end if;
end if;
end process;
end one;
仿真波形如下图8:
图8
6、闹钟时间的设定:
模块图如图9。一键设定闹铃时间,内部由四个d触发器构成。当确定sd键按下时,将当前时间的小时和分的个位十位分别存入四个d触发器内,作为闹时时间。
图9
程序如下
library IEEE;
use IEEE.STD_LOGIC_.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity df4 is
Port ( sd :in std_logic;
hh,hl,mh,ml : in std_logic_vector(3 downto 0);
hh_o,hl_o,mh_o,ml_o: out std_logic_vector(3 downto 0));
end df4;
architecture one of df4 is
begin
process (sd,hh,hl,mh,ml)
begin
if sd='1' then
hh_o<=hh;hl_o<=hl;mh_o<=mh;ml_o<=ml;end if;
end process;
end one;
仿真波形如下图:
图
7、二选一电路
(1)一位二选一:
模块图如图。用以进行正常计时和校时/分的选择。alarm为经过消抖的校时/分信号。当按键未曾按下时,即校时/分信号没有到来时,二选一选择器会选择输出a(正常计时输入)信号,否则当alarm按键按下时输出y为校时/分输入信号——4Hz。
图
程序如下:
library IEEE;
use IEEE.STD_LOGIC_.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity xuan is
Port ( alarm,a,b: in std_logic;
y:out std_logic);
end xuan ;
architecture one of xuan is
begin
process(alarm,a,b)
begin
if alarm='0' then y<=a;else y<=b;
end if;
end process;
end one;
仿真波形如下图:
图
(2)三位二选一:
模块图如图。用以进行正常计时时间与闹铃时间显示的选择,alarm输入为按键。当alarm按键未曾按下时二选一选择器会选择输出显示正常的计时结果,否则当alarm按键按下时选择器将选择输出显示闹铃时间显示。
图
程序如下:
library IEEE;
use IEEE.STD_LOGIC_.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity x is
Port ( alarm : in std_logic;
y:out std_logic_vector(3 downto 0);
a,b: in std_logic_vector(3 downto 0));
end x;
architecture one of x is
begin
process(alarm,a,b)
begin
if alarm='0' then y<=a;else y<=b;
end if;
end process;
end one;
仿真结果如下图:
图
8、整点报时及闹时:
模块图如图。在分秒、秒、秒、秒给扬声器赋以低音Hz信号,在分秒给扬声器赋以高音Hz信号,音响持续1秒钟,在Hz音响结束时刻为整点。当系统时间与闹铃时间相同时给扬声器赋以高音Hz信号。闹时时间为一分钟。
图
程序如下:
library IEEE;
use IEEE.STD_LOGIC_.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity voice is
Port ( hou1,huo0,min1,min0,sec1,sec0,hh,hl,mh,ml: std_logic_vector(3 downto 0);
in_,in_:in std_logic;
q : out std_logic);
end voice;
architecture one of voice is
begin
process(min1,min0,sec1,sec0)
begin
if min1="" and min0="" and sec1="" then
if sec0="" or sec0="" or sec0="" or sec0=""
then q<=in_;
elsif sec1="" and sec0="" then q<=in_;
else q<='0';
end if;
else q<='0';
end if;
if min1=mh and min0=ml and hou1=hh and huo0=hl then
q<=in_;
end if;
end process;
end one;
仿真波形如下图
图
9、顶层原理图:
三、感想
通过这次设计,既复习了以前所学的知识,也进一步加深了对EDA的了解,让我对它有了更加浓厚的兴趣。特别是当每一个子模块编写调试成功时,心里特别的开心。但是在画顶层原理图时,遇到了不少问题,最大的问题就是根本没有把各个模块的VHD文件以及生成的器件都全部放在顶层文件的文件夹内,还有就是程序设计的时候考虑的不够全面,没有联系着各个模式以及实验板的情况来编写程序,以至于多考虑编写了译码电路而浪费了很多时间。在波形仿真时,也遇到了一点困难,想要的结果不能在波形上得到正确的显示
:在分频模块中,设定输入的时钟信号后,却只有二分频的结果,其余三个分频始终没反应。后来,在数十次的调试之后,才发现是因为规定的信号量范围太大且信号的初始值随机,从而不能得到所要的结果。还有的仿真图根本就不出波形,怎么调节都不管用,后来才知道原来是路径不正确,路径中不可以有汉字。真是细节决定成败啊!总的来说,这次设计的数字钟还是比较成功的,有点小小的成就感,终于觉得平时所学的知识有了实用的价值,达到了理论与实际相结合的目的,不仅学到了不少知识,而且锻炼了自己的能力,使自己对以后的路有了更加清楚的认识,同时,对未来有了更多的信心。
四、
参考资料:
1、潘松,王国栋,VHDL实用教程〔M〕.成都:电子科技大学出版社,.(1)
2、崔建明主编,电工电子EDA仿真技术北京:高等教育出版社,
3、李衍编著,EDA技术入门与提高王行西安:西安电子科技大学出版社,
4、侯继红,李向东主编,EDA实用技术教程北京:中国电力出版社,
5、沈明山编著,EDA技术及可编程器件应用实训北京:科学出版社,
6、侯伯亨等,VHDL硬件描述语言与数字逻辑电路设计西安: 西安电子科技大学出版社,
7、辛春艳编著,VHDL硬件描述语言北京:国防工业出版社,
EDA课ç¨è®¾è®¡ï¼ç¨VHDLç¼ç¨ååºç§è½¦è®¡è´¹å¨
课ç¨è®¾è®¡å 容ä¸è¦æ±
1ï¼ç¨å¼å ³æé®è¡¨ç¤ºèå²ï¼æ¯ä¸ªèå²ä»£è¡¨ç±³ï¼ä¸ªèå²1å ¬éï¼æ¯å ¬é1.4å ï¼è½åæ¥æ¾ç¤ºéç¨åè´¹ç¨ï¼
2ï¼ä½äº2å ¬é5å 计费ï¼é«äº2å ¬éæ»è´¹ç¨=èµ·æ¥è´¹ç¨+ï¼éç¨-2å ¬éï¼*éç¨åä»·+
çåæ¶é´*çååä»·ï¼
3ï¼çåæ¶é´å¤§äº2åéï¼ææ¯åé1.3å 计费ï¼
4ï¼å¯ä»¥è®¾å®èµ·æ¥ä»·åéç¨åä»·ã
ä¸ã设计åçä¸ææ¯æ¹æ³ï¼
å æ¬ï¼çµè·¯å·¥ä½åçåæä¸åçå¾ãå å¨ä»¶éæ©ä¸åæ°è®¡ç®ãçµè·¯è°è¯æ¹æ³ä¸ç»æ说æï¼
软件设计说æ书ä¸æµç¨å¾ã软件æºç¨åºä»£ç ã软件è°è¯æ¹æ³ä¸è¿è¡ç»æ说æã
æ ¹æ®è®¾è®¡è¦æ±ï¼ç³»ç»çè¾å ¥ä¿¡å·clkï¼è®¡ä»·å¼å§ä¿¡å·startï¼çå¾ ä¿¡å·stopï¼éç¨èå²ä¿¡å·finãç³»ç»çè¾åºä¿¡å·æï¼æ»è´¹ç¨æ°C0âc3ï¼è¡é©¶è·ç¦»k0âk1ï¼çå¾ æ¶é´m0âm1çãç³»ç»æ两个èå²è¾å ¥ä¿¡å·clk_k,fin,å ¶ä¸clk_kå°æ ¹æ®è®¾è®¡è¦æ±åé¢æhzï¼hzå1hzåå«ä½ä¸ºå ¬é计费åè¶ æ¶è®¡è´¹çèå²ã两个æ§å¶è¾å ¥å¼å ³startï¼stopï¼æ§å¶è¿ç¨ä¸ºï¼startä½ä¸ºè®¡è´¹å¼å§çå¼å ³ï¼å½start为é«çµå¹³æ¶ï¼ç³»ç»å¼å§æ ¹æ®è¾å ¥çæ åµè®¡è´¹ãå½æä¹å®¢ä¸è½¦å¹¶å¼å§è¡é©¶æ¶ï¼finèå²å°æ¥ï¼è¿è¡è¡é©¶è®¡è´¹ï¼æ¤æ¶çstopéè¦ç½®ä¸º0ï¼å¦éå车çå¾ ï¼å°±æstopå为é«çµå¹³ï¼
并å»é¤finè¾å ¥èå²ï¼è¿è¡çå¾ è®¡è´¹ï¼å½ä¹å®¢ä¸è½¦ä¸ä¸çå¾ æ¶ï¼ç´æ¥å°start置为0ï¼ç³»ç»åæ¢å·¥ä½ï¼ä»·æ ¼å¼å§å½ä¸ºèµ·æ¥ä»·5.0å ã
æ´ä¸ªè®¾è®¡ç±åé¢æ¨¡åï¼è®¡é模åï¼è®¡è´¹æ¨¡åï¼æ§å¶æ¨¡ååæ¾ç¤ºæ¨¡åäºä¸ªé¨åç»æã
å ¶ä¸è®¡é模åæ¯æ´ä¸ªç³»ç»å®ç°éç¨è®¡æ°åæ¶é´è®¡æ°çéè¦é¨åï¼æ§å¶æ¨¡åæ¯å®ç°ä¸å计费æ¹å¼çéæ©é¨åï¼æ ¹æ®æ设计ç使è½ç«¯éæ©æ¯æ ¹æ®éç¨è®¡è´¹è¿æ¯æ ¹æ®çå¾ æ¶é´è®¡è´¹ï¼åæ¶è®¾è®¡éè¿åé¢æ¨¡å产çä¸åé¢ççèå²ä¿¡å·æ¥å®ç°ç³»ç»ç计费ã计é模åéç¨1hzç驱å¨ä¿¡å·ï¼è®¡è´¹æ¨¡åéç¨hzï¼hzç驱å¨ä¿¡å·ï¼è®¡é模åæ¯è®¡æ°ä¸æ¬¡ï¼è®¡é模åå°±å®ç°æ¬¡æè 次计æ°ï¼å³ä¸ºå®ç°è®¡æ¶ç1.3å /minï¼è®¡ç¨æ¶ç1.4å /kmçæ¶è´¹ãç»ææ¡å¾å¦ä¸æ示ï¼
1.ç¾è¿å¶æ¨¡åï¼
å®ç°ç¾ç±³èå²ç驱å¨ä¿¡å·ï¼å 件æ¡å¾å¦å¾3æ示ï¼
å¾3 ç¾è¿å¶æ¨¡åæ¡å¾
æºç¨åºå¦ä¸ï¼
library ieee;
use ieee.std_logic_.all;
use ieee.std_logic_unsigned.all;
entity baijinzhi is
port(start,clk2: in std_logic; --ç§èå²
a: out std_logic_vector(3 downto 0));
end baijinzhi;
architecture rt1 of baijinzhi is
signal count_1:std_logic_vector(3 downto 0);
begin
a<=count_1;
process(start,clk2)
begin
if(start='0')then
count_1<="";
elsif(clk2'event and clk2='1')then
if(count_1="")then
count_1<="";
else
count_1<=count_1+'1';
end if;
end if;
end process;
end rt1
2.计费模å
; å®ç°éç¨åçåæ¶é´ç计费并è¾åºå°æ¾ç¤ºï¼å 件æ¡å¾4å¦ä¸ï¼
å¾4 计费模åæ¡å¾
æºç¨åºå¦ä¸ï¼
Library IEEE;
use IEEE.std_logic_.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
entity jifei is
port(clk2:in std_logic; --计费驱å¨ä¿¡å·
start:in std_logic; --计费å¼å§ä¿¡å·
c0,c1,c2,c3:buffer std_logic_vector(3 downto 0));
end jifei;
architecture rt1 of jifei is
begin
process(clk2,start)
begin
if start='0'then c3<="";c2<="";c1<="";c0<=""; --èµ·æ¥ä»·5å
elsif clk2'event and clk2='1'then
if c0="" then c0<="";
if c1="" then c1<="";
if c2="" then c2<="";
if c3="" then c3<="";
else c3<=c3+1;
end if;
else c2<=c2+1;
end if;
else c1<=c1+1;
end if;
else c0<=c0+1;
end if;
end if;
end process;
end rt1;
3.å ¬é模å
å®ç°åç¨ç计æ°åè¾åºè®¡è´¹èå²ï¼å 件æ¡å¾5å¦ä¸ï¼
å¾5 å ¬é模åæ¡å¾
æºç¨åºå¦ä¸ï¼
library ieee;
use ieee.std_logic_.all;
use ieee.std_logic_unsigned.all;
entity gongli is
port(clk1,start: in std_logic; --ç¾ç±³èå²
k1,k2,k3,k4: out std_logic_vector(3 downto 0); --éç¨æ¾ç¤º
temp2 : out std_logic);
end gongli;
architecture rt1 of gongli is
signal count_1: std_logic_vector(3 downto 0);
signal count_2: std_logic_vector(3 downto 0);
signal count_3: std_logic_vector(3 downto 0);
signal count_4: std_logic_vector(3 downto 0);
begin
k1<=count_1;
k2<=count_2;
k3<=count_3;
k4<=count_4;
process(start,clk1)
begin
if(start='0')then
count_1<="";
count_2<="";
count_3<="";
count_4<=""; ---å ¬éæ¸ é¶
elsif(clk1'event and clk1='1')then
if(count_1="")then --å ¬é计æ°å¨
count_1<="";count_2<=count_2+1;temp2<='1';
if(count_2="")then
count_2<="";count_3<=count_3+'1';
if(count_3="")then
count_3<="";count_4<=count_4+'1';
end if;
end if;
else
count_1<=count_1+'1';temp2<='0';
end if;
end if;
end process;
end rt1;
4.è¾åºæ¨¡å
å®ç°æææ°æ®çè¾åºï¼å 件æ¡å¾6å¦ä¸ï¼
å¾6 è¾åºæ¨¡åæ¡å¾
æºç¨åºå¦ä¸ï¼
library ieee;
use ieee.std_logic_.all;
use ieee.std_logic_unsigned.all;
entity shuchu is
port(y: in std_logic_vector(3 downto 0);
e: out std_logic_vector(6 downto 0));
end shuchu;
architecture rt1of shuchu is
begin
process
begin
case y is
when""=>e<="";
when""=>e<="";
when""=>e<="";
when""=>e<="";
when""=>e<="";
when""=>e<="";
when""=>e<="";
when""=>e<="";
when""=>e<="";
when""=>e<="";
when others=>e<="";
end case;
end process;
end rt1;
5.æ¾ç¤ºæ¨¡å
å®ç°æææ°æ®çæ¾ç¤ºï¼å 件æ¡å¾7å¦ä¸ï¼
å¾7 æ¾ç¤ºæ¨¡åæ¡å¾
æºç¨åºå¦ä¸ï¼
library ieee;
use ieee.std_logic_.all;
use ieee.std_logic_unsigned.all;
entity xianshi is
port(start: in std_logic;
a:in std_logic_vector(3 downto 0); --éæ©ä¿¡å·
c1,c2,c3,c4,out1,out2,out3,out4:in std_logic_vector(3 downto 0); --éç¨æ¾ç¤º,æ¶é´æ¾ç¤ºè¾å ¥
y:out std_logic_vector(3 downto 0)); --éç¨æ¾ç¤º,æ¶é´æ¾ç¤ºè¾åº
end xianshi;
architecture rt1 of xianshi is
begin
process
begin
if(start='0')then
y<="";
else case a is
when ""=> y<=c1 ;
when ""=> y<=c2 ;
when ""=> y<=c3 ;
when ""=> y<=c4 ;
when ""=> y<=out1 ;
when ""=> y<=out2;
when ""=> y<=out3 ;
when ""=> y<=out4;
when others =>y<= "";
end case;
end if;
end process;
end rt1;
6.dian模å
å¾8 dian模åæ¡å¾
æºç¨åºå¦ä¸ï¼
library ieee;
use ieee.std_logic_.all;
use ieee.std_logic_unsigned.all;
entity dian is
port(a: in std_logic_vector(3 downto 0);
e: out std_logic);
end dian;
architecture rt1 of dian is
begin
process
begin
case a is
when ""=>e<='1';
when ""=>e<='1';
when others=>e<='0';
end case;
end process;
end rt1;
ä¸ãä¸å个模å设计åæ
ç³»ç»æ»ä½é¡¶å±æ¡å¾å¦ä¸ï¼
ç³»ç»æ»ä½é¡¶å±æ¡å¾
ç¨åºæç»åè½å®ç°æ³¢å½¢ä»¿ç
1. åé¢æ¨¡å
ç±äºå®éªç®±ä¸æ²¡æhzåhzçæ´æ°åæ¶éä¿¡å·ï¼å æ¤éç¨é¢çè¾å¤§çkhzè¿è¡åé¢ï¼ä»¥è¿ä¼¼å¾å°hzï¼hzå1hzçæ¶éé¢çãéè¿ä»¥ä¸ä¸ç§ä¸åé¢ççèå²ä¿¡å·å®è¡åºç§è½¦è¡é©¶ï¼çå¾ ä¸¤ç§æ åµä¸çä¸å计费ã模åå 件å¦ä¸ï¼
åé¢æ¨¡åæ¡å¾
æºç¨åºå¦ä¸ï¼
Library IEEE;
use IEEE.std_logic_.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
entity fenpin is
port(clk_k:in std_logic; --ç³»ç»æ¶é
clk_:buffer std_logic; --åé¢
clk_:buffer std_logic; --åé¢
clk_1 : buffer std_logic); --1åé¢
end fenpin ;
architecture rt1 of fenpin is
signal q_:integer range 0 to ; --å®ä¹ä¸é´ä¿¡å·é
signal q_:integer range 0 to ;
signal q_1:integer range 0 to ;
begin
process(clk_k)
begin
If(clk_k' event and clk_k='1')then
If q_= then q_<=0;clk_<=not clk_;
else q_<=q_+1;
end if; --å¾hzé¢çä¿¡å·
If q_= then q_<=0;clk_<=not clk_;
else q_<=q_+1;
end if; --å¾hzé¢çä¿¡å·
If q_1= then q_1<=0;clk_1<=not clk_1;
else q_1<=q_1+1;
end if; --å¾1hzé¢çä¿¡å·
end if;
end process;
end rt1ï¼
2. 计é模å
计é模å主è¦å®æ计æ¶å计ç¨åè½ã
计æ¶é¨åï¼è®¡ç®ä¹å®¢ççå¾ ç´¯ç§¯æ¶é´ï¼å½çå¾ æ¶é´å¤§äº2minæ¶ï¼æ¬æ¨¡åä¸en1使è½ä¿¡å·å为1ï¼å½clk1æ¯æ¥ä¸ä¸ªä¸å沿ï¼è®¡æ¶å¨å°±èªå¢1ï¼è®¡æ¶å¨çéç¨ä¸ºminï¼æ»¡éç¨åèªå¨å½é¶ã
计ç¨é¨åï¼è®¡ç®ä¹å®¢æè¡é©¶çå ¬éæ°ï¼å½è¡é©¶éç¨å¤§äº2kmæ¶ï¼æ¬æ¨¡åä¸en0使è½ä¿¡å·å为1ï¼å½clkæ¯æ¥ä¸ä¸ªä¸å沿ï¼è®¡ç¨å¨å°±èªå¢1ï¼è®¡ç¨å¨çéç¨ä¸ºkmï¼æ»¡éç¨åèªå¨å½é¶ã
å 件æ¡å¾ä¸ºï¼
计é模åæ¡å¾
计é模å仿ç波形为ï¼
æºç¨åºå¦ä¸ï¼
library ieee;
use ieee.std_logic_.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity jiliang is
port(start:in std_logic; --计费å¼å§ä¿¡å·
fin:in std_logic; --éç¨èå²ä¿¡å·
stop:in std_logic; --è¡é©¶ä¸éçå¾ ä¿¡å·
clk1:in std_logic; --驱å¨èå²
en1,en0:buffer std_logic; --计费å价使è½ä¿¡å·
k1,k0:buffer std_logic_vector(3 downto 0); --è¡é©¶å ¬é计æ°
m1,m0:buffer std_logic_vector(3 downto 0)); --çå¾ æ¶é´è®¡æ°
end jiliang;
architecture rt2 of jiliang is
signal w:integer range 0 to ; --计æ¶èå´0~
begin
process(clk1)
begin
if(clk1'event and clk1='1')then
if start='0' then
w<=0;en1<='0';en0<='0';m1<="";
m0<="";k1<="";k0<="";
elsif stop='1' then --计æ¶å¼å§ä¿¡å·
if w= then
w<=0;
else w<=w+1;
end if;
if m0="" then
m0<="";
if m1="" then
m1<="";
else m1<=m1+1;
end if;
else m0<=m0+1;
end if;
if stop='1' then en0<='0';
if m1&m0>"" then en1<='1'; --è¥çå¾ æ¶é´å¤§äº2minåen1ç½®1
else en1<='0';
end if;
end if;
elsif fin='1' then --éç¨è®¡æ°å¼å§
if k0="" then k0<="";
if k1="" then k1<=""; --计ç¨èå´0~
else k1<=k1+1;
end if;
else k0<=k0+1;
end if;
if stop='0' then
en1<='0';
if k1&k0>"" then
en0<='1'; --è¥è¡ä½¿éç¨å¤§äº2kmï¼åen0ç½®1
else en0<='0';
end if;
end if;
end if;
end if;
end process;
end rt2;
3. æ§å¶æ¨¡å
æ¬æ¨¡å主è¦æ¯éè¿è®¡é模å产çç两个ä¸åçè¾å ¥ä½¿è½ä¿¡å·en0ï¼en1ï¼å¯¹æ¯ä¸ªåé¢æ¨¡åè¾åºçhzï¼hzçèå²è¿è¡éæ©è¾åºçè¿ç¨ï¼æ¬æ¨¡åå®ç°äºåèå²çäºéä¸ï¼æç»ç®ç为äºè®¡è´¹æ¨¡åä¸å¯¹è¡é©¶è¿ç¨ä¸ä¸åçæ¶æ®µè¿è¡è®¡ä»·ã
模åå 件å¦ä¸ï¼
æ§å¶æ¨¡åæ¡å¾
æ§å¶æ¨¡å仿ç波形为ï¼
æºç¨åºå¦ä¸ï¼
Library IEEE;
use IEEE.std_logic_.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
entity kongzhi is
port(en0,en1:in std_logic; --使è½éæ©ä¿¡å·
clk_in1:in std_logic; --åé¢è¾å ¥ä¿¡å·
clk_in2:in std_logic; --åé¢è¾å ¥ä¿¡å·
clk_out:out std_logic); --è¾åºä¿¡å·
end kongzhi;
architecture rt3 of kongzhi is
begin
process(en0,en1)
begin
if en0='1' then --å®ç°äºéä¸åè½
clk_out<=clk_in1;
elsif en1='1' then
clk_out<=clk_in2;
end if;
end process;
end rt3;
4.计费模å
å½è®¡è´¹ä¿¡å·startä¸ç´å¤äºé«çµå¹³å³è®¡è´¹ç¶ææ¶ï¼æ¬æ¨¡åæ ¹æ®æ§å¶æ¨¡åéæ©åºçä¿¡å·ä»è对ä¸åçåä»·æ¶æ®µè¿è¡è®¡è´¹ãå³è¡ç¨å¨2kmå ï¼èä¸çå¾ ç´¯è®¡æ¶é´å°äº2minå为起æ¥ä»·5å ï¼2kmå¤ä»¥æ¯å ¬é1.4.å 计费ï¼çå¾ ç´¯ç§¯æ¶é´è¶ è¿2minåææ¯åé1.3å 计费ãc0ï¼c1ï¼c2ï¼c3åå«è¡¨ç¤ºè´¹ç¨çæ¾ç¤ºã
模åå 件为ï¼
计费模åæ¡å¾
计费模å仿ç波形为ï¼
æºç¨åºå¦ä¸ï¼
Library IEEE;
use IEEE.std_logic_.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
entity jifei is
port(clk2:in std_logic; --计费驱å¨ä¿¡å·
start:in std_logic; --计费å¼å§ä¿¡å·
c0,c1,c2,c3:buffer std_logic_vector(3 downto 0));
end jifei;
architecture rt4 of jifei is
begin
process(clk2,start)
begin
if start='0'then c3<="";c2<="";c1<="";c0<=""; --èµ·æ¥ä»·5å
elsif clk2'event and clk2='1'then
if c0="" then c0<="";
if c1="" then c1<="";
if c2="" then c2<="";
if c3="" then c3<=""; --计价èå´0~.9
else c3<=c3+1;
end if;
else c2<=c2+1;
end if;
else c1<=c1+1;
end if;
else c0<=c0+1;
end if;
end if;
end process;
end rt4;
5.æ¾ç¤ºæ¨¡å
æ¾ç¤ºæ¨¡åå®æ计价ï¼è®¡æ¶å计ç¨æ°æ®æ¾ç¤ºã计费æ°æ®éå ¥æ¾ç¤ºæ¨¡åè¿è¡è¯ç ï¼æåéè³ä»¥ç¾å ï¼åå ï¼å ï¼è§ä¸ºåä½å¯¹åºçæ°ç 管ä¸æ¾ç¤ºã计æ¶æ°æ®éå ¥æ¾ç¤ºæ¨¡åè¿è¡è¯ç ï¼æåéè³ä»¥å为åä½å¯¹åºçæ°ç 管ä¸æ¾ç¤ºã计ç¨æ°æ®éå ¥æ¾ç¤ºæ¨¡åè¿è¡è¯ç ï¼æåéè³ä»¥km为åä½çæ°ç 管ä¸æ¾ç¤ºã
模åå 件为ï¼
æ¾ç¤ºæ¨¡åæ¡å¾
æºç¨åºå¦ä¸ï¼
library ieee;
use ieee.std_logic_.all;
use ieee.std_logic_unsigned.all; --å®ä¹åºå
entity xianshi is --å®ä¹å®ä½
port(
clk_scan:in std_logic; --æ«ææ¶éä¿¡å·ç«¯å£è®¾ç½®
c3,c2,c1,c0:in std_logic_vector(3 downto 0); --æ»è´¹ç¨è¾å ¥ç«¯å£
k0,k1:in std_logic_vector(3 downto 0); --éç¨è¾å ¥ç«¯å£
m0,m1:in std_logic_vector(3 downto 0); --çå¾ æ¶é´è¾å ¥ç«¯å£
sel:out std_logic_vector(2 downto 0); --æ§å¶æ°ç 管ä½éä¿¡å·çæ«æä¿¡å·è¾åºç«¯å£
led:out std_logic_vector(6 downto 0); --æ°ç 管çæ§å¶ç«¯å£
led_dp:out std_logic --æ°ç 管çå°æ°ç¹è¾åºç«¯å£
);
end xianshi;
architecture rt5 of xianshi is
signal duan:std_logic_vector(6 downto 0); --æ°ç æ¾ç¤ºç®¡ä¸é´åé
signal shuju:std_logic_vector(3 downto 0); --éæ©è¾å ¥ç«¯çä¸é´åé
signal cnt:std_logic_vector(2 downto 0); --æ§å¶æ°ç 管çä¸é´åé
signal xiaodian:std_logic; --å°æ°ç¹çä¸é´åé
begin
process(clk_scan) --å¼å§è¿ç¨
begin
if clk_scan'event and clk_scan='1' then
cnt<=cnt+1; --æ¯æä¸ä¸ªæ«æä¿¡å·ä¸å沿å®ç°å 1æ«æ
end if;
end process; --ç»æè¿ç¨
process(cnt) --å¼å§è¿ç¨(éæ©æ«ææ¾ç¤ºæ°ç 管)
begin
case cnt is --æ«ææ¶ç»æ¯ä¸ªæ°ç 管èµå¼
when ""=>shuju<=c0;
when ""=>shuju<=c1;
when ""=>shuju<=c2;
when ""=>shuju<=c3;
when ""=>shuju<=k0;
when ""=>shuju<=k1;
when ""=>shuju<=m0;
when ""=>shuju<=m1;
when others=> null;
end case;
if (cnt="" or cnt="")
then xiaodian<='1'; --å¨éç¨åæ»è´¹ç¨ç个ä½å¤æ¾ç¤ºå°æ°ç¹
else xiaodian<='0';
end if;
end process; --ç»æè¿ç¨
process(shuju) --å¼å§è¿ç¨(è¯ç æ¾ç¤º)
begin
case shuju is
when ""=>duan<=""; --0
when ""=>duan<=""; --1
when ""=>duan<=""; --2
when ""=>duan<=""; --3
when ""=>duan<=""; --4
when ""=>duan<=""; --5
when ""=>duan<=""; --6
when ""=>duan<=""; --7
when ""=>duan<=""; --8
when ""=>duan<=""; --9
when others=>null;
end case;
end process;
sel<=cnt;
led<=duan;
led_dp<=xiaodian;
end rt5;
äºã课ç¨è®¾è®¡å·¥ä½è®°å½ï¼
å æ¬ï¼è®¾è®¡æ¥éª¤ä¸æ¶é´å®æãè°è¯æ¥éª¤ä¸æ¶é´å®æã课é¢å®æç»æ说æ
2.课é¢å®æç»æ说æï¼
æ¤è®¡è´¹å¨è½å®ç°èµ·æ¥ä»·æ¯5å ï¼å®ç°å®éªè¦æ±ç1å ¬é计费ä¸æ¬¡åä»·ï¼è¡é©¶å ¬é大äº2kmæ¶æ¯å ¬éæ1.4å 计费并è½æ¾ç¤ºéç¨åæ»å ±çè´¹ç¨ãå½è¡é©¶äº6å ¬éï¼çå¾ äº4åéæ¶ï¼è´¹ç¨æ¾ç¤ºä¸º.8å ãä¸è®¡ç®å ¬å¼æ»è´¹ç¨=èµ·æ¥è´¹ç¨+ï¼éç¨-2å ¬éï¼*éç¨åä»·+çåæ¶é´*çååä»·ï¼å³.8=5+ï¼6-2ï¼*1.4+4*1.3ãå®éªç»æä¸ç论ç»æå®å ¨ä¸è´ï¼å®éªè®¾è®¡æåã