基于verilog HDL的出租车计费器
推荐-基于FPGA出租车计费系统的设计 精品

南京大学金陵学院本科毕业院系信息科学与工程系专业电子信息科学与技术题目基于FPGA出租车计费系统的设计提交日期20XX年6月3 日摘要通过出租车计费系统的设计,详细介绍了如何使用硬件描述语言Verilog HDL设计复杂逻辑电路的步骤和过程,以及应用美国ALTERA公司的Quartus II 9.0软件进行系统设计、仿真和下载实现的方法。
通过设计,可以看到在EDA平台上用CPLD器件构成该数字系统的设计思想和实现过程。
论述了计费模块、时钟模块、动态显示模块、计费形式判断模块、控制模块等的设计方法和技巧。
关键词:CPLD/FPGA; 电子自动化设计; Verilog HDL硬件描述语言; 出租车计费器; Quartus II 9.0软件ABSTRACTTaxi billing system through the design, details how to use the hardwaredes-cription language Verilog HDL design plexity and the process logic and the applicatio-n of the U.S. pany's Quartus II 9.0 ALTERA software system design, simulation, anddownload the realization of the method. By design, you can see in the EDA platform usi-ng CPLD devices constitute the digital system design and implementation process. Discuss-es the billing module, clock module, dynamic display module, billing forms to judge mod-ule, control module and other design methods and techniques.Keywords: CPLD/FPGA; EDA; Verilog HDL; Taxi Billing Machine; Quartus II 9.0目录第一章引言随着科技日新月异的发展,科技带来的改变无处不在。
Verilog出租车计费器课程设计

目录引言 (1)1、设计内容 (1)2、设计原理 (1)3、CPLD简介 (2)3.1、CPLD的基本结构 (2)3.2、CPLD 的特点 (3)4、系统功能模块设计 (4)4.1、计算里程和车费模块 (4)4.3、按键扫描模块 (17)4.4结构描述实现出租车计费器电路系统设计 (20)4.5、仿真电路图 (21)5、硬件实现 (22)5.1、引脚锁定 (22)5.2、编程下载 (23)6总结与体会 (23)7、参考文献 (23)附录:电气信息学院课程设计评分表 (24)引言Verilog HDL 是一种硬件描述语言(HDL:Hardware Discription Language ),是一种用文本形式来描述数字系统硬件的结构和行为的语言,用它可以表示逻辑电路图、逻辑表达式,还可以表示数字逻辑系统所完成的逻辑功能。
Verilog HDL和VHDL是目前世界上最流行的两种硬件描述语言,都是在20 世纪80年代中期开发出来的。
现在,随着系统级FPGA以及片上系统的出现,软硬件协同设计和系统设计变得越来越重要。
传统意义上的硬件设计越来越倾向于与系统设计和软件设计相结合。
随着出租车行业的发展,对出租车计费器的要求也越来越高,用户不仅要求计费器性能稳定计费准确,而且要求在乘坐出租车时,显示起步价、行车里程二部分,由自动计费器自动记录。
安装在与汽车轮相连接的传感器在汽车行进时向自动计费器发送脉冲信号,在一定的公里数内,按起步价计费;超过这一里程后,自动计费器按里程计费;超过一定费用后,则则增加里程费用;如果停车等候,则不收费。
本文以Altera公司的DE2开发板为中心,Quartus n软件作为开发平台,使用VerilogHDL语言编程,设计了一个出租车计费的计费器模型。
在程序描述的过程中,用了行为描述方式和结构描述方式二种描述方式对计费器进行描述。
该计费器能动态扫描电路,将车费和路显示出来,各有两位小数。
基于Verilog_HDL设计的出租车计价器(DOC)

