数字电路课程设计函数信号发生器Word文档格式.docx
《数字电路课程设计函数信号发生器Word文档格式.docx》由会员分享,可在线阅读,更多相关《数字电路课程设计函数信号发生器Word文档格式.docx(35页珍藏版)》请在冰点文库上搜索。
通过拨动开关A2、A1实现波形幅度的选择:
共计四种;
通过拨动开关F2、F1实现波形频率的选择:
下载并测试电路的功能,用示波器观察DAC0832输出波形。
1.3本人任务
进行基于vhdl的软件设计,包括顶层模块设计,配合硬件进行硬件仿真和测试。
第二部分设计
2.1软件电路方案设计
对六个波形模块和三个选择模块进行单独编写,最后设计顶层模块输出。
在确定课题的第一天,我和我的组员查找资料,初步确定了电路的设计方案。
2.2原理框图
第三部分单元模块设计,仿真结果及分析
3.1分频器模块
实体框图
程序清单:
libraryieee;
useieee.std_logic_1164.all;
entityfanais
port(a:
inintegerRANGE0TO312;
--a为频率输入的初始值
clk:
instd_logic;
q:
outstd_logic);
--q为输出的脉冲频率
end;
architecturefana_arcoffanais
begin
process(clk)
variableb,d:
std_logic;
variablec:
integerRANGE0TO312;
begin
ifclk'
eventandclk='
1'
then
ifb='
0'
then--检测b
c:
=a-1;
--b为低电平则将a-1送到c
b:
='
;
--且令b=1
else
ifc=1then--b为1时检测c
--c=1时使b=0
d:
=notd;
--d取反
elsec:
=c-1;
--c不等于1时c-1
endif;
q<
=d;
--将d作为频率输出
endprocess;
分析:
这一部分主要实现对fpga内部时钟的初始分频。
波形如上,当输入a为256时,每256个clk脉冲后q发生一个脉冲。
3.2频率选择
实体框图
程序清单:
entitychuzhiis
port(f0:
instd_logic_vector(1downto0);
--f0初始频率选择开关
outintegerRANGE0TO312);
architecturechu_arcofchuzhiis
withf0select--四种不同的初值
=312when"
00"
201when"
01"
101when"
10"
10when"
11"
NULLwhenothers;
这部分程序实现脉冲频率的选择,当f0为00、01、10、11时,频率分别为312、201、101、10;
将此输出作为分频器的输入。
3.3幅度选择
entityfuduis
port(f1:
outintegerRANGE0TO255);
architecturefudu_arcoffuduis
withf1select--四种不同的初值
=255when"
207when"
167when"
119when"
分析:
此程序为幅度选择,当f1为00、01、10、11时,幅度分别为255、207、167、169。
3.4六种波形设计
a、方波
entitysquareis
port(clk,clr:
k:
inintegerrange0to255;
--幅度选择信号
outintegerrange0to255);
--方波输出
architecturesq_arcofsquareis
signala:
bit;
process(clr,clk)
variablecnt:
integer;
begin
ifclr='
then
a<
elsifclk'
then--时钟上升沿
ifcnt<
31thencnt:
=cnt+1;
--cnt未到31时加1
elsecnt:
=0;
--cnt到31时清零
=nota;
--并将a取反
process(clk,a)
ifa='
then--每个时钟上升沿检测a
=k;
--a为1则q为最大值,即高电平
else
--a为0时取反,q为最小值
endif;
64个上升沿脉冲形成一个周期,半个周期为高电平255,半个周期低电平0。
b、三角波
useieee.std_logic_unsigned.all;
entitydeltais
port(clk,clr:
--k幅度选择信号
enddelta;
architectureaofdeltais
process(clk,clr)
variablenum:
integerrange0to255;
variableff:
--上升沿/下降沿判断标志,为0时上升,为1时下降
then--异步复位端
num:
then--上升沿
ifff='
ifnum=k-7then
ff:
else
=num+8;
--ff=0,每个上升沿脉冲加8
ifnum=7then
=num-8;
--ff=1,下降沿,每个脉冲减8
=num;
enda;
每个脉冲上升8个点,点连成线形成三角的上升和下降曲线。
由上图可知当幅度输入为207时,当上升到207个点时下降。
c、正弦波
entitysinis
architecturesin_arcofsinis
process(clk,clr,k)
variabletmp:
integerrange0to63;
d<
iftmp=63then--tmp=63则清零
tmp:
=tmp+1;
--否则tmp+1
ifk=255then
casetmpis
when00=>
d<
=255;
when01=>
=254;
when02=>
=252;
--上升曲线
when03=>
=249;
when04=>
=245;
when05=>
=239;
when06=>
=233;
when07=>
=225;
when08=>
=217;
when09=>
=207;
when10=>
=197;
when11=>
=186;
when12=>
=174;
when13=>
=162;
when14=>
=150;
when15=>
=137;
when16=>
=124;
when17=>
=112;
when18=>
=99;
when19=>
=87;
when20=>
=75;
when21=>
=64;
when22=>
=53;
when23=>
=43;
when24=>
=34;
when25=>
=26;
when26=>
=19;
when27=>
=13;
when28=>
=8;
when29=>
=4;
when30=>
=1;
when31=>
when32=>
--下降曲线
when33=>
when34=>
when35=>
when36=>
when37=>
when38=>
when39=>
when40=>
when41=>
when42=>
when43=>
when44=>
when45=>
when46=>
when47=>
when48=>
when49=>
when50=>
when51=>
when52=>
when53=>
when54=>
when55=>
when56=>
when57=>
when58=>
when59=>
when60=>
when61=>
when62=>
when63=>
--完成一个周期
whenothers=>
NULL;
endcase;
elsifk=207then
=206;
=205;
=202;
=199;
=195;
=190;
=183;
=177;
=169;
=160;
=152;
=142;
=132;
=123;
=111;
=100;
=91;
=80;
=70;
=61;
=52;
=35;
=28;
=21;
=15;
=10;
=6;
=3;
elsifk=167then
=167;
=166;
=165;
=163;
=155;
=151;
=146;
=141;
=134;
=128;
=121;
=113;
=105;
=97;
=89;
=81;
=73;
=56;
=49;
=42;
=22;
=17;
=12;
=5;
elsifk=119then
=119;
=118;
=117;
=116;
=114;
=109;
=101;
=92;
=76;
=58;
=46;
=41;
=30;
=25;
=20;
=16;
=9;
=2;
--下降曲线
与三角波一样,正弦波也是采用点连成曲线的方法完成的。
d、锯齿波
entityjuchiis
outintegerra