基于VHDL语言出租车计价器设计.docx
《基于VHDL语言出租车计价器设计.docx》由会员分享,可在线阅读,更多相关《基于VHDL语言出租车计价器设计.docx(20页珍藏版)》请在冰点文库上搜索。
![基于VHDL语言出租车计价器设计.docx](https://file1.bingdoc.com/fileroot1/2023-5/9/b1ab913d-a8d6-4b5b-b29e-fa66783626b4/b1ab913d-a8d6-4b5b-b29e-fa66783626b41.gif)
基于VHDL语言出租车计价器设计
1.设计背景
汽车计价器是乘客与司机双方的交易准则,它是出租车行业发展的重要标志,是出租车最重要的工具。
它关系着双方的利益。
具有良好的性能的计价器无疑是对广大出租车司机朋友还是乘客来说都是很重要的。
因此,汽车计价器的研究也是十分有应用价值的。
随着生活水平的提高,人们已不再满足于衣食住的享受,出行的舒适已受到越来越多人的关注。
于是,出租车行业以低价高质的服务给人们带来了出行的享受。
但是总存在着买卖纠纷困扰着行业的发展。
而在出租车行业中解决这一矛盾的最好方法就是改良计价器。
用更加精良的计价器来为乘客提供更加方便快捷的服务。
我国在70年代开始出现出租车,但那时的计费系统大都是国外进口的,不但不不够准确,而且价格还十分昂贵。
随着改革开放的日益深入,出租车行业的发展势头已十分突出,国各机械厂纷纷推出国产计价器。
刚开始出租车计价器的功能从刚才开始的只显示路程,到能够自主计费,以及现在能够打印发票和语音提示、按时间自主变动单价等功能。
随着旅游业的发展,出租车行业已成为城市的窗口,象征着一个城市的文明程度。
本设计就是采用VHDL硬件描述语言作为设计手段,采用自顶向下的设计思路,得到出租车计价系统的硬件结构,通过QuartusII7.2软件下进行设计、仿真,再在EDA试验箱进行硬件仿真,使各项指标符合设计要求,具有一定的实用性。
虽然以前有基于数字电路、单片机进行的出租车计价器的设计,但用数字电路设计的整体电路规模较大,所用的器件较多,造成故障率高,导致计价器不够准确;而基于单片机的设计,虽然开发成本降低,但其外围电路较多,而且调试复杂,抗干扰能力差,从而也导致计价器不够准确。
而基于VHDL语言的FPGA芯片稳定性好,抗干扰能力强,外围电路少,执行速度快,适合像出租车计价器的这种较复杂的电路设计。
2.设计原理
2.1设计要求
设计一种出租车计价器,计费标准如下:
(1)起步价8.00元,起步公里为3公里;
(2)超过三公里,每公里按1.00元收费;
(3)单程行驶里程超过20公里。
每公里租价加收50%;
(4)等候时间累积一分钟,每分钟1.00元;
要求显示里程、计费及等候时间。
乘客上车后,按下启动键,开始计费,除非同一个乘客往返用哪个车,否则按下单程键,这样行驶里程超过20公里时,每公里加收50%,即每公里租费1.5元;计费显示为3位整数,一位小数。
2.2设计模块
2.2.1总体设计
本出租车计价器的设计共分4个模块:
判断模块、时间模块、里程模块、计费模块。
总的设计图如图1所示:
2.2.2判断模块
判断模块主要通过对秒脉冲和里程脉冲进行计数,判断出租车是否停下,然后输出片选信号,选择时间计费还是里程计费。
判断模块的模块图如图2所示:
2.2.3时间模块
时间模块是当出租车停下时,对秒脉冲进行计数,从而计算出出租车停下的累积时间,并输出累积时间和计费脉冲。
时间模块的模块图如图3所示:
2.2.4里程模块
里程模块是当出租车行驶的时候,对里程脉冲进行计数,从而算出出租车所行驶的里程,通过对单双程的控制进行不同的计费标准,最后输出行驶里程和计费脉冲。
里程模块的模块图如图4所示:
2.2.5计费模块
计费模块通过对里程计费脉冲和时间计费脉冲分别进行计数,将其换算成价钱并对进行价钱输出。
计费模块的模块图如图5所示:
3.仿真结果分析
3.1判断模块的仿真
判断模块的仿真结果如图6所示:
图6判断模块的仿真结果
3.2时间模块的仿真
时间模块的仿真结果如图7所示:
图7时间模块的仿真结果
3.3里程模块的仿真
里程模块的仿真结果如图8所示:
图8里程模块的仿真结果
3.4计费模块的仿真
计费模块的仿真结果如图9所示:
图9计费模块的仿真结果
3.5元件例化后的仿真
元件例化后的仿真结果如图10所示:
图10元件例化后的仿真结果
6.模块的引脚锁定
图11模块的引脚锁定
引脚锁定图如图11所示:
4.设计总结
在这次对出租车计价器的课程设计实习中,我们充分的应用了所学的知识,通过去图书馆查阅相关资料和上网搜索相关知识,我们颇有收获。
由于这次设计比往常设计要复杂,如果将所有功能设计到一个模块中,对于设计和编程都有不小的困难,所以最后我们采用模块化设计,将某些功能设计成一个模块,最后用元件例化将各个模块连接起来,形成一个完整的系统,这种设计方法不仅降低了编程难度,而且使我们的设计更有条理。
通过这次设计,我们对模块化设计有了更深的了解。
在这次设计中,我们也遇到了许多困难。
有些设计虽然在逻辑上成立,但FPGA的硬件结构不能实现这种设计,比如多值驱动问题,上升下降沿问题,像我在设计计费模块的时候,预想的是时间计费脉冲和里程计费脉冲共同来驱动计费计数器,实现计费功能,这种设计很简单,但这种设计会报错。
最后只能时间、里程分别计费,然后将费用分别相加,这种设计虽然有点复杂,但并没有报错,而且仿真结果正确。
通过这次设计我们更加了解了FPGA的硬件结构,以后设计的时候要注意使用能实现的设计方式。
这次设计让我们更加了解了EDA的设计方法,熟悉了模块化的设计思路,对于以后的设计很有帮助。
总之,这次设计很有意义。
参考文献
[1]松,黄继业.《EDA技术使用教程》.科学,2010.6
[2]江海.《EDA技术课程设计》.华中科技大学,2009.5
附录
参考程序:
1.判断模块
libraryieee;
useieee.std_logic_1164.all;
--
entityjudgeis
port(sclk,sta,lclk:
instd_logic;
dge:
outstd_logic);
end;
architecturebehofjudgeis
begin
process(sta,lclk,sclk)
variablea:
integerrange0to64;
begin
ifsta='1'then
iflclk'eventandlclk='1'then
a:
=a+1;
endif;
ifsclk'eventandsclk='1'then
ifa=0then
dge<='0';--shijianprocess
else
dge<='1';--lichengprocess
endif;
endif;
ifsclk='1'then
a:
=0;
endif;
else
dge<='Z';
endif;
endprocess;
end;
2.时间模块
libraryieee;
useieee.std_logic_1164.all;
--
entitytime_countis
port(sta,sclk,dge:
instd_logic;
t_count:
outstd_logic;
minge:
outintegerrange0to10;
minshi:
outintegerrange0to10);
end;
--
architecturebehoftime_countis
begin
process(sta,sclk,dge)
variablecount:
integerrange0to60;
variablege:
integerrange0to10;
variableshi:
integerrange0to10;
variablet_c:
std_logic;
begin
ifsta='1'then
ifdge='0'then
ifsclk'eventandsclk='1'then
count:
=count+1;
ifcount=1then
t_c:
='0';
endif;
ifcount=60then
count:
=0;
ge:
=ge+1;
t_c:
='1';
ifge=10then
ge:
=0;
shi:
=shi+1;
ifshi=10then
shi:
=0;
endif;
endif;
endif;
endif;
endif;
else
ge:
=0;
shi:
=0;
t_c:
='0';
endif;
minge<=ge;
minshi<=shi;
t_count<=t_c;
endprocess;
end;
3.里程模块
--1500round/km
--1.00yuan/km->per150->+1
--1.50yuan/km->per100->+1
libraryieee;
useieee.std_logic_1164.all;
--
entitydistance_countis
port(sta,lclk,doub,dge:
instd_logic;
kmfen,kmge,kmshi:
outintegerrange0to10;
d_count:
outstd_logic);
end;
--
architecturebehofdistance_countis
begin
process(sta,lclk,doub,dge)
variablefen,ge,shi:
integerrange0to10;
variablecount:
integerrange0to150;
variablect:
integerrange0to150;
variabled_c:
std_logic;
begin
ifsta='1'then
ifdge='1'then
iflclk'eventandlclk='1'then
ct:
=ct+1;
count:
=count+1;
ifdoub='0'andshi>=2then--singleandlicheng>=20km
ifct=1then
d_c:
='0';
endif;
ifct=100then
ct:
=0;
d_c:
='1';
endif;
elsifge>=3orshi/=0then--doubleorlicheng<=20kmandkm>3
ifct=1then
d_c:
='0';
endif;
ifct=150then
ct:
=0;
d_c:
='1';
endif;
else
ct:
=0;
endif;
ifcount=150then
count:
=0;
fen:
=fen+1;
iffen=10then
fen:
=0;
ge:
=ge+1;
ifge=10then
ge:
=0;
shi:
=shi+1;
ifshi=10then
shi:
=0;
endif;
endif;
endif;
endif;
endif;
endif;
else
fen:
=0;
ge:
=0;
shi:
=0;
d_c:
='0';
endif;
kmfen<=fen;
kmge<=ge;
kmshi<=shi;
d_count<=d_c;
endprocess;
end;
4.计费模块
libraryieee;
useieee.std_logic_1164.all;
--
entityprice_countis
port(sta,t_count,d_count:
instd_logic;
mjiao,mge,mshi,mbai:
outintegerrange0to10);
end;
--
architecturebehofprice_countis
signalt_ge,t_shi,t_bai:
integerrange0to10;
signald_ge,d_shi,d_bai:
integerrange0to10;
begin
--
process(sta,t_count)
variabletshi,tbai:
integerrange0to10;
variabletge:
integerrange0to10:
=8;
begin
ifsta='1'then
ift_count'eventandt_count='1'then
tge:
=tge+1;
iftge=10then
tge:
=0;
tshi:
=tshi+1;
iftshi=10then
tshi:
=0;
tbai:
=tbai+1;
iftbai=10then
tbai:
=0;
endif;
endif;
endif;
endif;
else
tge:
=8;
tshi:
=0;
tbai:
=0;
endif;
t_ge<=tge;
t_shi<=tshi;
t_bai<=tbai;
endprocess;
--
process(sta,d_count)
variabledjiao:
integerrange0to10;
variabledge,dshi,dbai:
integerrange0to10;
begin
ifsta='1'then
ifd_count'eventandd_count='1'then
djiao:
=djiao+1;
ifdjiao=10then
djiao:
=0;
dge:
=dge+1;
ifdge=10then
dge:
=0;
dshi:
=dshi+1;
ifdshi=10then
dshi:
=0;
dbai:
=dbai+1;
ifdbai=10then
dbai:
=0;
endif;
endif;
endif;
endif;
endif;
else
djiao:
=0;
dge:
=0;
dshi:
=0;
dbai:
=0;
endif;
mjiao<=djiao;
d_ge<=dge;
d_shi<=dshi;
d_bai<=dbai;
endprocess;
--
process(d_ge,d_shi,d_bai,t_ge,t_shi,t_bai)
variablecge,cshi,cbai:
integerrange0to1;
variablege,shi,bai:
integerrange0to20;
begin
ge:
=d_ge+t_ge;
ifge>=10then
ge:
=ge-10;
cge:
=1;
else
cge:
=0;
endif;
shi:
=d_shi+t_shi+cge;
ifshi>=10then
shi:
=shi-10;
cshi:
=1;
else
cshi:
=0;
endif;
bai:
=d_bai+t_bai+cshi;
ifbai>=10then
bai:
=bai-10;
cbai:
=1;
else
cbai:
=0;
endif;
mge<=ge;
mshi<=shi;
mbai<=bai;
endprocess;
end;
5.元件例化
libraryieee;
useieee.std_logic_1164.all;
--
entitycompis
port(sclk,lclk,sta,doub:
instd_logic;
time_ge,time_shi:
outintegerrange0to10;
pri_jiao,pri_ge,pri_shi,pri_bai:
outintegerrange0to10;
dis_fen,dis_ge,dis_shi:
outintegerrange0to10);
end;
--
architecturebehofcompis
--
componentjudgeis
port(sclk,sta,lclk:
instd_logic;
dge:
outstd_logic);
endcomponent;
--
componenttime_countis
port(sta,sclk,dge:
instd_logic;
t_count:
outstd_logic;
minge:
outintegerrange0to10;
minshi:
outintegerrange0to10);
endcomponent;
--
componentdistance_countis
port(sta,lclk,doub,dge:
instd_logic;
kmfen,kmge,kmshi:
outintegerrange0to10;
d_count:
outstd_logic);
endcomponent;
--
componentprice_countis
port(sta,t_count,d_count:
instd_logic;
mjiao,mge,mshi,mbai:
outintegerrange0to10);
endcomponent;
--
signalw,x,y:
std_logic;
--
begin
U1:
judgeportmap(sta=>sta,sclk=>sclk,lclk=>lclk,dge=>w);
U2:
time_countportmap(sta=>sta,sclk=>sclk,dge=>w,
t_count=>x,minge=>time_ge,minshi=>time_shi);
U3:
distance_countportmap(sta=>sta,doub=>doub,lclk=>lclk,dge=>w,
d_count=>y,kmfen=>dis_fen,kmge=>dis_ge,kmshi=>dis_shi);
U4:
price_countportmap(sta=>sta,t_count=>x,d_count=>y,
mjiao=>pri_jiao,mge=>pri_ge,mshi=>pri_shi,mbai=>pri_bai);
end;