华北水利水电大学EDA课程设计题目:出租车计价器专业:通信工程年级:2011级学生:李高飞学号:201114715指导教师:司孝平完成日期: 2013 年 12月 27日摘要:本文介绍了一种采用可编程逻辑器件(FPGA/CPLD)进行出租车计费器的设计思想以及实现方法。
本设计实现了出租车计费器所需的一些基本功能,计费金额包括起步价、里程计费、等待计时计费等。
该设计采用模块化设计,在Quartus II9.0软件平台下,采用Verilog HDL 硬件描述语言描述和模拟仿真了分频模块、计程模块、计费模块、计时模块,译码以及动态扫描显示模块,完成了出租车计费器仿真设计和硬件电路的实现。
关键词:FPGA,出租车计费器,Quartus,Verilog HDLAbstract:This article describes the design ideas and methods of the taximeter, through the programmable logic device (FPGA/CPLD).The design of a taximeter to achieve the required basic functions,The total of billing included the starting price, metered, and wait for time billing.Through the Quartus II 9.0 Software Platform,Using Verilog HDL language completed the description and simulation of frequency module, the meter module, Billing module, timing modules, decoding, dynamic scanning display module. IT It has completed the taxi meter simulation and the hardware circuit.Keywords:FPGA, Taximeter, Quartus, Verilog HDL目录1.前言 (1)2.总体方案设计 (2)2.1 设计要求 (2)2.2 方案论证与选择 (2)2.3 设计思想及原理 (3)3.单元模块设计 (5)3.1 分频模块 (5)3.1.1 计数器分频模块 (5)3.1.2 计数器分频模块仿真结果 (5)3.1.3 数码管分频模块 (6)3.2 计程模块 (6)3.2.1 计程模块电路 (6)3.2.2 计程模块仿真结果 (7)3.3 计时模块 (7)3.3.1 计时模块电路 (7)3.3.2 计时模块的仿真结果 (7)3.4 控制模块 (8)3.4.1 控制模块电路 (8)3.4.2 计时模块的仿真结果 (9)3.5 计费模块 (10)3.5.1 控制模块电路 (10)3.5.2 计费模块的仿真结果 (10)2.6 数码管显示模块 (11)4.整体顶层模块设计 (12)4.1 整体顶层模块电路 (12)5.系统功能仿真及调试 (13)5.1 系统仿真及调试 (13)6.总结与体会 (16)致谢 (17)参考文献 (17)附录A: 单元模块Verilog HDL源代码 (18)A.1 计数器的分频模块VerilogHDL源代码 (18)A.2数码管的分频模块VerilogHDL源代码 (18)A.3 计程模块VerilogHDL源代码 (19)A.4 计时模块VerilogHDL源代码 (20)A.5 控制模块VerilogHDL源代码 (21)A.6 计费模块VerilogHDL源代码 (21)A.7 数码管显示模块VerilogHDL源代码 (21)A.8整体顶层模块VerilogHDL源代码 (23)附录B: 整体顶层电路图 (24)2.总体方案设计2.1 设计要求该出租车计价器实现功能:1、行程≤4公里,且等待累计时间≤2分钟,起步费为8.0元。
基于Verilog HDL的出租车计费器设计

李明洪基于Verilog HDL的出租车计费器设计基于Verilog HDL的出租车计费器设计学生姓名:李明洪指导老师:肖红光摘要本次课程设计主要是基于FPGA芯片,使用硬件描述语言Veriloh HDL,采用“自顶向下”的设计方法,编写一个出租车计费器芯片,并使用Max+Plus II软件仿真平台。
本文主要描述了出租车计费器的设计思路与模块划分。
把出租车计费器划分为五大模块,共同实现了出租车计费以及预置和模拟汽车启动、停止、暂停等功能,并动态扫描显示车费数目。
最后,使用Max+Plus II仿真平台对每个模块和主程序分别进行了仿真,并对仿真出来的波形作了分析。
关键词出租车计费;Verilog HDL;Max+Plus II;仿真The design of taxi meter based onVerilog HDLAbstract The course design is mainly based on FPGA chip, the use of hardware description language Veriloh HDL, using "top down " design method, the preparation of a taxi meter chip, and use the Max + Plus II software simulation platform. This paper describes the design idea of the taxi meter and module division. The taxi meter is divided into five modules together to achieve a taxi and analog auto billing and pre-start, stop, pause function, and dynamic scan showed the number of fare. Finally, using Max + Plus II simulation platform and the main program for each module were simulated, and the simulation from an analysis of the waveform.Keywords Taxi charges;Verilog HDL;Max+Plus II;Simulation1 引言随着中国城市化的快速发展,人们出行的选择也会越来越多样化,但是出租车作为一种重要的交通工具,也越来越多的被人们所选择,虽然在大中城市,出租车已经相当普及,但是在一些小的城市,出租车行业也因为城市化进程的加快而快速发展。
基于VHDL_的出租车计费器的设计

