出租车计费器VHDL语言_第1页
出租车计费器VHDL语言_第2页
出租车计费器VHDL语言_第3页
出租车计费器VHDL语言_第4页
出租车计费器VHDL语言_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、数字逻辑电路课程设计 出租车计费器的设计计算机学院 软件工程1401赵雷 3140608027出租车计费器的设计1、 系统设计任务及要求(1) 能实现计费功能,计费标准为:按行驶里程收费,起步价为7.00元,并在车行3千米后再按2元/千米,当总费用达到或超过40元时,每千米收费4元,客户端需要停车等待时按时间收费,计费单价每20秒1元。(2) 设计动态扫描电路:以十进制显示出租车行驶的里程与车费,在数码管上显示(前四个显示里程,后三个显示车费)。(3) 用VHDL语言设计符合上述功能要求的出租车计费器,并用层次化设计方法设计该电路。(4) 完成电路全部设计后,通过系统试验箱下载验证设计的正确性

2、。2、 系统设计方案根据系统设计设计要求不难得知,整个出租车计费系统按功能主要分为速度选择模块、计程模块、计时模块、计费模块4个模块。顶层原理图1. 速度模块:通过对速度信号sp的判断,决定行使的路程,这里是通过速度信号来模拟一个变量的取值。如kinside变量,其含义是行进100m所需的时钟周期数,然后每行进100m,则产生一个脉冲clkout来驱动计费模块。VHDL语言:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity Taxi_part1 is port(clk,reset,st

3、art,stop:in std_logic; sp :in std_logic_vector(2 downto 0); clkout :out std_logic);end Taxi_part1;architecture behavior of Taxi_part1 isbegin process(clk,reset,stop,start,sp) type state_type is(s0,s1); variable s_state:state_type; variable cnt:integer range 0 to 1400; variable kinside:integer range

4、0 to 1400;begin case sp is when "000"=> kinside:=0; when "001"=> kinside:=1400; when "010"=> kinside:=1200; when "011"=> kinside:=1000; when "100"=> kinside:=800; when "101"=> kinside:=600; when "110"=> kinsid

