FPGA设计数字系统.docx

上传人:b****8 文档编号:9686848 上传时间:2023-02-05 格式:DOCX 页数:139 大小:48.76KB
下载 相关 举报
FPGA设计数字系统.docx_第1页
第1页 / 共139页
FPGA设计数字系统.docx_第2页
第2页 / 共139页
FPGA设计数字系统.docx_第3页
第3页 / 共139页
FPGA设计数字系统.docx_第4页
第4页 / 共139页
FPGA设计数字系统.docx_第5页
第5页 / 共139页
点击查看更多>>
下载资源
资源描述

FPGA设计数字系统.docx

《FPGA设计数字系统.docx》由会员分享,可在线阅读,更多相关《FPGA设计数字系统.docx(139页珍藏版)》请在冰豆网上搜索。

FPGA设计数字系统.docx

FPGA设计数字系统

例1矩形波发生器----------------------------------------------------------2

例2三角波发生器---------------------------------------------------------15

例3数字频率计------------------------------------------------------------22

例4数字钟------------------------------------------------------------------32

例5交通灯控制器---------------------------------------------------------43

例6LED字符显示器----------------------------------------------------52

例7LED跑马灯----------------------------------------------------------55

例8过河游戏---------------------------------------------------------------59

例9拔河游戏---------------------------------------------------------------69

例10键盘输入显示器----------------------------------------------------82

 

附录

I用VHDL设计数字系统实例

为了拓宽设计思路,在光盘中再举出一些用VHDL设计数字系统的实例。

以下实例只提供简单的

总体框图和简单的注释作为提示,未涉及之处留给读者思考、开拓。

例1矩形波发生器

1.设计任务及要求

(1)设计一个矩形波发生器,输出频率范围为10Hz~1kHz,分如下两挡:

1

○10Hz~100Hz挡,其频率可调节,频率递增步进长度为10Hz。

2

○100Hz~1kHz挡,其频率可调节,频率递增步进长度为100Hz。

(2)输出矩形波的占空比在10%~90%之间可调,调节的递增步进长度为10%。

(3)输出电压峰峰值为5V。

(4)每个周期信号的构造数据由30个取样点的值组成。

2.可选器件

EPM7128S、共阴极七段数码管、DAC0832、LM741、开关、电阻和电容。

3.设计总体框图

矩形波发生器总体框图如附图1.1所示。

附图1.1矩形波发生器总体框图

4.源程序及注释

(1)上层模块

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_signed.all;

useieee.std_logic_unsigned.all;

entitycheifis

port(clk_1m:

instd_logic;--时钟信号,1MHz。

k1:

instd_logic;--调节频率的开关信号。

k2:

instd_logic;--调节占空比的开关信号。

k3:

instd_logic;--换挡开关信号。

sel:

outstd_logic_vector(5downto0);--数码管片选信号。

d:

outstd_logic_vector(6downto0);--数码管的驱动信号。

f:

outstd_logic_vector(7downto0));--输出给DAC0832的8位数字信号。

endcheif;

architectureaaofcheifis

signalmode_mid:

integerrange0to1;

signalclk_125_mid:

std_logic;

signals1:

std_logic;

signals2:

std_logic;

signals3:

std_logic;

signalfs_mid:

std_logic;

signalstatusf_mid:

integerrange0to9;

signalstatush_mid:

integerrange0to8;

componentkeyin--调用防抖动模块。

port(k:

instd_logic;

kout:

bufferstd_logic;

clk_125:

instd_logic);

endcomponent;

componentfp--调用分频及控制模块。

port(clk_1m:

instd_logic;

s1:

instd_logic;

s3:

instd_logic;

statusf:

outintegerrange0to9;

mode:

outintegerrange0to1;

fs:

outstd_logic);

endcomponent;

componentoutput--调用信号输出模块。

port(fs:

instd_logic;

s2:

instd_logic;

statush:

outintegerrange0to8;

f:

outstd_logic_vector(7downto0));

endcomponent;

componentdisplay--调用分频及显示模块。

port(statusf:

inintegerrange0to9;

statush:

inintegerrange0to8;

mode:

inintegerrange0to1;

clk_1m:

instd_logic;

clk_125:

outstd_logic;

sel:

outstd_logic_vector(5downto0);

d:

outstd_logic_vector(6downto0));