基于VHDL 的出租车计费器的设计目前以硬件描述语言(Verilog 或VHDL)所完成的电路设计,可以经过简单的综合与布局,快速的烧录至FPGA 上进行测试,是现代IC 设计验证的技术主流。
这些可编辑元件可以被用来实现一些基本的逻辑门电路(比如AND、OR、XOR、NOT)或者更复杂一些的组合功能比如解码器或数学方程式。
在大多数的FPGA里面,这些可编辑的元件里也包含记忆元件例如触发器(Flip-flop)或者其他更加完整的记忆块。
系统设计师可以根据需要通过可编辑的连接把FPGA内部的逻辑块连接起来,就好像一个电路试验板被放在了一个芯片里。
一个出厂后的成品FPGA的逻辑块和连接可以按照设计者而改变,所以FPGA可以完成所需要的逻辑功能。
本设计是一种采用FPGA芯片进行出租车计费器,主要分为分频模块、计量模块、计费模块、控制模块等模块,利用FPGA的可编程性,简洁又多变的设计方法,缩短了研发周期。
主要采用了FPGA芯片,使用VHDL语言进行编程,使其具有了更强的移植性,更加利于产品的升级。
一、设计任务与要求(1)、能够实现计费功能费用的计算是按行驶里程收费,设出租车的起步价是5.00元,当里程小于3km里时,按起步价收费;当里程大于3km时每公里按1.3元计费。
等待累计时间超过2min,按每分钟1.5元计费。
所以总费用按下式计算:总费用=起步价+(里程-3km)*里程单价+等候时间*等候单价(2)、能够实现显示功能●显示汽车行驶里程:用四位数字显示,显示方式为“XXXX”,单价为km。
计程范围为0~99km,计程分辨率为1km。
●显示等候时间:用两位数字显示分钟,显示方式为“XX”。
计时范围为0~59min,计时分辨率为1min。
●显示总费用:用四位数字显示,显示方式为“XXX.X”,单位为元。
计价范围为999.9元,计价分辨率为0.1元。
二、设计原理根据设计要求,系统的输入信号clk,计价开始信号Start,等待信号Stop,里程脉冲信号fin。
基于VHDL语言的出租车计价器

