北航FPGA实验报告分析.docx
《北航FPGA实验报告分析.docx》由会员分享,可在线阅读,更多相关《北航FPGA实验报告分析.docx(30页珍藏版)》请在冰点文库上搜索。
北航FPGA实验报告分析
电气技术实践
可编程逻辑器件FPGA应用开发
实验报告
姓名
班级
学号
2016年12月
一、实验目的
1、熟悉使用可编程逻辑器件(Altera公司FPGACyclone系列EP1C6Q)。
2、熟悉使用硬件描述语言VHDL。
3、掌握FPGA集成环境(Altera公司FPGAQuartusII9.0)开发流程。
4、熟悉使用核心目标系统板与接口电路等工作原理及其功能模块绑定信息。
5、熟悉并掌握下载线方式和下载文件的选择。
二、实验要求
1、学习并掌握文本、图形等输入和时序、功能仿真方法。
2、学习并熟悉门电路、组合电路、时序电路等单一模块功能。
3、学习并设计各种不同状态机逻辑功能。
4、学习并设计由单一模块→较多功能模块集成→系统集成方法。
5、学习并选择多种模式显示(发光二极管显示、米字型数码管显示、七段数码管→动态扫描或静态扫描显示、LED点阵显示各种字符和图形或静止或移动等方式、LCD液晶显示各种字符和图形或静止或移动等方式)。
6、根据自已的兴趣和愿望,可从以下给定的实验目录中选取或自已设定功能题目。
7、实验数目没有要求,关键是看质量,是否是自已编写、调试、实现。
三、实验内容
1、按指导书集成开发环境章节操作实现文本编程实例1和图形编程实例2全过程。
2、任选门电路、组合电路、时序电路实验各完成一个其逻辑功能,其实现方案自已规定。
在进行FPGA目标器件输入和输出引脚绑定时,输入引脚绑定高/低电平、单脉冲、各种分频连续脉冲等多种信号,输出引脚可绑定发光二极管、七段数码管、LED点阵等显示模式。
3、在完成1位十进制计数器的基础上,可增加完成2或3等多位十进制计数器逻辑功能并用多位七段数码管来显示。
4、用LED点阵显示任意字符、图形等信息。
四、实验代码及实验结果
1、4位二进制加法计数器
(1)实验代码
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityerjinzhiis
port(clk,
rst:
instd_logic;
q:
outstd_logic_vector(3downto0));
endentityerjinzhi;
architecturebhvoferjinzhiis
signalq1:
std_logic_vector(3downto0);
begin
process(rst,clk)
begin
if(rst='0')then
q1<="0000";
elsif(clk'eventandclk='1')then
q1<=q1+1;
endif;
endprocess;
q<=q1;
endarchitecturebhv;
(2)管脚分配
(3)实验操作
①输入信号clk时钟→把FPGA_EA2_P6(Pin_P20)用导线与(FRQ_Q211Hz)连接、rst清零→N18(SW-1)、输出信号q3→U12(LED1)、q2→V12(LED2);q1→V15(LED3);q0→W13(LED4)。
②把输入信号rst设为“1”、clk时钟(FRQ_Q211Hz)用导线与(FRQ_Q211Hz)连接。
(4)实验现象
输出结果信息为第一、二、三、四个发光二极管按照0000→0001→……→1111循环显示,符合实验要求。
(该实验板上低电平为“1”)
2、半加器
(1)实验原理图
(2)管脚分配
(3)实验操作
逻辑分析:
输入信号a、b;输出信号分别为sum(和)、carry(进位)。
逻辑方程:
sum=a⊕b;carry=a*b。
输入信号a→N18(SW-1)、b→M20(SW-2)、输出信号sum(和)→U12(LED1)、carry(进位)→V12(LED2)
(4)实验现象
ⅰ输入信号a、b都为“0”,输出结果信息为两个发光二极管均为“灭”,说明和和进位都为0;ⅱ输入信号a为“1”,b为“0”,输出结果信息为第一个发光二极管“灭”,第二个发光二极管“亮”,说明和为“1”,进位为0;ⅲ输入信号a为“0”,b为“1”,输出结果信息为第一个发光二极管“灭”,第二个发光二极管“亮”。
说明和为“1”,进位为“0”;ⅳ输入信号a、b都为“1”,输出结果信息为第一个发光二极管“亮”第二个发光二极管“灭”,说明和为“0”,进位为“1”.均符合设计要求
3、RS触发器
(1)实验代码
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityrs_clkis
port(s,r,res:
instd_logic;
q,not_q:
outstd_logic);
endrs_clk;
architecturebehavofrs_clkis
signalsel1,sel2:
std_logic;
begin
process(res,sel1,sel2)
begin
ifres='0'thensel1<='0';
sel2<='1';
elsif(S='1'andR='0')thensel1<='1';
sel2<='0';
elsif(S='0'andR='1')thensel1<='0';
sel2<='1';
elsif(S='0'andR='0')thensel1<=sel1;
sel2<=sel2;
endif;
Q<=sel1;
not_q<=sel2;
endprocess;
endbehav;
(2)管脚分配
(3)实验操作
(3)实验现象
将实验现象总结为RS触发器特性表,其中X指0或1均可;输入为”1”指SW输入为高,输入为”0”指SW输入为低;输出为”1”指对应LED灯灭(实验台的LED灯为高电平灭),输出为”0”指对应LED灯亮。
CLK触发
输入S
输入R
原来的Q
新的输出Q*
1
0
0
X
保持原状
1
1
0
1
1
1
1
0
0
1
1
0
1
1
0
1
0
1
0
0
1
1
1
X
不定状态
0
X
X
X
保持原状
4、数码管十六进制计数器
(1)实验代码
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitymotoris
port(
clk:
instd_logic;
rst:
instd_logic;
sel:
outstd_logic;
q:
outstd_logic_vector(3downto0);
d:
outstd_logic_vector(7downto0)
);
endentity;
architectureb1ofmotoris
signalq1,q2:
std_logic_vector(3downto0);
begin
process(clk,rst)
begin
ifclk'eventandclk='1'then
q1<=q1+1;
q2<="0010";
endif;
endprocess;
q<=q2;
process(q1)
begin
if(rst='1')thensel<='0';
caseq1is
when"0000"=>d<="11111100";
when"0001"=>d<="01100000";
when"0010"=>d<="11011010";
when"0011"=>d<="11110010";
when"0100"=>d<="01100110";
when"0101"=>d<="10110110";
when"0110"=>d<="10111110";
when"0111"=>d<="11100000";
when"1000"=>d<="11111110";
when"1001"=>d<="11110110";
when"1010"=>d<="11101110";
when"1011"=>d<="00111110";
when"1100"=>d<="10011100";
when"1101"=>d<="01111010";
when"1110"=>d<="10011110";
when"1111"=>d<="10001110";
endcase;
endif;
endprocess;
end;
(2)管脚分配
(3)实验现象
将CLK接入较低频率,这样可以清晰地观察数码管从0—F(16进制数)的转变,完成一个循环之后,自动重新从0开始显示,进入下一个循环
5、跑马灯
(1)实验代码
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityledis
port(clk:
instd_logic;
rst:
instd_logic;
q:
outstd_logic_vector(7downto0));
end;
architectureledofledis
constants0:
std_logic_vector(1downto0):
="00";
constants1:
std_logic_vector(1downto0):
="01";
constants2:
std_logic_vector(1downto0):
="10";
constants3:
std_logic_vector(1downto0):
="11";
signalpresent:
std_logic_vector(1downto0);
signalq1:
std_logic_vector(7downto0);
signalcount:
std_logic_vector(3downto0);
begin
process(rst,clk)
begin
if(rst='0')then
present<=s0;
q1<=(others=>'0');
elsif(clk'eventandclk='1')then
casepresentis
whens0=>if(q1="00000000")then
q1<="10000000";
elseif(count="0111")then
count<=(others=>'0');
q1<="00000001";
present<=s1;
elseq1<=q1(0)&q1(7downto1);
count<=count+1;
present<=s0;
endif;
endif;
whens1=>if(count="0111")then
count<=(others=>'0');
q1<="10000001";
present<=s2;
elseq1<=q1(6downto0)&q1(7);
count<=count+1;
present<=s1;
endif;
whens2=>if(count="0011")then
count<=(others=>'0');
q1<="00011000";
present<=s3;
elseq1(7downto4)<=q1(4)&q1(7downto5);
q1(3downto0)<=q1(2downto0)&q1(3);
count<=count+1;
present<=s2;
endif;
whens3=>if(count="0011")then
count<=(others=>'0');
q1<="10000000";
present<=s0;
elseq1(7downto4)<=q1(6downto4)&q1(7);
q1(3downto0)<=q1(0)&q1(3downto1);
count<=count+1;
present<=s3;
endif;
endcase;
endif;
endprocess;
q<=q1;
end;
(2)管脚分配
(3)实验现象
实验开始,除了最左边的LED灯,其余实验箱上一排LED显示器全都点亮;然后随着接入CLK触发信号的频率,每一个触发脉冲,灭的灯往右移动一位(原来灭的灯的右边一位灯灭),而原来灭的灯重新点亮;当最右边一个灯灭了之后,下一个触发脉冲会重置循环,即又开始最左边的灯灭,其余的灯亮。
这样从视觉上就是一个黑点从左侧往右侧不断平移,一次移动一位,到达右侧终端后,黑点再次回到左侧,进入下一个周期。
6、键盘电路
(1)实验代码
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
useieee.std_logic_arith.all;
entitykeyboardis
port(clk:
instd_logic;
start:
instd_logic;
KBCol:
instd_logic_vector(3downto0);
KBRow:
outstd_logic_vector(3downto0);
seg7:
outstd_logic_vector(6downto0);
scan:
outstd_logic_vector(7downto0));
endkeyboard;
architecturebevofkeyboardis
signalcount:
std_logic_vector(1downto0);
signalsta:
std_logic_vector(1downto0);
begin
scan<="00000001";
a:
process(clk)
begin
if(clk'eventandclk='1')then
count<=count+1;
endif;
endprocessa;
b:
process(clk)
begin
if(clk'eventandclk='1')then
casecount(1downto0)is
when"00"=>KBRow<="0111";
sta<="00";
when"01"=>KBRow<="1011";
sta<="01";
when"10"=>KBRow<="1101";
sta<="10";
when"11"=>KBRow<="1110";
sta<="11";
whenothers=>KBRow<="1111";
endcase;
endif;
endprocessb;
process(clk,start)
begin
ifstart='0'then
seg7<="0000000";
elseif(clk'eventandclk='1')then
casestais
when"00"=>
caseKBColis
when"1110"=>seg7<="1001110";
When"1101"=>seg7<="0111101";
When"1011"=>seg7<="1001111";
When"0111"=>seg7<="1000111";
Whenothers=>seg7<="0000000";
endcase;
when"01"=>
caseKBColis
when"1110"=>seg7<="1111111";
when"1101"=>seg7<="1110011";
when"1011"=>seg7<="1110111";
when"0111"=>seg7<="0011111";
Whenothers=>seg7<="0000000";
endcase;
when"10"=>
caseKBColis
when"1110"=>seg7<="0110011";
when"1101"=>seg7<="1011011";
when"1011"=>seg7<="1011111";
when"0111"=>seg7<="1110000";
whenothers=>seg7<="0000000";
endcase;
when"11"=>
caseKBColis
when"1110"=>seg7<="1111110";
when"1101"=>seg7<="0110000";
when"1011"=>seg7<="1101101";
when"0111"=>seg7<="1111001";
whenothers=>seg7<="0000000";
endcase;
whenothers=>seg7<="0000000";
endcase;
endif;
endif;
endprocessc;
endbev;
(2)管脚分配
(3)实验操作
将SW1拨到1,按下键盘上相应的按键,如按下5
(4)实验现象
LED显示按下键位对应的数字
7、LED点阵显示
(1)实验代码
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_Unsigned.all;
useieee.std_logic_ARITH.all;
ENTITYdianzhenis
port(clk:
instd_logic;
en:
instd_logic;
hang:
outstd_logic_vector(15downto0);
count:
outstd_logic_vector(3downto0));
Enddianzhen;
Architecturedianzhenofdianzhenis
signalosc:
std_logic;
signalx:
std_logic_vector(0downto0);
signaly:
std_logic_vector(1downto0);
signalcount1:
std_logic_vector(3downto0);
signalcount2:
std_logic_vector(25downto0);
signaldata:
std_logic_vector(15downto0);
signald0,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15:
std_logic_vector(15downto0);
signala0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15:
std_logic_vector(15downto0);
signalc0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15:
std_logic_vector(15downto0);
signalb0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15:
std_logic_vector(15downto0);
Begin
hang<=data;
a0<="0000000000000000";
a1<="0000000000000000";
a2<="0000011111110000";
a3<="0000010000010000";
a4<="0000010000010000";
a5<="0000010000010000";
a6<="0000010000010000";
a7<="0111111111111110";
a8<="0000010000010000";
a9<="0000010000010000";
a10<="0000010000010000";
a11<="0000010000010000";
a12<="0000011111110000";
a13<="0000000000000000";
a14<="0000000000000000";
a15<="0000000000000000";
c0<="0000000000000000";
c1<="0000000000000000";
c2<="0111111111111110";
c3<="0100000000000010";
c4<="0101000000000010";
c5<="0101000000001010";
c6<="0101000010001010";
c7<="0101000010001010";
c8<="0101111111111010";
c9<="0101000010001010";
c10<="0101001010001010";
c11<="0101010000001010";
c12<="0101000000000010";
c13<="0100000000000010";
c14<="0111111111111110";
c15<="0000000000000000";
b0<="0000000000000000";
b1<="0010000000000000";
b2<="0001000000000000";
b3<="0000100000000000";
b4<="0000010000000000";
b5<="0000001000000000";
b6<="0000000110000000";
b7<="0000000011111110";
b8<="0000000110000000";
b9<="0000001000000000";
b10<="0000010000000000";
b11<="0000100000000000";
b12<="0001000000000000";
b13<="0010000000000000";
b14<="0000000000000000";
a15<="0000000000000000";