出租车计费器VHDL语言

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

《数字逻辑电路》课程设计——出租车计费器的设计计算机学院软件工程1401赵雷3140608027出租车计费器的设计一、系统设计任务及要求(1)能实现计费功能,计费标准为:按行驶里程收费,起步价为7.00元,并在车行3千米后再按2元/千米,当总费用达到或超过40元时,每千米收费4元,客户端需要停车等待时按时间收费,计费单价每20秒1元。(2)设计动态扫描电路:以十进制显示出租车行驶的里程与车费,在数码管上显示(前四个显示里程,后三个显示车费)。(3)用VHDL语言设计符合上述功能要求的出租车计费器,并用层次化设计方法设计该电路。(4)完成电路全部设计后,通过系统试验箱下载验证设计的正确性。二、系统设计方案根据系统设计设计要求不难得知,整个出租车计费系统按功能主要分为速度选择模块、计程模块、计时模块、计费模块4个模块。车速控制模块计数器模块译码模块动态扫描电路模块顶层原理图1.速度模块:通过对速度信号sp的判断,决定行使的路程,这里是通过速度信号来模拟一个变量的取值。如kinside变量,其含义是行进100m所需的时钟周期数,然后每行进100m,则产生一个脉冲clkout来驱动计费模块。VHDL语言:libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityTaxi_part1isport(clk,reset,start,stop:instd_logic;sp:instd_logic_vector(2downto0);clkout:outstd_logic);endTaxi_part1;architecturebehaviorofTaxi_part1isbeginprocess(clk,reset,stop,start,sp)typestate_typeis(s0,s1);variables_state:state_type;variablecnt:integerrange0to1400;variablekinside:integerrange0to1400;begincasespiswhen000=kinside:=0;when001=kinside:=1400;when010=kinside:=1200;when011=kinside:=1000;when100=kinside:=800;when101=kinside:=600;when110=kinside:=400;when111=kinside:=200;endcase;if(reset='1')thens_state:=s0;elsif(clk'eventandclk='1')thencases_stateiswhens0=cnt:=0;clkout='0';if(start='1')thens_state:=s1;elses_state:=s0;endif;whens1=clkout='0';if(stop='1')thens_state:=s0;--相当于无客户上车elsif(sp=000)thens_state:=s1;---有客户上车,但车速位0,即客户刚上车还未起步elsif(cnt=kinside)thencnt:=0;clkout='1';s_state:=s1;elsecnt:=cnt+1;s_state:=s1;endif;endcase;endif;endprocess;endbehavior;2.计程模块:由于一个clkout信号代表行进100m,故通过对clkout计数,可以获得共行进的距离kmcount。VHDL语言:libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityTaxi_part2isport(clkout,reset:instd_logic;kmcnt1:outstd_logic_vector(3downto0);kmcnt2:outstd_logic_vector(3downto0);kmcnt3:outstd_logic_vector(3downto0));endTaxi_part2;architecturebehaviorofTaxi_part2isbeginprocess(clkout,reset)variablekm_reg:std_logic_vector(11downto0);beginif(reset='1')thenkm_reg:=000000000000;elsif(clkout'eventandclkout='1')then--km_reg(3downto0)对应里程十分位if(km_reg(3downto0)=1001)thenkm_reg:=km_reg+0111;--十分位向个位的进位处理elsekm_reg(3downto0):=km_reg(3downto0)+0001;endif;if(km_reg(7downto4)=1010)thenkm_reg:=km_reg+01100000;--个位向十位的进位处理endif;endif;kmcnt1=km_reg(3downto0);kmcnt2=km_reg(7downto4);kmcnt3=km_reg(11downto8);endprocess;endbehavior;3.计时模块:在汽车启动时,当遇到顾客等人时,出租车采用计时收费的方式。通过对速度信号sp的判断决定是否开始记录时间。当stop=1时,不计费,当stop=0,sp=0时,开始按时间计费,当时间达到足够长时则产生Timecount脉冲,并重新计时。一个Timecount脉冲相当于等待的时间达到了时间计费的长度。使用1kHz的系统时钟,计算20s计数值为20000。libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityTaxi_part3isport(clk,reset,start,stop:instd_logic;sp:instd_logic_vector(2downto0);timecount:outstd_logic);endTaxi_part3;architecturebehaviorofTaxi_part3isbeginprocess(reset,clk,sp,stop,start)typestate_typeis(t0,t1,t2);variablet_state:state_type;variablewaittime:integerrange0to1000;beginif(reset='1')thent_state:=t0;elsif(clk'eventandclk='1')thencaset_stateiswhent0=waittime:=0;timecount='0';if(start='1')thent_state:=t1;elset_state:=t0;endif;whent1=if(sp=000)thent_state:=t2;elsewaittime:=0;t_state:=t1;endif;whent2=waittime:=waittime+1;timecount='0';if(waittime=1000)thentimecount='1';--20s,即1000个clk,产生一个时间计费脉冲waittime:=0;elsif(stop='1')thent_state:=t0;elsif(sp=000)thent_state:=t2;elsetimecount='0';t_state:=t1;endif;endcase;endif;endprocess;endbehavior;4.计费模块:计费模块由两个线程组成。其中一个进程根据条件对Enable和Price赋值:当记录的距离达到3千米后Enable变为1,开始进行每千米收费,当总费用大于40元后,则单价Price由原来的2元/千米变为4元/千米;第二个进程在每个时钟周期判断Timecount和Clkcount的值。当其为1时,则在总费用上加上相应的费用。VHDL语言:libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityTaxi_part4isport(clk,reset,timecount,clkout:instd_logic;kmcnt2:instd_logic_vector(3downto0);kmcnt3:instd_logic_vector(3downto0);count1:outstd_logic_vector(3downto0);count2:outstd_logic_vector(3downto0);count3:outstd_logic_vector(3downto0));endTaxi_part4;architecturebehaviorofTaxi_part4issignalcash:std_logic_vector(11downto0);signalPrice:std_logic_vector(3downto0);signalEnable:std_logic;beginprocess(cash,kmcnt2)beginif(cash=000001000000)thenprice=0100;elsePrice=0010;endif;if((kmcnt2=0011)or(kmcnt3=0001))thenEnable='1';elseEnable='0';endif;endprocess;kmmoney2:process(reset,clkout,clk,Enable,Price,kmcnt2)variablereg2:std_logic_vector(11downto0);variableclkout_cnt:integerrange0to10;beginif(reset='1')thencash=000000000111;--起步费用设为7元elsif(clk'eventandclk='1')thenif(timecount='1')then--判断是否需要时间计费,每20s加一元reg2:=cash;if(reg2(3downto0)+00011001)thenreg2(7downto0):=reg2(7downto0)+00000111;if(reg2(7downto4)1001)thencash=reg2+000001100000;elsecash=reg2;endif;elsecash=reg2+0001;endif;elsif(clkout='1'andEnable='1')then--里程计费if(clkout_cnt=9)thenclkout_cnt:=0;reg2:=cash;if(0000®2(3downto0)+price(3downto0)00001001)thenreg2(7downto0):=reg2(7downto0)+00000110+price;if(reg2(7downto4)1001)thencash=reg2+000001100000;elsecash=reg2;endif;elsecash=reg2+price;endif;elseclkout_cnt:=clkout_cnt+1;endif;endif;endif;endprocess;count1=cash(3downto0);--总费用的个位count2=cash(7downto4);--总费用的十位count3=cash(11downto8);--总费用的百位endbehavior;5.显示模

1 / 11
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功