(基于VHDL语言)出租车计价器自己做的大作业经过测试完全通过,不过里面的时间脉冲以及里程脉冲的时钟信号都比较难搞,不过可以修改其中的值来满足你们提供的时钟脉冲题目要求:(1)行程3公里内(包括3公里),且等待累计时间2分钟内(包括2分钟),起步费为10元;(2)3公里外(不包括3公里)以每公里2元,等待累计时间2分钟外(不包括2分钟)以每分钟以1.0元计费;(3)能显示行驶公里数、等待累计时间和最后的总费用;(4)本计费器的显示范围为0~99元,计价分辨率为1元;计程器显示范围为0~99公里,分辨率为1公里;计时器的显示范围是分钟的显示范围是0—99,分辨率为1分钟。
秒的显示范围是0—59。
分辨率为1秒本出租车计价器的设计共分4个模块:判断模块、时间模块、里程模块、计费模块。
总的设计图如图1所示:计价开始控制判断模块library ieee;use ieee.std_logic_1164.all;--entity judge isport(sclk,sta,lclk: in std_logic;dge: out std_logic);end;architecture beh of judge isbeginprocess(sta,lclk,sclk)variable a: integer range 0 to 64;beginif sta='1' thenif lclk'event and lclk='1' thena:=a+1;end if;if sclk'event and sclk='1' thenif a=0 thendge<='0';--shijian processelsedge<='1';--licheng processend if;end if;if sclk='1' thena:=0;end if;elsedge<='Z';end if;end process;end;时间模块library ieee;use ieee.std_logic_1164.all;--entity time_count isport(sta,sclk,dge: in std_logic;t_count: out std_logic;minge: out integer range 0 to 10;minshi: out integer range 0 to 10); end;--architecture beh of time_count is beginprocess(sta,sclk,dge)variable count: integer range 0 to 60; variable ge: integer range 0 to 10; variable shi: integer range 0 to 10; variable t_c: std_logic;beginif sta='1' thenif dge='0' thenif sclk'event and sclk='1' then count:=count+1;if count=1 thent_c:='0';end if;if count=60 thencount:=0;ge:=ge+1;if ge>2 thent_c:='1';elsif ge>0 thent_c:='1';end if;if ge=10 thenge:=0;shi:=shi+1;if shi=10 thenshi:=0;end if;end if;end if;end if;end if;elsege:=0;shi:=0;t_c:='0';end if;minge<=ge;minshi<=shi;t_count<=t_c;end process;end;里程模块library ieee;use ieee.std_logic_1164.all; --entity time_count isport(sta,sclk,dge: in std_logic;t_count: out std_logic;minge: out integer range 0 to 10;minshi: out integer range 0 to 10); end;--architecture beh of time_count is beginprocess(sta,sclk,dge)variable count: integer range 0 to 60; variable ge: integer range 0 to 10; variable shi: integer range 0 to 10; variable t_c: std_logic;beginif sta='1' thenif dge='0' thenif sclk'event and sclk='1' then count:=count+1;if count=1 thent_c:='0';end if;if count=60 thencount:=0;ge:=ge+1;if ge>2 thent_c:='1';elsif ge>0 thent_c:='1';end if;if ge=10 thenge:=0;shi:=shi+1;if shi=10 thenshi:=0;end if;end if;end if;end if;end if;elsege:=0;shi:=0;t_c:='0';end if;minge<=ge;minshi<=shi;t_count<=t_c;end process;end;计费模块library ieee;use ieee.std_logic_1164.all;--entity price_count isport(sta,t_count,d_count: in std_logic;mge,mshi: out integer range 0 to 10); end;--architecture beh of price_count issignal t_ge,t_shi: integer range 0 to 10; signal d_ge,d_shi: integer range 0 to 10; begin--process(sta,t_count)variable tshi: integer range 0 to 10:=1; variable tge: integer range 0 to 10;beginif sta='1' thenif t_count'event and t_count='1' then tge:=tge+1;if tge=10 thentge:=0;tshi:=tshi+1;if tshi=10 thentshi:=0;end if;end if;end if;elsetge:=0;tshi:=1;end if;t_ge<=tge;t_shi<=tshi;end process;--process(sta,d_count)variable dge,dshi: integer range 0 to 10; beginif sta='1' thenif d_count'event and d_count='1' then dge:=dge+2;if dge=10 thendge:=0;dshi:=dshi+1;if dshi=10 thendshi:=0;end if;end if;end if;elsedge:=0;dshi:=0;end if;d_ge<=dge;d_shi<=dshi;end process;--process(d_ge,d_shi,t_ge,t_shi) variable cge: integer range 0 to 1; variable ge,shi:integer range 0 to 10; beginge:=d_ge+t_ge;if ge>=10 thenge:=ge-10;cge:=1;elsecge:=0;end if;shi:=d_shi+t_shi+cge;mge<=ge;mshi<=shi;end process;end;显示模块library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity display isport(CLK:in std_logic;sminge,sminshi: in integer range 0 to 10;skmge,skmshi: in integer range 0 to 10;smge,smshi: in integer range 0 to 10;weixuan:OUT std_logic_vector(2 downto 0);seg:out std_logic_vector(7 downto 0)); end;architecture one of display issignal cnt1:std_logic_vector(22 downto 0);signal S:std_logic_vector(2 downto 0);signal sel:std_logic_vector(2 downto 0);beginprocess(CLK)beginif CLK'event and CLK='1' THEN cnt1<=cnt1+1;end if;END PROCESS;S<=cnt1(5 downto 3);--300hzsel<="000" when S="000" else"001" when S="001" else"010" when S="010" else"011" when S="011" else"100" when S="100" else"101" when S="101" else"110" when S="110" else"111" when S="111" else"ZZZ";weixuan<=sel;process(sel,sminshi,sminge,skmshi,skmge,smshi,smge) variable num:integer range 0 to 10;begincase sel ISwhen"000"=>num:=sminge;when"001"=>num:=sminshi;when"011"=>num:=skmge;when"100"=>num:=skmshi;when"110"=>num:=smge;when"111"=>num:=smshi;when others=>num:=0;end case;case num ISwhen 0=>seg<="00111111";when 1=>seg<="00000110";when 2=>seg<="01011011";when 3=>seg<="01001111";when 4=>seg<="01100110";when 5=>seg<="01101101";when 6=>seg<="01111101";when 7=>seg<="00000111";when 8=>seg<="01111111";when 9=>seg<="01101111";when others=>seg<="00000000";end case;end process;end one;元件例化模块library ieee;use ieee.std_logic_1164.all;--entity comp isport(sclk,lclk,sta,dclk: in std_logic;weixuan:OUT std_logic_vector(2 downto 0);seg:out std_logic_vector(7 downto 0)); end;--architecture beh of comp is--component judge isport(sclk,sta,lclk: in std_logic;dge: out std_logic);end component;--component time_count isport(sta,sclk,dge: in std_logic;t_count: out std_logic;minge: out integer range 0 to 10;minshi: out integer range 0 to 10);end component;--component distance_count isport( sta,lclk,dge: in std_logic;kmge,kmshi: out integer range 0 to 10;d_count: out std_logic);end component;--component price_count isport(sta,t_count,d_count: in std_logic;mge,mshi: out integer range 0 to 10);end component;--component display isport(CLK:in std_logic;sminge,sminshi: in integer range 0 to 10;skmge,skmshi: in integer range 0 to 10;smge,smshi: in integer range 0 to 10;weixuan:OUT std_logic_vector(2 downto 0);seg:out std_logic_vector(7 downto 0));end component;--signal w,x,y: std_logic;signal time_ge,time_shi:integer range 0 to 10;signal pri_ge,pri_shi:integer range 0 to 10;signal dis_ge,dis_shi:integer range 0 to 10;--beginU1: judge port map(sta=>sta,sclk=>sclk,lclk=>lclk,dge=>w);U2: time_count port map(sta=>sta,sclk=>sclk,dge=>w,t_count=>x,minge=>time_ge,minshi=>time_shi);U3: distance_count port map(sta=>sta,lclk=>lclk,dge=>w,d_count=>y,kmge=>dis_ge,kmshi=>dis_shi);U4: price_count port map(sta=>sta,t_count=>x,d_count=>y,mge=>pri_ge,mshi=>pri_shi);U5: display port map(dclk,time_ge,time_shi,dis_ge,dis_shi,pri_ge,pri_shi,weixuan,seg);end;。
基于VerilogHDL的出租车计费器的实现