endcomponent;

begin

u1:

keyinportmap(k1,s1,clk_125_mid);

u2:

keyinportmap(k2,s2,clk_125_mid);

u3:

keyinportmap(k3,s3,clk_125_mid);

u4:

fpportmap(clk_1m,s1,s3,statusf_mid,mode_mid,fs_mid);

u5:

outputportmap(fs_mid,s2,statush_mid,f);

u6:

displayportmap(statusf_mid,statush_mid,mode_mid,clk_1m,

clk_125_mid,sel,d);

endaa;

(2)下层模块

①防抖动模块

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entitykeyinis

port(k:

instd_logic;--有抖动的开关信号。

kout:

bufferstd_logic;--消抖动后的开关信号。

clk_125:

instd_logic);--时钟信号,125Hz。

endkeyin;

architectureaaofkeyinis

signala,d1,d2,s,r,q1,q2,b:

std_logic;

begin

p1:

process(clk_125)

begin

if(clk_125=′0′)then

d1<=k;

d2<=d1;

endif;

endprocess;

p2:

process

begin

s<=d1andd2;

r<=(notd1)and(notd2);

a<=sor((notr)anda);

endprocess;

p3:

process(clk_125)

begin

if(clk_125′eventandclk_125=′1′)then

q2<=q1;

q1<=a;

endif;

b<=q1andnotq2;

kout<=b;

endprocess;

endaa;

②分频及控制模块

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_signed.all;

useieee.std_logic_unsigned.all;

entityfpis

port(clk_1m:

instd_logic;--时钟信号,1MHz。

s1:

instd_logic;--经过防抖后输入的调节频率的开关信号。

s3:

instd_logic;--经过防抖后输入的换挡开关信号。

statusf:

outintegerrange0to9;--改变频率的控制计数器。

mode:

outintegerrange0to1;--换挡控制信号。

fs:

outstd_logic);--取样信号。

endfp;

architectureaaoffpis

signaln:

integerrange0to166;

signalm:

integerrange0to1;

signalstatus:

integerrange0to9;

signalfs2:

std_logic;

signalfs2_10:

std_logic;

signalfs1:

std_logic;

signalcount:

integerrange0to166;

signalc:

integerrange0to10;

begin

process(s1,s3)

begin

if(s1′eventands1=′1′)then

if(status=9)then

status<=0;

else

status<=status+1;

endif;

endif;

if(s3′eventands3=′1′)then

if(m=1)then

m<=0;

elsif(m=0)then

m<=1;

endif;

endif;

casestatusis

when0=>n<=166;--信号n用来控制对1MHz信号分频电路输出信号的频率。

when1=>n<=83;

when2=>n<=55;

when3=>n<=41;

when4=>n<=33;

when5=>n<=27;

when6=>n<=23;

when7=>n<=20;

when8=>n<=18;

when9=>n<=16;

whenothers=>n<=null;

endcase;

endprocess;

process(clk_1m)

begin

if(clk_1m′eventandclk_1m=′1′)then

if(count=n)then--n的值不同,输出信号的频率也不同。

count<=1;

fs2<=′1′;

else

count<=count+1;

fs2<=′0′;

endif;

elsenull;

endif;

endprocess;

process(fs2)

begin

if(fs2′eventandfs2=′1′)then--实现换挡功能。

if(m=0)then

fs2_10<=fs2;

else

if(c=9)then

c<=0;

fs2_10<=′0′;

else

c<=c+1;

fs2_10<=′1′;

endif;

endif;

endif;

endprocess;

process(fs2_10)

begin

if(fs2_10′eventandfs2_10=′1′)then

fs1<=notfs1;--2分频后得到不同频率的取样信号。

endif;

endprocess;

fs<=fs1;

statusf<=status;

mode<=m;

endaa;

③信号输出模块

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_signed.all;

entityoutputis

port(fs:

instd_logic;--取样信号。

s2:

instd_logic;--经过防抖后输入的调节占空比的开关信号。

statush:

outintegerrange0to8;--改变占空比的控制计数器。

f:

outstd_logic_vector(7downto0));--输出给DAC0832的8位数字信号。

endoutput;

architectureaaofoutputis

signalm:

integerrange0to29;

signalstatus:

integerrange0to8;

begin

p1:

process(s2)

begin

777776

