北京航空航天大学电气实验报告FPGA实验张天130325班学号:13031220一.实验目的略二.实验要求略三.实验设备略四.实验内容略五.实验实例1.实例6-1思考题1:输出信号q3q2q1绑定接口电路的七段数码管或米字型数码管或LED点阵显示?答:思考题2:怎样修改成4位二进制减法计数器,具有清零,启动控制功能等?答:思考题3:把计数器修改成2位或更多位十进制计数功能,再用七段数码管进行显示等?答:2.实例6-2思考题:一位半加器电路采用VHDL语言实验答:library ieee;use ieee.std_logic_1164.all;use iee.std_logic_unsigned.all;entity halfadd isport (a,b;in std_logicsum,carry; out std_logic)end entity halfadd;architecture halfadd isbeginsum<=a and(not b)+b and (not a);carry<= a and b;end architecture halfadd;六.实验过程我们组做的是一个利用led点阵规律亮灭变化形成字体,并且字体产生变化,形成“自动化❤”的样子,实现图片如下图:1.实验分析:实验设计思路:本实验的设计思路是利用led灯的辉光效应,利用逐行扫描,在高频情况下就会显示所有行的亮灯,进而形成汉字,并且有时钟计数程序,当时钟数字达到规定值(本实验为111111111b)时,跳转到下一个状态,显示第二个憨子。
每个汉字的颜色由led灯决定,改led矩阵有红绿两种led灯,因此有红绿橙三种颜色显示。
2.实现过程对设计思路的实现并非一帆风顺,最初编写的时候遇到了一些问题。
首先,定义输入输出角是个繁琐的事情(需要定义40+次,每次必须手动),另外,在程序编写过程中,也出现了一些逻辑错误,对于错误,我们仔细逐条语句分析,最终解决了错误,解决过程中也加深了对FPGA的语言逻辑及硬件结构的理解。
七.FPGA使用心得在学习FPGA过程中,我获得了很多收获。
首先,由于有单片机的基础,上手过程并不是十分复杂,对于输入输出的理解我没有遇到太多阻碍。
这次学习也验证了我具有短时间内掌握一款新型的芯片的能力。
学习过程中最大的困难就是VDHL语言的编写。
我们以前有c语言的基础,不过学习这种新的语言还是花出了不少时间与精力,现在可以说基本掌握的VDHL的基本写法和思路,能运用到需要的程序中来。
另外,调试的过程能极强地加大对程序的理解及逻辑的构建,在调试中,逐渐明白了以前不懂的东西,对FPGA的工作原理的理解更加透彻了。
不了解的人可能会把FPGA当做一种单片机,但其实,相比于单片机,FPGA 是有很多优势的。
其无固定的硬件结构使其具有远超单片机的灵活性,另外,它的编程方法可以同步进行多个process 使其能同步处理多个进程,因此,它的运算效率大大提高,在当今社会,有很大的利用价值。
八.电气实验总结略附:程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity led isport(clk:in std_logic;rst:in std_logic;com:out std_logic_vector(7 downto 0);red:out std_logic_vector(7 downto 0);green:out std_logic_vector(7 downto 0));end;architecture led of led isconstant s0:std_logic_vector(1 downto 0):="00";constant s1:std_logic_vector(1 downto 0):="01";constant s2:std_logic_vector(1 downto 0):="10";constant s3:std_logic_vector(1 downto 0):="11";signal present:std_logic_vector(1 downto 0);signal com1:std_logic_vector(7 downto 0);signal red1:std_logic_vector(7 downto 0);signal green1:std_logic_vector(7 downto 0);signal count:std_logic_vector(9 downto 0);signal zi:std_logic_vector(2 downto 0);beginprocess(rst,clk)beginif(rst='0')then--――系统初始化present<=s0;com1<=(others=>'0');elsif(clk'event and clk='1')thencase present iswhen s0=>if(com1="00000000")thencom1<="11111111";red1<="11111111";green1<="11111111";zi<="000";present<=s0;else if(count="111111111")thencount<=(others=>'0');present<=s1;elsecase zi iswhen "000"=>com1<="00001000";green1<="00000000"; count<=count+1;zi<=zi+1;when "001" =>com1<="00111100"; red1<="00000010"; green1<="00000000"; count<=count+1;zi<=zi+1;when "010"=>com1<="00100100"; red1<="00000100"; green1<="00000000"; count<=count+1;zi<=zi+1;when "011"=>com1<="00111100"; red1<="00001000"; green1<="00000000"; count<=count+1;zi<=zi+1;when "100"=>com1<="00100100"; red1<="00010000"; green1<="00000000"; count<=count+1;zi<=zi+1;when "101"=> com1<="00111100"; red1<="00100000"; green1<="00000000"; count<=count+1;zi<=zi+1;when "110"=> com1<="00100100"; red1<="01000000"; green1<="00000000";zi<=zi+1;when "111"=>com1<="00111100";red1<="10000000";green1<="00000000";count<=count+1;present<=s0;zi<="000";end case;end if;end if;when s1=>if(count="111111111")then --S1模式:从右到左逐个点亮LEDcount<=(others=>'0');present<=s2;else present<=s1;case zi iswhen "000"=>com1<="00100000";red1<="00000001";green1<="00000001";count<=count+1;zi<=zi+1;when "001" =>com1<="00100000";red1<="00000010";green1<="00000010";count<=count+1;zi<=zi+1;when "010"=>com1<="00100110";red1<="00000100";green1<="00000100";count<=count+1;zi<=zi+1;when "011"=>com1<="11110000";green1<="00001000";count<=count+1;zi<=zi+1;when "100"=>com1<="10101111";red1<="00010000";green1<="00010000";count<=count+1;zi<=zi+1;when "101"=>com1<="10100100";red1<="00100000";green1<="00100000";count<=count+1;zi<=zi+1;when "110"=>com1<="10101010";red1<="01000000";green1<="01000000";count<=count+1;zi<=zi+1;when "111"=>com1<="10101111";red1<="10000000";green1<="10000000";count<=count+1;present<=s0;zi<="000";end case;count<=count+1;present<=s1;end if;when s2=>if(count="111111111")then --S2模式:从两边到中间逐个点亮LEDcount<=(others=>'0');present<=s3;elsecase zi iswhen "000"=>com1<="00011000";red1<="00000000";green1<="00000001";count<=count+1;zi<=zi+1;when "001" =>com1<="00010100";red1<="00000000";green1<="00000010";count<=count+1;zi<=zi+1;when "010"=>com1<="01010010";red1<="00000000";green1<="00000100";count<=count+1;zi<=zi+1;when "011"=>com1<="00110011";red1<="00000000";green1<="00001000";count<=count+1;zi<=zi+1;when "100"=>com1<="00010010";red1<="00000000";green1<="00010000";count<=count+1;zi<=zi+1;when "101"=>com1<="00011010";red1<="00000000";green1<="00100000";count<=count+1;zi<=zi+1;when "110"=>com1<="10010010";red1<="00000000";green1<="01000000";count<=count+1;zi<=zi+1;when "111"=>com1<="11110010";red1<="00000000";green1<="10000000";count<=count+1;present<=s0;zi<="000";end case;count<=count+1;present<=s2;end if;when s3=>if(count="111111111")thencount<=(others=>'0');present<=s0;elsepresent<=s3;case zi iswhen "000"=>com1<="00000000";red1<="00000001";green1<="00000000";count<=count+1;zi<=zi+1;when "001" =>com1<="01100110";red1<="00000010";green1<="00000000";count<=count+1;zi<=zi+1;when "010"=>com1<="11111111";red1<="00000100";green1<="00000000";count<=count+1;zi<=zi+1;when "011"=>com1<="11111111";red1<="00001000";green1<="00000000";count<=count+1;zi<=zi+1;when "100"=>com1<="01111110";red1<="00010000";green1<="00000000";count<=count+1;zi<=zi+1;when "101"=>com1<="00111100";red1<="00100000";green1<="00000000";count<=count+1;zi<=zi+1;when "110"=>com1<="00011000";red1<="01000000";green1<="00000000";count<=count+1;zi<=zi+1;when "111"=>com1<="00000000";red1<="10000000";green1<="00000000";count<=count+1;present<=s0;zi<="000";end case;count<=count+1;present<=s3;end if;end case;end if;end process; com<=com1; red<=red1; green<=green1; end;。