基于VerilogHDL的出租车计费器的实现摘要本文介绍了出租车计费器系统的组成及工作原理,采用自顶而下的设计方法,设计了一种基于硬件描述语言的出租车自动计费器,在cpld芯片epm3256atc144-7上实现了其功能,并论述了显示模块、主控模块、计费模块等实现方法。
关键词 cpld;硬件描述语言;出租车计费器中图分类号u463 文献标识码a 文章编号1674-6708(2010)21-0137-02随着cpld/fpga等数字可编程器件的出现,他们可以解决传统电子设计不能完成的任务。
利用cpld来实现出租车计费器,可行性很高,而且电路简单,大大减少外围器件,可以用软件完全仿真,灵活度高,可以设计一些复杂的系统,而且编好的系统可以在不同的fpga或cpld芯片上通用。
1 mars-eda-s实验主板本设计采用了 mars-eda-s实验主板,其核心芯片是altera公司的 epm3256atc144-7芯片。
板上具有如下资源:主芯片:epm3256atc144-7,有源晶振:40mhz;复位芯片:stc811,支持复位手动输入,支持jtag下载模式。
核心板可以作为原型板,用户可以根据自己需要自行扩展。
2 出租车计费器系统设计概述基于cpld设计的出租车自动计费器,计费包括起步价、行车里程计费、等待时间计费3部分,用三位数码管显示总金额,最大值为99.9元。
起步价为5.0元,3km之内按起步价计费,超过3km的,每1km增加1元,等待时间单价为每分钟0.1元。
用两位数码管显示总里程,最大值为99km,用两位数码管等待时间,最大值为99min。
系统框图如图1所示。
2.1 分频模块由于epm3256atc144-7芯片的时钟频率为40mhz,而主控模块所用频率为1hz,必须经过分频才能使得epm3256atc144-7芯片与程序匹配。
//分频/*信号定义:clk_in:输入时钟信号:大小为40mhz;clk:输出时钟信号;大小为1hz;*/module clock_send(clk_in,clk);input clk_in;output clk;reg clock;reg clk;reg[24:0] cnt;always@(posedge clk_in)begincnt<=cnt+1;if(cnt==25’d1*******)begincnt<=0;clock=~clock;endclk<=clock;endendmodule2.2 主控模块在主控模块中,设置拨码开关m控制led灯使系统显示出租车的当前状态,当led灯亮时开始计程,计费显示起步价5元,3km之内为起步价,即300个clk之内为起步价,以后每1km增加1元,即每10个clk增加0.1元;led灯灭时开始记等待时间,每分钟计费增加0.1元,即每60个clk增加0.1元。
基于VerilogHDL出租车计费系统的研制

