SOPC课程设计实验报告.docx
- 文档编号:6049531
- 上传时间:2023-01-03
- 格式:DOCX
- 页数:15
- 大小:118.55KB
SOPC课程设计实验报告.docx
《SOPC课程设计实验报告.docx》由会员分享,可在线阅读,更多相关《SOPC课程设计实验报告.docx(15页珍藏版)》请在冰豆网上搜索。
SOPC课程设计实验报告
--本页仅作为文档封面,使用时请直接删除即可----内页可以根据需求调整合适字体及大小--
SOPC课程设计实验报告(总19页)
SOPC课程设计实验报告
基于SOPC的警示灯设计
2013电子信息工程3班
李婕
罗丹妮
一、设计目的
1、熟悉掌握SOPC的基本流程
2、设计一个警示灯并满足基本要求
3、通过设计发现问题并解决
二、设计设备
1、硬件:
PC机、SOPC-NIOSIIEDA/SOPC系统开发平台
2、软件:
QUARTUSII、SOPCBuilder、NIOSIIIDE
三、设计内容
•初始状态为红灯(LED2)熄灭,绿灯(LED1)点亮,数码管显示为0。
•当按键按下,红灯(LED2)闪烁,绿灯(LED1)熄灭,同时蜂鸣器响起,数码管开始倒计时9S,此状态持续时间为9s。
•9s后,恢复初始状态。
四、设计步骤
1、使用QuartusII建立一个工程文件和顶层文件;
2、使用SOPCBuilder建立一个简单NiosII硬件系统
1)启动SOPCBuilder
2)指定目标FPGA
3)添加NiosII内核及其他外设
A、添加NiosII、SRAM、JTAG-UART、Avalon总线的IP核
B、添加一个2位的输入型PIO作为按键key
C、添加两个1位的输出型PIO作为led1及led2的输出端口
D、添加一个1位的输出型PIO作为蜂鸣器的输入端口A
E、添加一个3位的输出型PIO作为数码管的位选sel
F、添加一个8位的输出型PIO作为数码管的段选dat
4)指定基地址和中断优先级
5)设置NiosII复位和异常地址
6)编译生成NiosII系统
SOPCBuilder行程图如下:
3、在QuartusII中建立一个蜂鸣器
1)用VHDL语言编写蜂鸣器程序
2)编译成功后Creatsymbol,生成Projectsing
4、在QuartusII中编译NiosII硬件系统并生成配置文件
1)在QuartusII加入NiosII系统符号到顶层文件
2)给各端口加入输入输出引脚,并重命名
3)设置参数
4)编译顶层文件
5)分配管脚
6)再次编译
5、在NiosIIIDE中建立C/C++工程,编写用户程序
6、编译用户程序
7、下载.SOF至FPGA,运行程序,观察结果
五、设计程序
蜂鸣器程序(VHDL):
LIBRARYIEEE;
USEsing1IS
PORT(
CLK:
INSTD_LOGIC;
p:
INSTD_LOGIC;
--DIGIT:
BUFFERSTD_LOGIC_VECTOR(6DOWNTO0);
SPEAKER:
OUTSTD_LOGIC);
ENDENTITY;
ARCHITECTURESONGOFsing1IS
SIGNALDRIVER,ORIGIN:
STD_LOGIC_VECTOR(12DOWNTO0);
SIGNALCOUNTER:
INTEGERRANGE0TO140;
SIGNALCOUNTER1:
INTEGERRANGE0TO3;
SIGNALCOUNTER2:
INTEGERRANGE1TO;
SIGNALDIGIT:
STD_LOGIC_VECTOR(6DOWNTO0);
SIGNALCOUNT:
STD_LOGIC_VECTOR(1DOWNTO0);
SIGNALCARRIER,CLK_4MHZ,CLK_4HZ:
STD_LOGIC;
BEGIN
PROCESS(CLK)
BEGIN
IFCLK'EVENTANDCLK='1'THEN
IFCOUNTER1=1THENCLK_4MHZ<='1';
COUNTER1<=2;
ELSIFCOUNTER1=3THENCLK_4MHZ<='0';
COUNTER1<=0;
ELSECOUNTER1<=COUNTER1+1;
ENDIF;
IFCOUNTER2=5000000THENCLK_4HZ<='1';
COUNTER2<=5000001;
ELSIFCOUNTER2=THENCLK_4HZ<='0';
COUNTER2<=1;
ELSECOUNTER2<=COUNTER2+1;
ENDIF;
ENDIF;
ENDPROCESS;
PROCESS(CLK_4MHZ)
BEGIN
IFCLK_4MHZ'EVENTANDCLK_4MHZ='1'THEN
IFDRIVER=""THEN
CARRIER<='1';
DRIVER<=ORIGIN;
ELSE
DRIVER<=DRIVER+1;
CARRIER<='0';
ENDIF;
ENDIF;
ENDPROCESS;
PROCESS(CARRIER)
BEGIN
if(p='1')then
IFCARRIER'EVENTANDCARRIER='1'THEN
COUNT<=COUNT+1;
IFCOUNT="00"THEN
SPEAKER<='1';
ELSE
SPEAKER<='0';
ENDIF;
ENDIF;
endif;
ENDPROCESS;
PROCESS(CLK_4HZ)
BEGIN
IFCLK_4HZ'EVENTANDCLK_4HZ='1'THEN
IFCOUNTER=140THEN
COUNTER<=0;
ELSECOUNTER<=COUNTER+1;
ENDIF;
ENDIF;
CASECOUNTERIS
WHEN0=>DIGIT<="0000011";WHEN1=>DIGIT<="0000011";
WHEN2=>DIGIT<="0000011";WHEN3=>DIGIT<="0000011";
WHEN4=>DIGIT<="0000101";WHEN5=>DIGIT<="0000101";
WHEN6=>DIGIT<="0000101";WHEN7=>DIGIT<="0000110";
WHEN8=>DIGIT<="0001000";WHEN9=>DIGIT<="0001000";
WHEN10=>DIGIT<="0001000";WHEN11=>DIGIT<="0010000";
WHEN12=>DIGIT<="0000110";WHEN13=>DIGIT<="0001000";
WHEN14=>DIGIT<="0000101";WHEN15=>DIGIT<="0000101";
WHEN16=>DIGIT<="0101000";WHEN17=>DIGIT<="0101000";
WHEN18=>DIGIT<="0101000";WHEN19=>DIGIT<="1000000";
WHEN20=>DIGIT<="0110000";WHEN21=>DIGIT<="0101000";
WHEN22=>DIGIT<="0011000";WHEN23=>DIGIT<="0101000";
WHEN24=>DIGIT<="0010000";WHEN25=>DIGIT<="0010000";
WHEN26=>DIGIT<="0010000";WHEN27=>DIGIT<="0010000";
WHEN28=>DIGIT<="0010000";WHEN29=>DIGIT<="0010000";
WHEN30=>DIGIT<="0000011";WHEN31=>DIGIT<="0000000";
WHEN32=>DIGIT<="0010000";WHEN33=>DIGIT<="0010000";
WHEN34=>DIGIT<="0010000";WHEN35=>DIGIT<="0011000";
WHEN36=>DIGIT<="0000111";WHEN37=>DIGIT<="0000111";
WHEN38=>DIGIT<="0000110";WHEN39=>DIGIT<="0000110";
WHEN40=>DIGIT<="0000101";WHEN41=>DIGIT<="0000101";
WHEN42=>DIGIT<="0000101";WHEN43=>DIGIT<="0000110";
WHEN44=>DIGIT<="0001000";WHEN45=>DIGIT<="0001000";
WHEN46=>DIGIT<="0010000";WHEN47=>DIGIT<="0010000";
WHEN48=>DIGIT<="0000011";WHEN49=>DIGIT<="0000011";
WHEN50=>DIGIT<="0001000";WHEN51=>DIGIT<="0001000";
WHEN52=>DIGIT<="0000110";WHEN53=>DIGIT<="0000101";
WHEN54=>DIGIT<="0000110";WHEN55=>DIGIT<="0001000";
WHEN56=>DIGIT<="0000101";WHEN57=>DIGIT<="0000101";
WHEN58=>DIGIT<="0000101";WHEN59=>DIGIT<="0000101";
WHEN60=>DIGIT<="0000101";WHEN61=>DIGIT<="0000101";
WHEN62=>DIGIT<="0000101";WHEN63=>DIGIT<="0000101";
WHEN64=>DIGIT<="0011000";WHEN65=>DIGIT<="0011000";
WHEN66=>DIGIT<="0011000";WHEN67=>DIGIT<="0101000";
WHEN68=>DIGIT<="0000111";WHEN69=>DIGIT<="0000111";
WHEN70=>DIGIT<="0010000";WHEN71=>DIGIT<="0010000";
WHEN72=>DIGIT<="0000110";WHEN73=>DIGIT<="0001000";
WHEN74=>DIGIT<="0000101";WHEN75=>DIGIT<="0000101";
WHEN76=>DIGIT<="0000101";WHEN77=>DIGIT<="0000101";
WHEN78=>DIGIT<="0000101";WHEN79=>DIGIT<="0000101";
WHEN80=>DIGIT<="0000011";WHEN81=>DIGIT<="0000101";
WHEN82=>DIGIT<="0000011";WHEN83=>DIGIT<="0000011";
WHEN84=>DIGIT<="0000101";WHEN85=>DIGIT<="0000110";
WHEN86=>DIGIT<="0000111";WHEN87=>DIGIT<="0010000";
WHEN88=>DIGIT<="0000110";WHEN89=>DIGIT<="0000110";
WHEN90=>DIGIT<="0000110";WHEN91=>DIGIT<="0000110";
WHEN92=>DIGIT<="0000110";WHEN93=>DIGIT<="0000110";
WHEN94=>DIGIT<="0000101";WHEN95=>DIGIT<="0000110";
WHEN96=>DIGIT<="0001000";WHEN97=>DIGIT<="0001000";
WHEN98=>DIGIT<="0001000";WHEN99=>DIGIT<="0010000";
WHEN100=>DIGIT<="0101000";WHEN101=>DIGIT<="0101000";
WHEN102=>DIGIT<="0101000";WHEN103=>DIGIT<="0011000";
WHEN104=>DIGIT<="0010000";WHEN105=>DIGIT<="0010000";
WHEN106=>DIGIT<="0011000";WHEN107=>DIGIT<="0010000";
WHEN108=>DIGIT<="0001000";WHEN109=>DIGIT<="0001000";
WHEN110=>DIGIT<="0000110";WHEN111=>DIGIT<="0000101";
WHEN112=>DIGIT<="0000011";WHEN113=>DIGIT<="0000011";
WHEN114=>DIGIT<="0000011";WHEN115=>DIGIT<="0000011";
WHEN116=>DIGIT<="0001000";WHEN117=>DIGIT<="0001000";
WHEN118=>DIGIT<="0000110";WHEN119=>DIGIT<="0001000";
WHEN120=>DIGIT<="0000110";WHEN121=>DIGIT<="0000011";
WHEN122=>DIGIT<="0000011";WHEN123=>DIGIT<="0010000";
WHEN124=>DIGIT<="0000011";WHEN125=>DIGIT<="0000101";
WHEN126=>DIGIT<="0000110";WHEN127=>DIGIT<="0001000";
WHEN128=>DIGIT<="0000101";WHEN129=>DIGIT<="0000101";
WHEN130=>DIGIT<="0000101";WHEN131=>DIGIT<="0000101";
WHEN132=>DIGIT<="0000101";WHEN133=>DIGIT<="0000101";
WHEN134=>DIGIT<="0000101";WHEN135=>DIGIT<="0000101";
WHEN136=>DIGIT<="0000000";WHEN137=>DIGIT<="0000000";
WHEN138=>DIGIT<="0000000";WHEN139=>DIGIT<="0000000";
WHENOTHERS=>DIGIT<="0000000";
ENDCASE;
CASEDIGITIS
WHEN"0000011"=>ORIGIN<="0";
WHEN"0000101"=>ORIGIN<="0";
WHEN"0000110"=>ORIGIN<="0";
WHEN"0000111"=>ORIGIN<="";
WHEN"0001000"=>ORIGIN<="";
WHEN"0010000"=>ORIGIN<="";
WHEN"0011000"=>ORIGIN<="";
WHEN"0101000"=>ORIGIN<="";
WHEN"0110000"=>ORIGIN<="";
WHEN"1000000"=>ORIGIN<="";
WHENOTHERS=>ORIGIN<="";
ENDCASE;
ENDPROCESS;
ENDSONG;
警示灯总程序:
#include<>
#include
#include<>
#include<>
#include""
#include""
#include""
#include"sys/"
intnum;
staticvoidButton_ISR_Init(void);
staticvoidButton_Irq_Handler(void*context,alt_u32id);
alt_u8segtab[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//0~9段码
staticvoiddisplay(intnum);
//按键初始化
staticvoidButton_ISR_Init(void)
{
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY_BASE,0xff);//允许8个按键中断
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE,0);//清除中断标志寄存器
alt_irq_register(KEY_IRQ,NULL,Button_Irq_Handler);//注册中断
}
staticvoiddisplay(intnum)
{
IOWR_ALTERA_AVALON_PIO_DATA(SEL_BASE,0);//数码管位选
IOWR_ALTERA_AVALON_PIO_DATA(DAT_BASE,segtab[num]);//显示倒计时
usleep(1000);
}
/*------------------------------------------------------------------
***********************按键中断处理函数****************************
*-----------------------------------------------------------------*/
staticvoidButton_Irq_Handler(void*context,alt_u32id)
{
inti;
for(i=0;i<9;i++)
{
num=9-i;
display(num);
IOWR_ALTERA_AVALON_PIO_DATA(A_BASE,1);//蜂鸣器响起
IOWR_ALTERA_AVALON_PIO_DATA(LED1_BASE,0);
IOWR_ALTERA_AVALON_PIO_DATA(LED2_BASE,1);
usleep(500000);
IOWR_ALTERA_AVALON_PIO_DATA(LED2_BASE,0);
usleep(500000);
}
IOWR_ALTERA_AVALON_PIO_DATA(A_BASE,0);//蜂鸣器关闭
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE,0);
num=0;
display(num);
}
intmain(void)
{
printf("Begin!
\n");
Button_ISR_Init();//按键中断初始化
while
(1)
{
usleep(100000);
IOWR_ALTERA_AVALON_PIO_DATA(LED1_BASE,1);
IOWR_ALTERA_AVALON_PIO_DATA(LED2_BASE,0);
num=0;
display(num);
}
return0;
}
六、设计结果
按键未按下时,处于初始状态:
LED1亮,LED2灭,数码管显示为0,蜂鸣器未启动;按键按下之后,LED1灭,LED2闪烁,数码管进入9秒倒计时并且蜂鸣器响;9秒后恢复初始状态。
七、设计问题
设计中遇到了不少问题:
一开始因为延迟原因使得蜂鸣器音乐间断,后来将延迟时间缩短后问题解决;
然后在数码管动态显示时,也存在延时问题,按下按键后数码管在一秒后才进入倒计时,修改程序后问题解决;
八、心得感受
通过本次设计,我们更加熟悉C语言和SOPC,也在自己动手设计中发现了平时所没遇到的很多问题,包括硬件和软件方面的,有一部分是粗心,有一部分确实是不够了解这门技术;因此在设计过程中,我们不断和其他小伙伴探讨后解决了问题,并从他们那里学到了不少东西。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- SOPC 课程设计 实验 报告