(s2′eventands2=if′1′)then

if(status=8)then

status<=0;

else

status<=status+1;

endif;

endif;

endprocessp1;

p3:

process(fs)--本进程描述一个用于调节脉宽的控制计数器。

begin

if(fs′eventandfs=′1′)then

if(m=29)then

m<=0;

else

m<=m+1;

endif;

else

null;

endif;

endprocessp3;

p2:

process(status)--本进程描述不同占空比的矩形波的显示控制。

begin

casestatusis

when0=>

casemis--当m<3,占空比为10%。

when0=>f<="11111111";

when1=>f<="11111111";

when2=>f<="11111111";

whenothers=>f<="00000000";

endcase;

when1=>

casemis。

when0=>f<="11111111";

when1=>f<="11111111";

when2=>f<="11111111";

when3=>f<="11111111";

when4=>f<="11111111";

when5=>f<="11111111";

whenothers=>f<="00000000";

endcase;

when2=>

casemis

when0=>f<="11111111";

when1=>f<="11111111";

when2=>f<="11111111";

when3=>f<="11111111";

when4=>f<="11111111";

when5=>f<="11111111";

when6=>f<="11111111";

when7=>f<="11111111";

when8=>f<="11111111";

whenothers=>f<="00000000";

endcase;

when3=>

casemis

when0=>f<="11111111";

when1=>f<="11111111";

when2=>f<="11111111";

when3=>f<="11111111";

when4=>f<="11111111";

when5=>f<="11111111";

when6=>f<="11111111";

when7=>f<="11111111";

when8=>f<="11111111";

when9=>f<="11111111";

when10=>f<="11111111";

when11=>f<="11111111";

whenothers=>f<="00000000";

endcase;

when4=>

casemis

when0=>f<="11111111";

when1=>f<="11111111";

when2=>f<="11111111";

when3=>f<="11111111";

when4=>f<="11111111";

when5=>f<="11111111";

when6=>f<="11111111";

when7=>f<="11111111";

when8=>f<="11111111";

when9=>f<="11111111";

when10=>f<="11111111";

when11=>f<="11111111";

when12=>f<="11111111";

when13=>f<="11111111";

when14=>f<="11111111";

whenothers=>f<="00000000";

endcase;

when5=>

casemis

when18=>f<="00000000";

when19=>f<="00000000";

when20=>f<="00000000";

when21=>f<="00000000";

when22=>f<="00000000";

when23=>f<="00000000";

when24=>f<="00000000";

when25=>f<="00000000";

when26=>f<="00000000";

when27=>f<="00000000";

when28=>f<="00000000";

when29=>f<="00000000";

whenothers=>f<="11111111";

endcase;

when6=>

casemis

when21=>f<="00000000";

when22=>f<="00000000";

when23=>f<="00000000";

when24=>f<="00000000";

when25=>f<="00000000";

when26=>f<="00000000";

when27=>f<="00000000";

when28=>f<="00000000";

when29=>f<="00000000";

whenothers=>f<="11111111";

endcase;

when7=>

casemis

when24=>f<="00000000";

when25=>f<="00000000";

when26=>f<="00000000";

when27=>f<="00000000";

when28=>f<="00000000";

when29=>f<="00000000";

whenothers=>f<="11111111";

endcase;

when8=>

casemis

when27=>f<="00000000";

when28=>f<="00000000";

when29=>f<="00000000";

whenothers=>f<="11111111";

endcase;

whenothers=>f<=null;

endcase;

endprocessp2;

statush<=status;

endaa;

④分频及显示模块

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_signed.all;

useieee.std_logic_unsigned.all;

entitydisplayis

port(statusf:

inintegerrange0to9;--改变显示频率的控制计数器。

statush:

inintegerrange0to8;--改变显示占空比的控制计数器。

mode:

inintegerrange0to1;--换挡控制信号。

clk_1m:

instd_logic;--时钟信号,1MHz。

clk_125:

outstd_logic;--防抖动模块的时钟信号。

sel:

outstd_logic_vector(5downto0);--数码管片选信号。

d:

outstd_logic_vector(6downto0));--数码管的驱动信号。

enddisplay;

architectureaaofdisplayis

signalnto1999;:

integerrange0

signalclk_500:

std_logic;

signalclk_250:

std_logic;

signalclk_125_mid

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1