第23卷第10期 2004年10月实验室研究与探索R ESEA RCH AND EXPLORA T I ON I N LABORA TOR YV o l .23N o.10 O ct .2004 基于V erilog HDL 出租车计费系统的研制高 健1, 刘向峰1, 赖 谨2, 戴路红1(南京大学1.电子科学与工程系;2.计算中心,江苏南京210093)摘 要:以上海地区的出租车计费器为例,利用V erilog HDL 语言设计了出租车计费器,使其具有时间显示、计费以及模拟出租车启动、停止、复位等功能,并设置了动态扫描电路显示车费和对应时间,显示了硬件描述语言V erilog 2HDL 设计数字逻辑电路的优越性。
源程序经M A X +PLU S 软件调试、优化,下载到EPF 10K 10TC 14423芯片中,可应用于实际的出租车收费系统。
关键词:V erilog HDL ;电子自动化设计;硬件描述语言;M A X +PLU S 中图分类号:T P 39文献标识码:B 文章编号:100627167(2004)1020049204D e s ign of Ta xi Accounting S ys tem B a s e d on V e rilog HDLGA O J ian 1, L IU X iang 2f eng 1, L A I J in 2, DA I L u 2hong1(1.D ep t .of E lectron ic Science and Eng .; p u ter Cen ter ,N an jing U n iv .,N an jing 210093,Ch ina )Abstract :T he tax i accoun ting system referred to that u sed in Shanghai w as designed by V erilog HDL ,w ith functi on s of ti m e disp lay ,accoun t ,and si m u lati on of start ,stop ,p au se and so on .In additi on ,the dynam icscann ing circu it w as designed to disp lay the tariff num ber .T he design of th is system show s the advan tage of V erilog HDL as a hardw are descri p ti on language .A fter debugging and op ti m izing the sou rce p rogram by the softw are M A X +PLU S of A ltera Com p any ,the p rogram can be u sed in the real tax i accoun ting system by dow n loading to the EPK 10K 10TC 14423ch i p .Key words :V erilog HDL ;EDA ;hardw are descri p ti on language (HDL );M A X +PLU S收稿日期:2003209223;修改稿日期:2004206207第一作者简介:高健(19762),男,助教。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
《EDA技术与应用》实训报告学号姓名指导教师:江国强杨艺敏2011 年4 月28 日实训题目:出租车计费器1.系统设计1.1 设计要求1.1.1 设计任务设计并制作一台出租车计费器。
1.1.2 技术要求①用EDA实训仪的I/O设备和PLD芯片实现出租车计费器的设计。
②出租车起步开始计程和计费,计程系统按实际公里数计程,计费系统首先显示起步价(如7.0),车行驶2km以内,只收起步价7元。
③出租车行驶超过2km后,按每公里1.6元在7.0元的基础上增加。
④出租车行驶超过10km后(或超过20元路费),每公里加收50%的车费,即车费变为每公里2.4元。
⑤出租车达到目的地后,(用一个按钮)计程和计费数据清零,为下一次计费开始。
1.2 方案比较最初计费模块选择乘法,但占用资源过多,所以选择分段加法来解决1.3 方案论证1.3.1 总体思路整个系统主要由计程兼计费模块组成,另外添加计时器和流水灯模块作为附加功能,最后由选择模块选择输出费用或时间,分频模块作为路程模拟输入。
1.3.2 设计方案分频器将实训仪的时钟转换成1s或0.1s的脉冲模拟行进一公里,将脉冲输入计程兼计费模块进行路程累加和计费,同时输出路程数和费用。
流水灯则按行进路程进行亮灭,附加的时钟功能可以查看时间。
最后由选择模块进行费用和时间间的切换。
2.各个模块程序的设计①分频模块:模拟车辆行进,分1s/km档和0.1s/km档module fpq(clk,cout,k1);input clk,k1;reg [24:0] q;output reg cout;always @(posedge clk)begincase(k1)0: begin q=q+1;if (q==20000000-1)begin cout=1;q=0;endelse cout=0;end1: begin q=q+1 ;if (q==2000000-1)begin cout=1;q=0;endelse cout=0;endendcaseendendmodule②计程兼计费模块:jsq99累计路程dejfq按规则计费,同时附带输出显示该模块又由两个小模块组成:jsq99:路程显示module jsq99(clr,clk,q,cout,k2);input clk,clr,k2;output reg[7:0]q;output reg cout;always @(posedge clk or negedge clr)beginif(~clr) q = 0;else beginif(k2==0)beginif(q=='h99) q = 0;else q = q+1;if(q[3:0]=='ha)beginq[3:0] = 0;q[7:4] = q[7:4]+1;endif(q==0) cout = 1;else cout = 0;endendendendmoduledejfq:计费module dejfq(clk,clrn,q,k2);input clk,k2;input clrn;output reg[11:0] q;reg[3:0] c;always @(posedge clk or negedge clrn)beginif(~clrn) begin c=0;q=0;endelse beginif(k2==0)beginif(c<14) c=c+1;if(c<=2) q[7:4]=7;else if(c<=10)beginq[3:0]=q[3:0]+6;q[7:4]=q[7:4]+1;if(q[3:0]>9)begin q[3:0]=q[3:0]-10;q[7:4]=q[7:4]+1;endif(q[7:4]>9)begin q[7:4]=q[7:4]-10;q[11:8]=q[11:8]+1; endendelse if(c>10)beginq[3:0]=q[3:0]+4;q[7:4]=q[7:4]+2;if(q[3:0]>9)begin q[3:0]=q[3:0]-10;q[7:4]=q[7:4]+1;endif(q[7:4]>9)begin q[7:4]=q[7:4]-10;q[11:8]=q[11:8]+1;endendend if(c>14) c=11;endendendmodule③选择器:选择显示时间或费用,拨下拨码开关显示路程和费用,拨上显示时钟。
module xzq(k,qm,qf,qs,q,q1,sum);input k;input[7:0] qm,qf,qs,q1;input[11:0] sum;output reg [23:0] q;alwaysbeginif (k==0) beginq[7:0]=q1;q[11:8]=0;q[23:12]=sum;endelse q[23:0]={qs,qf,qm};endendmodule④时间模块:24小时时钟,可以显示时分秒,可以校准。
该模块又由几个小模块组成module clkgen(clk,cout);//两千万分频器input clk;reg [24:0] q;output reg cout;always @(posedge clk)beginif (q==20000000-1) q=0;else q=q+1;if (q==20000000-1) cout=1;else cout=0;endendmodulemodule cnt60(clk,clrn,j,q,cout);//60进制计数器input clk,clrn,j;output reg[7:0] q;output reg cout;always @(posedge clk^j or negedge clrn)beginif (~clrn) q=0;else beginif (q=='h59) q=0;else q=q+1;if (q[3:0]=='ha) beginq[3:0]=0; q[7:4]=q[7:4]+1; endif (q=='h59) cout=1;else cout=0;endendendmodulemodule cnt24(clk,clrn,j,q,cout);//24进制计数器input clk,clrn,j;output reg[7:0] q;output reg cout;always @(posedge clk^j or negedge clrn)beginif (~clrn) q=0;else beginif (q=='h23) q=0;else q=q+1;if (q[3:0]=='ha) beginq[3:0]=0; q[7:4]=q[7:4]+1; endif (q=='h23) cout=1;else cout=0;endendendmodule⑤流水灯模块:通过亮灭提示行进状态module lsd(clk,q,k2);input clk,k2;output reg[11:0] q;reg [7:0] d;initial q=1;always @(posedge clk)if(k2==0)beginif(d==23) d=0;else d=d+1;if(d<=11)beginif(q==12'b111111111111) q=12'b0111111111111;else q=q<<1;q=q+1;endif(d>11)beginif(q==12'b000000000000) q=1;else q=q<<1;endendendmodule3.制作与调试过程①新建工程,输入程序,生成模块②各模块波形模拟③进行各模块间连线④引脚锁定⑤下载硬件验证调试:最初计费时选择乘法,但占用资源过多,而且在数码管显示时出现16进制,所以转换成加法,成功解决问题。
4.结论通过硬件验证,我的系统已经达到设计要求,同时附加了时钟和流水灯显示两个小功能,可以通过拨码开关选择显示时间和费用。
但由于是初次实践,所以选用了以前上课的模块,导致程序过于臃肿,总体来说还是可以的。
5.实训心得体会为期两周的实训结束了,这是我首次将EDA课程学习到的知识运用到实际当中。
在实训过程中我遇到许多的困难,特别是将16进制转换成0-9的16进制输出到数码管这个地方,困扰了我数天的时间,通过查找资料我采用将乘法转换成加法的方法避开了问题,同时也降低了资源占用率,我在这一点上明白了,想要得到一个优异的程序,我们必须善于发现问题改正问题,同时要有一颗持之以恒的心。
虽然在实训中遇到了一些我们不能完成的问题,但也能在问题中提高很多专业知识,当然也离不开老师的悉心教导。
6.参考文献①《数字逻辑电路基础》,江国强,电子工业出版社②《EDA技术与应用》,江国强,电子工业出版社附录:①仿真波形图(部分模块)路程兼计费模块:②程序清单module fpq(clk,cout,k1);//分频模块input clk,k1;reg [24:0] q;output reg cout;always @(posedge clk)begincase(k1)0: begin q=q+1;if (q==20000000-1)begin cout=1;q=0;endelse cout=0;end1: begin q=q+1 ;if (q==2000000-1)begin cout=1;q=0;endelse cout=0;endendcaseendendmodulemodule jsq99(clr,clk,q,cout,k2);//计程input clk,clr,k2;output reg[7:0]q;output reg cout;always @(posedge clk or negedge clr) beginif(~clr) q = 0;else beginif(k2==0)beginif(q=='h99) q = 0;else q = q+1;if(q[3:0]=='ha)beginq[3:0] = 0;q[7:4] = q[7:4]+1;endif(q==0) cout = 1;else cout = 0;endendendendmodulemodule dejfq(clk,clrn,q,k2);//计费input clk,k2;input clrn;output reg[11:0] q;reg[3:0] c;always @(posedge clk )beginif(~clrn) begin c=0;q=0;endif(k2==0)beginif(c<14) c=c+1;if(c<=2) q[7:4]=7;else if(c<=10) begin q[3:0]=q[3:0]+6;q[7:4]=q[7:4]+1;if(q[3:0]>9)begin q[3:0]=q[3:0]-10;q[7:4]=q[7:4]+1;endif(q[7:4]>9)begin q[7:4]=q[7:4]-10;q[11:8]=q[11:8]+1; endendelse if(c>10) begin q[3:0]=q[3:0]+4;q[7:4]=q[7:4]+2;if(q[3:0]>9)begin q[3:0]=q[3:0]-10;q[7:4]=q[7:4]+1;endif(q[7:4]>9)begin q[7:4]=q[7:4]-10;q[11:8]=q[11:8]+1;endendif(c>14) c=1;endendendmodulemodule clkgen(clk,cout);//两千万分频器input clk;reg [24:0] q;output reg cout;always @(posedge clk)beginif (q==20000000-1) q=0;else q=q+1;if (q==20000000-1) cout=1;else cout=0;endendmodulemodule cnt60(clk,clrn,j,q,cout);//60进制计数器input clk,clrn,j;output reg[7:0] q;output reg cout;always @(posedge clk^j or negedge clrn)beginif (~clrn) q=0;else beginif (q=='h59) q=0;else q=q+1;if (q[3:0]=='ha) beginq[3:0]=0; q[7:4]=q[7:4]+1; endif (q=='h59) cout=1;else cout=0;endendendmodulemodule cnt24(clk,clrn,j,q,cout);//24进制计数器input clk,clrn,j;output reg[7:0] q;output reg cout;always @(posedge clk^j or negedge clrn)beginif (~clrn) q=0;else beginif (q=='h23) q=0;else q=q+1;if (q[3:0]=='ha) beginq[3:0]=0; q[7:4]=q[7:4]+1; endif (q=='h23) cout=1;else cout=0;endendendmodulemodule xzq(k,qm,qf,qs,q,q1,sum);//选择器input k;input[7:0] qm,qf,qs,q1;input[11:0] sum;output reg [23:0] q;alwaysbeginif (k==0) beginq[7:0]=q1;q[11:8]=0;q[23:12]=sum;endelse q[23:0]={qs,qf,qm};endendmodulemodule lsd(clk,q,k2);//流水灯input clk,k2;output reg[11:0] q;reg [7:0] d;initial q=1;always @(posedge clk)if(k2==0)beginif(d==23) d=0;else d=d+1;if(d<=11)beginif(q==12'b111111111111) q=12'b0111111111111; else q=q<<1;q=q+1;endif(d>11)beginif(q==12'b000000000000) q=1;else q=q<<1;endendendmodule。