5、e:=400; when "111"=> kinside:=200; end case; if(reset='1') then s_state:=s0; elsif(clk'event and clk='1') then case s_state is when s0=> cnt:=0;clkout<='0' if(start='1') then s_state:=s1; else s_state:=s0; end if; when s1=> clkout<='0&

6、#39; if(stop='1') then s_state:=s0; -相当于无客户上车 elsif(sp="000") then s_state:=s1; -有客户上车,但车速位0,即客户刚上车还未起步 elsif(cnt=kinside) then cnt:=0;clkout<='1' s_state:=s1; else cnt:=cnt+1; s_state:=s1; end if; end case; end if; end process;end behavior;2.计程模块:由于一个clkout信号代表行进100m,故通

7、过对clkout计数,可以获得共行进的距离kmcount。VHDL语言:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity Taxi_part2 is port(clkout,reset:in std_logic; kmcnt1:out std_logic_vector(3 downto 0); kmcnt2:out std_logic_vector(3 downto 0); kmcnt3:out std_logic_vector(3 downto 0);end Taxi_part2;a

8、rchitecture behavior of Taxi_part2 isbegin process(clkout,reset) variable km_reg:std_logic_vector(11 downto 0);begin if(reset='1') then km_reg:="000000000000" elsif(clkout'event and clkout='1') then -km_reg(3 downto 0)对应里程十分位 if(km_reg(3 downto 0)="1001")then

9、km_reg:=km_reg+"0111" -十分位向个位的进位处理 else km_reg(3 downto 0):=km_reg(3 downto 0)+"0001" end if; if(km_reg(7 downto 4)="1010")then km_reg:=km_reg+"01100000" -个位向十位的进位处理 end if;end if;kmcnt1<=km_reg(3 downto 0);kmcnt2<=km_reg(7 downto 4);kmcnt3<=km_reg(11

10、 downto 8);end process;end behavior;3. 计时模块:在汽车启动时,当遇到顾客等人时,出租车采用计时收费的方式。通过对速度信号sp的判断决定是否开始记录时间。当stop=1时,不计费,当stop=0,sp=0时,开始按时间计费,当时间达到足够长时则产生Timecount脉冲,并重新计时。一个Timecount脉冲相当于等待的时间达到了时间计费的长度。使用1kHz的系统时钟,计算20s计数值为20000。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity

11、Taxi_part3 is port(clk,reset,start,stop:in std_logic; sp:in std_logic_vector(2 downto 0); timecount:out std_logic);end Taxi_part3;architecture behavior of Taxi_part3 isbegin process(reset,clk,sp,stop,start) type state_type is(t0,t1,t2); variable t_state:state_type; variable waittime: integer range 0

12、 to 1000; begin if(reset='1') then t_state:=t0; elsif(clk'event and clk='1')then case t_state is when t0 => waittime:=0;timecount<='0' if(start='1') then t_state:=t1; else t_state:=t0; end if; when t1 => if(sp="000") then t_state:=t2; else waitt

13、ime:=0;t_state:=t1; end if; when t2 => waittime:=waittime+1; timecount<='0' if(waittime=1000) then timecount<='1' -20s,即1000个clk,产生一个时间计费脉冲 waittime:=0; elsif(stop='1') then t_state:=t0; elsif(sp="000") then t_state:=t2; else timecount<='0't_stat

14、e:=t1; end if; end case;end if;end process;end behavior;4.计费模块:计费模块由两个线程组成。其中一个进程根据条件对Enable和Price赋值:当记录的距离达到3千米后Enable变为1,开始进行每千米收费,当总费用大于40元后,则单价Price由原来的2元/千米变为4元/千米;第二个进程在每个时钟周期判断Timecount和Clkcount的值。当其为1时,则在总费用上加上相应的费用。VHDL语言:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.

15、all;entity Taxi_part4 is port(clk,reset,timecount,clkout:in std_logic; kmcnt2:in std_logic_vector(3 downto 0); kmcnt3:in std_logic_vector(3 downto 0); count1:out std_logic_vector(3 downto 0); count2:out std_logic_vector(3 downto 0); count3:out std_logic_vector(3 downto 0);end Taxi_part4;architecture

16、 behavior of Taxi_part4 issignal cash:std_logic_vector(11 downto 0);signal Price:std_logic_vector(3 downto 0);signal Enable: std_logic;begin process(cash,kmcnt2) begin if(cash>="000001000000") then price<="0100" else Price<="0010" end if; if(kmcnt2>="00

17、11")or(kmcnt3>="0001") then Enable<='1' else Enable<='0' end if; end process;kmmoney2:process(reset,clkout,clk,Enable,Price,kmcnt2)variable reg2:std_logic_vector(11 downto 0);variable clkout_cnt:integer range 0 to 10;begin if(reset='1') then cash<=&

18、quot;000000000111" -起步费用设为7元 elsif(clk'event and clk='1') then if(timecount='1') then -判断是否需要时间计费,每20s加一元 reg2:=cash; if(reg2(3 downto 0)+"0001">"1001") then reg2(7 downto 0):=reg2(7 downto 0)+"00000111" if(reg2(7 downto 4)>"1001"

19、;) then cash <=reg2+"000001100000" else cash<=reg2; end if; else cash<=reg2+"0001" end if;elsif(clkout='1' and Enable='1')then -里程计费 if(clkout_cnt=9) then clkout_cnt:=0; reg2:=cash; if("0000"&reg2(3 downto 0)+price(3 downto 0)>"00001

20、001") then reg2(7 downto 0):=reg2(7 downto 0)+"00000110"+price; if(reg2(7 downto 4)>"1001") then cash<=reg2+"000001100000" else cash<=reg2; end if; else cash<=reg2+price; end if; else clkout_cnt:=clkout_cnt+1; end if;end if;end if;end process;count1<

21、=cash(3 downto 0); -总费用的个位count2<=cash(7 downto 4); -总费用的十位count3<=cash(11 downto 8); -总费用的百位end behavior;5. 显示模块:时间的显示需要用到全部8个数码管,由于实验板上的所有数码管均对应同一组7段码,因此,需要采用动态扫描的方式实现时间显示。VHDL语言:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity display isport(clk:in std_logic;

22、kmcount1:in std_logic_vector(3 downto 0); kmcount2:in std_logic_vector(3 downto 0); kmcount3:in std_logic_vector(3 downto 0); count1:in std_logic_vector(3 downto 0); count2:in std_logic_vector(3 downto 0); count3:in std_logic_vector(3 downto 0); clkout:out std_logic_vector(6 downto 0); sel:buffer st

23、d_logic_vector(2 downto 0);end display;architecture dtsm of display is signal key:std_logic_vector(3 downto 0); begin process(clk) variable dount:std_logic_vector(2 downto 0):="000" begin if rising_edge(clk) then if dount="111" then dount:="000" else dount:=dount+1; end

24、 if; end if; sel<=dount; end process; process(sel) begin case sel is when "000"=>key<=kmcount3(3 downto 0 ); when "001"=>key<=kmcount2(3 downto 0); when "011"=>key<=kmcount1(3 downto 0); when "010"=>key<="1011" when "101"=>key<=count3(3 downto 0); when "110"=>key<=count2(3 downto 0); when "111"=>key<=count1(3 downto 0); when "100"=>key<="1010" when others=&g

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论