sopc課程設(shè)計(jì)實(shí)驗(yàn)報(bào)告_第1頁(yè)
已閱讀1頁(yè),還剩18頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、<p>  SOPC課程設(shè)計(jì)實(shí)驗(yàn)報(bào)告</p><p>  基于SOPC的警示燈設(shè)計(jì)</p><p>  2013電子信息工程3班</p><p>  李婕20134557</p><p>  羅丹妮20134563</p><p>  設(shè)計(jì)目的

2、 </p><p>  熟悉掌握SOPC的基本流程</p><p>  設(shè)計(jì)一個(gè)警示燈并滿足基本要求</p><p>  通過(guò)設(shè)計(jì)發(fā)現(xiàn)問(wèn)題并解決</p><p><b>  設(shè)計(jì)設(shè)備</b></p><p>  1、硬件:PC機(jī)、SOPC-N

3、IOS II EDA/SOPC系統(tǒng)開發(fā)平臺(tái)</p><p>  2、軟件:QUARTUS II、SOPC Builder、NIOS II IDE</p><p><b>  設(shè)計(jì)內(nèi)容</b></p><p>  初始狀態(tài)為紅燈(LED2)熄滅,綠燈(LED1)點(diǎn)亮,數(shù)碼管顯示為0。</p><p>  當(dāng)按鍵按下,紅燈(

4、LED2)閃爍,綠燈(LED1)熄滅,同時(shí)蜂鳴器響起,數(shù)碼管開始倒計(jì)時(shí)9S,此狀態(tài)持續(xù)時(shí)間為9s。</p><p>  9s后,恢復(fù)初始狀態(tài)。</p><p><b>  設(shè)計(jì)步驟</b></p><p>  使用Quartus II建立一個(gè)工程文件和頂層文件;</p><p>  使用SOPC Builder建立一個(gè)簡(jiǎn)

5、單Nios II硬件系統(tǒng)</p><p>  啟動(dòng)SOPC Builder</p><p><b>  指定目標(biāo)FPGA</b></p><p>  添加NiosII內(nèi)核及其他外設(shè)</p><p>  A、添加NiosII、SRAM、JTAG-UART、Avalon總線的IP核</p><p>

6、  B、添加一個(gè)2位的輸入型PIO作為按鍵key</p><p>  C、添加兩個(gè)1位的輸出型PIO作為 led1及l(fā)ed2的輸出端口</p><p>  D、添加一個(gè)1位的輸出型PIO作為蜂鳴器的輸入端口A</p><p>  E、添加一個(gè)3位的輸出型PIO作為數(shù)碼管的位選sel</p><p>  F、添加一個(gè)8位的輸出型PIO作為數(shù)碼管

7、的段選dat</p><p>  4) 指定基地址和中斷優(yōu)先級(jí)</p><p>  5) 設(shè)置NiosII復(fù)位和異常地址</p><p>  6) 編譯生成NiosII系統(tǒng)</p><p>  SOPC Builder行程圖如下:</p><p>  3、在Quartus II中建立一個(gè)蜂鳴器<

8、;/p><p>  1) 用VHDL語(yǔ)言編寫蜂鳴器程序</p><p>  2) 編譯成功后Creat symbol,生成Project sing</p><p>  4、在Quartus II中編譯Nios II硬件系統(tǒng)并生成配置文件</p><p>  1) 在Quartus II加入Nios II系統(tǒng)符號(hào)到頂層文件</

9、p><p>  2) 給各端口加入輸入輸出引腳,并重命名</p><p><b>  3) 設(shè)置參數(shù)</b></p><p>  4) 編譯頂層文件</p><p><b>  5) 分配管腳</b></p><p><b>  6) 再次編譯<

10、;/b></p><p>  5、在Nios II IDE中建立C/C++工程,編寫用戶程序</p><p><b>  6、編譯用戶程序</b></p><p>  7、下載.SOF至FPGA,運(yùn)行程序,觀察結(jié)果</p><p><b>  五、設(shè)計(jì)程序 </b></p>&l

11、t;p>  蜂鳴器程序(VHDL):</p><p>  LIBRARY IEEE;</p><p>  USE IEEE.STD_LOGIC_1164.ALL;</p><p>  USE IEEE.STD_LOGIC_UNSIGNED.ALL;</p><p>  ENTITY sing1 IS</p><

12、p><b>  PORT(</b></p><p>  CLK:IN STD_LOGIC;</p><p>  p:IN STD_LOGIC;</p><p>  -- DIGIT:BUFFER STD_LOGIC_VECTOR(6 DOWNTO 0);</p><p>  SPEAKER:OUT STD_LOG

13、IC);</p><p>  END ENTITY;</p><p>  ARCHITECTURE SONG OF sing1 IS</p><p>  SIGNAL DRIVER,ORIGIN:STD_LOGIC_VECTOR(12 DOWNTO 0);</p><p>  SIGNAL COUNTER:INTEGER RANGE 0 TO

14、 140;</p><p>  SIGNAL COUNTER1:INTEGER RANGE 0 TO 3;</p><p>  SIGNAL COUNTER2:INTEGER RANGE 1 TO 10000000;</p><p>  SIGNAL DIGIT :STD_LOGIC_VECTOR(6 DOWNTO 0);</p><p>

15、  SIGNAL COUNT :STD_LOGIC_VECTOR(1 DOWNTO 0); </p><p>  SIGNAL CARRIER,CLK_4MHZ,CLK_4HZ:STD_LOGIC;</p><p><b>  BEGIN</b></p><p>  PROCESS(CLK)</p><p><b

16、>  BEGIN</b></p><p>  IF CLK'EVENT AND CLK='1' THEN</p><p>  IF COUNTER1=1 THEN CLK_4MHZ<='1';</p><p>  COUNTER1<=2;</p><p>  ELSIF C

17、OUNTER1=3 THEN CLK_4MHZ<='0';</p><p>  COUNTER1<=0;</p><p>  ELSE COUNTER1<=COUNTER1+1;</p><p><b>  END IF;</b></p><p>  IF COUNTER2=500000

18、0 THEN CLK_4HZ<='1';</p><p>  COUNTER2<=5000001;</p><p>  ELSIF COUNTER2=10000000 THEN CLK_4HZ<='0';</p><p>  COUNTER2<=1;</p><p>  ELSE COU

19、NTER2<=COUNTER2+1;</p><p><b>  END IF;</b></p><p><b>  END IF;</b></p><p>  END PROCESS;</p><p>  PROCESS(CLK_4MHZ)</p><p><b

20、>  BEGIN</b></p><p>  IF CLK_4MHZ'EVENT AND CLK_4MHZ='1' THEN</p><p>  IF DRIVER="1111111111111"THEN</p><p>  CARRIER<='1';</p><

21、p>  DRIVER<=ORIGIN;</p><p><b>  ELSE</b></p><p>  DRIVER<=DRIVER+1;</p><p>  CARRIER<='0';</p><p><b>  END IF;</b></p>

22、<p><b>  END IF;</b></p><p>  END PROCESS;</p><p>  PROCESS(CARRIER)</p><p><b>  BEGIN</b></p><p>  if(p='1')then</p><

23、p>  IF CARRIER'EVENT AND CARRIER='1' THEN</p><p>  COUNT<=COUNT+1;</p><p>  IF COUNT="00"THEN</p><p>  SPEAKER<='1';</p><p><b

24、>  ELSE</b></p><p>  SPEAKER<='0';</p><p><b>  END IF;</b></p><p><b>  END IF;</b></p><p><b>  end if;</b></p

25、><p>  END PROCESS;</p><p>  PROCESS(CLK_4HZ)</p><p><b>  BEGIN</b></p><p>  IF CLK_4HZ'EVENT AND CLK_4HZ='1' THEN</p><p>  IF COUNTER

26、=140 THEN</p><p>  COUNTER<=0;</p><p>  ELSE COUNTER<=COUNTER+1;</p><p><b>  END IF;</b></p><p><b>  END IF;</b></p><p>  CAS

27、E COUNTER IS</p><p>  WHEN 0 =>DIGIT<="0000011"; WHEN 1 =>DIGIT<="0000011";</p><p>  WHEN 2 =>DIGIT<="0000011"; WHEN 3 =>

28、DIGIT<="0000011";</p><p>  WHEN 4 =>DIGIT<="0000101"; WHEN 5 =>DIGIT<="0000101";</p><p>  WHEN 6 =>DIGIT<="0000101";

29、 WHEN 7 =>DIGIT<="0000110";</p><p>  WHEN 8 =>DIGIT<="0001000"; WHEN 9 =>DIGIT<="0001000";</p><p>  WHEN 10 =>DIGIT<="0

30、001000"; WHEN 11 =>DIGIT<="0010000";</p><p>  WHEN 12 =>DIGIT<="0000110"; WHEN 13 =>DIGIT<="0001000";</p><p>  WHEN 14 =>

31、;DIGIT<="0000101"; WHEN 15 =>DIGIT<="0000101";</p><p>  WHEN 16 =>DIGIT<="0101000"; WHEN 17 =>DIGIT<="0101000";</p><p

32、>  WHEN 18 =>DIGIT<="0101000"; WHEN 19 =>DIGIT<="1000000";</p><p>  WHEN 20 =>DIGIT<="0110000"; WHEN 21 =>DIGIT<="0101000"

33、;</p><p>  WHEN 22 =>DIGIT<="0011000"; WHEN 23 =>DIGIT<="0101000";</p><p>  WHEN 24 =>DIGIT<="0010000"; WHEN 25 =>DIGIT<=&

34、quot;0010000";</p><p>  WHEN 26 =>DIGIT<="0010000"; WHEN 27 =>DIGIT<="0010000";</p><p>  WHEN 28 =>DIGIT<="0010000"; WHEN 2

35、9 =>DIGIT<="0010000";</p><p>  WHEN 30 =>DIGIT<="0000011"; WHEN 31 =>DIGIT<="0000000";</p><p>  WHEN 32 =>DIGIT<="0010000"

36、;; WHEN 33 =>DIGIT<="0010000";</p><p>  WHEN 34 =>DIGIT<="0010000"; WHEN 35 =>DIGIT<="0011000";</p><p>  WHEN 36 =>DIGIT<=

37、"0000111"; WHEN 37 =>DIGIT<="0000111";</p><p>  WHEN 38 =>DIGIT<="0000110"; WHEN 39 =>DIGIT<="0000110";</p><p>  WHEN

38、40 =>DIGIT<="0000101"; WHEN 41 =>DIGIT<="0000101";</p><p>  WHEN 42 =>DIGIT<="0000101"; WHEN 43 =>DIGIT<="0000110";</p>

39、<p>  WHEN 44 =>DIGIT<="0001000"; WHEN 45 =>DIGIT<="0001000";</p><p>  WHEN 46 =>DIGIT<="0010000"; WHEN 47 =>DIGIT<="001000

40、0";</p><p>  WHEN 48 =>DIGIT<="0000011"; WHEN 49 =>DIGIT<="0000011";</p><p>  WHEN 50 =>DIGIT<="0001000"; WHEN 51 =>DIGI

41、T<="0001000";</p><p>  WHEN 52 =>DIGIT<="0000110"; WHEN 53 =>DIGIT<="0000101";</p><p>  WHEN 54 =>DIGIT<="0000110";

42、 WHEN 55 =>DIGIT<="0001000";</p><p>  WHEN 56 =>DIGIT<="0000101"; WHEN 57 =>DIGIT<="0000101";</p><p>  WHEN 58 =>DIGIT<="00001

43、01"; WHEN 59 =>DIGIT<="0000101";</p><p>  WHEN 60 =>DIGIT<="0000101"; WHEN 61 =>DIGIT<="0000101";</p><p>  WHEN 62 =>DIG

44、IT<="0000101"; WHEN 63 =>DIGIT<="0000101";</p><p>  WHEN 64 =>DIGIT<="0011000"; WHEN 65 =>DIGIT<="0011000";</p><p>

45、  WHEN 66 =>DIGIT<="0011000"; WHEN 67 =>DIGIT<="0101000";</p><p>  WHEN 68 =>DIGIT<="0000111"; WHEN 69 =>DIGIT<="0000111";<

46、;/p><p>  WHEN 70 =>DIGIT<="0010000"; WHEN 71 =>DIGIT<="0010000";</p><p>  WHEN 72 =>DIGIT<="0000110"; WHEN 73 =>DIGIT<="

47、;0001000";</p><p>  WHEN 74 =>DIGIT<="0000101"; WHEN 75 =>DIGIT<="0000101";</p><p>  WHEN 76 =>DIGIT<="0000101"; WHEN 77 =&

48、gt;DIGIT<="0000101";</p><p>  WHEN 78 =>DIGIT<="0000101"; WHEN 79 =>DIGIT<="0000101";</p><p>  WHEN 80 =>DIGIT<="0000011";

49、 WHEN 81 =>DIGIT<="0000101";</p><p>  WHEN 82 =>DIGIT<="0000011"; WHEN 83 =>DIGIT<="0000011";</p><p>  WHEN 84 =>DIGIT<=&quo

50、t;0000101"; WHEN 85 =>DIGIT<="0000110";</p><p>  WHEN 86 =>DIGIT<="0000111"; WHEN 87 =>DIGIT<="0010000";</p><p>  WHEN 88 =

51、>DIGIT<="0000110"; WHEN 89 =>DIGIT<="0000110";</p><p>  WHEN 90 =>DIGIT<="0000110"; WHEN 91 =>DIGIT<="0000110";</p>&l

52、t;p>  WHEN 92 =>DIGIT<="0000110"; WHEN 93 =>DIGIT<="0000110";</p><p>  WHEN 94 =>DIGIT<="0000101"; WHEN 95 =>DIGIT<="0000110&qu

53、ot;;</p><p>  WHEN 96 =>DIGIT<="0001000"; WHEN 97 =>DIGIT<="0001000";</p><p>  WHEN 98 =>DIGIT<="0001000"; WHEN 99 =>DIGIT<

54、;="0010000";</p><p>  WHEN 100=>DIGIT<="0101000"; WHEN 101=>DIGIT<="0101000";</p><p>  WHEN 102=>DIGIT<="0101000"; WHE

55、N 103=>DIGIT<="0011000";</p><p>  WHEN 104=>DIGIT<="0010000"; WHEN 105=>DIGIT<="0010000";</p><p>  WHEN 106=>DIGIT<="0011000&q

56、uot;; WHEN 107=>DIGIT<="0010000";</p><p>  WHEN 108=>DIGIT<="0001000"; WHEN 109=>DIGIT<="0001000";</p><p>  WHEN 110=>DIGIT&l

57、t;="0000110"; WHEN 111=>DIGIT<="0000101";</p><p>  WHEN 112=>DIGIT<="0000011"; WHEN 113=>DIGIT<="0000011";</p><p>  WH

58、EN 114=>DIGIT<="0000011"; WHEN 115=>DIGIT<="0000011";</p><p>  WHEN 116=>DIGIT<="0001000"; WHEN 117=>DIGIT<="0001000";</p&

59、gt;<p>  WHEN 118=>DIGIT<="0000110"; WHEN 119=>DIGIT<="0001000";</p><p>  WHEN 120=>DIGIT<="0000110"; WHEN 121=>DIGIT<="000

60、0011";</p><p>  WHEN 122=>DIGIT<="0000011"; WHEN 123=>DIGIT<="0010000";</p><p>  WHEN 124=>DIGIT<="0000011"; WHEN 125=>D

61、IGIT<="0000101";</p><p>  WHEN 126=>DIGIT<="0000110"; WHEN 127=>DIGIT<="0001000";</p><p>  WHEN 128=>DIGIT<="0000101";

62、 WHEN 129=>DIGIT<="0000101";</p><p>  WHEN 130=>DIGIT<="0000101"; WHEN 131=>DIGIT<="0000101";</p><p>  WHEN 132=>DIGIT<="00

63、00101"; WHEN 133=>DIGIT<="0000101";</p><p>  WHEN 134=>DIGIT<="0000101"; WHEN 135=>DIGIT<="0000101";</p><p>  WHEN 136=>

64、DIGIT<="0000000"; WHEN 137=>DIGIT<="0000000";</p><p>  WHEN 138=>DIGIT<="0000000"; WHEN 139=>DIGIT<="0000000";</p><p&

65、gt;  WHEN OTHERS=>DIGIT<="0000000";</p><p><b>  END CASE;</b></p><p>  CASE DIGIT IS</p><p>  WHEN "0000011"=>ORIGIN<="0100001001100

66、";</p><p>  WHEN "0000101"=>ORIGIN<="0110000010001";</p><p>  WHEN "0000110"=>ORIGIN<="0111000111110";</p><p>  WHEN "0

67、000111"=>ORIGIN<="1000000101101";</p><p>  WHEN "0001000"=>ORIGIN<="1000100010001";</p><p>  WHEN "0010000"=>ORIGIN<="10010101

68、10010";</p><p>  WHEN "0011000"=>ORIGIN<="1010000100101";</p><p>  WHEN "0101000"=>ORIGIN<="1011000001000";</p><p>  WHEN &q

69、uot;0110000"=>ORIGIN<="1011100011110";</p><p>  WHEN "1000000"=>ORIGIN<="1100010001000";</p><p>  WHEN OTHERS=>ORIGIN<="1111111111111&qu

70、ot;;</p><p><b>  END CASE;</b></p><p>  END PROCESS;</p><p><b>  END SONG;</b></p><p><b>  警示燈總程序:</b></p><p>  #includ

71、e <stdio.h> </p><p>  #include <sys/unistd.h> </p><p>  #include <io.h> </p><p>  #include <string.h> </p><p>  #include "system.h" &l

72、t;/p><p>  #include "altera_avalon_pio_regs.h" </p><p>  #include "alt_types.h" </p><p>  #include "sys/alt_irq.h" </p><p><b>  int num

73、;</b></p><p>  static void Button_ISR_Init(void);</p><p>  static void Button_Irq_Handler(void* context,alt_u32 id);</p><p>  alt_u8 segtab[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,

74、0x7d,0x07,0x7f,0x6f}; //0~9段碼</p><p>  static void display(int num);</p><p><b>  //按鍵初始化</b></p><p>  static void Button_ISR_Init(void)</p><p><b>  {

75、 </b></p><p>  IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY_BASE,0xff); //允許8個(gè)按鍵中斷</p><p>  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE,0); //清除中斷標(biāo)志寄存器</p><p>  alt_irq_register(KEY_IRQ

76、,NULL,Button_Irq_Handler); //注冊(cè)中斷 </p><p><b>  }</b></p><p>  static void display(int num)</p><p><b>  {</b></p><p>  IOWR_ALTERA_AVALON_PIO

77、_DATA(SEL_BASE,0); //數(shù)碼管位選</p><p>  IOWR_ALTERA_AVALON_PIO_DATA(DAT_BASE,segtab[num]); //顯示倒計(jì)時(shí)</p><p>  usleep(1000);</p><p><b>  }</b></p><p>  /*--------

78、---------------------------------------------------------- </p><p>  ***********************按鍵中斷處理函數(shù)****************************</p><p>  *-------------------------------------------------------

79、----------*/ </p><p>  static void Button_Irq_Handler(void* context,alt_u32 id)</p><p><b>  {</b></p><p><b>  int i;</b></p><p>  for(i=0;i<9

80、;i++)</p><p><b>  { </b></p><p><b>  num=9-i;</b></p><p>  display(num); </p><p>  IOWR_ALTERA_AVALON_PIO_DATA(A_BASE, 1);//蜂鳴器響起</p><

81、;p>  IOWR_ALTERA_AVALON_PIO_DATA(LED1_BASE, 0);</p><p>  IOWR_ALTERA_AVALON_PIO_DATA(LED2_BASE, 1);</p><p>  usleep(500000);</p><p>  IOWR_ALTERA_AVALON_PIO_DATA(LED2_BASE, 0);&l

82、t;/p><p>  usleep(500000);</p><p><b>  } </b></p><p>  IOWR_ALTERA_AVALON_PIO_DATA(A_BASE, 0);//蜂鳴器關(guān)閉</p><p>  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE,0); &

83、lt;/p><p><b>  num=0;</b></p><p>  display(num); </p><p><b>  }</b></p><p>  int main(void)</p><p><b>  {</b></p>&

84、lt;p>  printf("Begin!\n");</p><p>  Button_ISR_Init(); //按鍵中斷初始化</p><p><b>  while(1)</b></p><p><b>  {</b></p><p>  usleep(100000

85、);</p><p>  IOWR_ALTERA_AVALON_PIO_DATA(LED1_BASE, 1);</p><p>  IOWR_ALTERA_AVALON_PIO_DATA(LED2_BASE, 0);</p><p><b>  num=0;</b></p><p>  display(num); <

86、;/p><p><b>  }</b></p><p><b>  return 0;</b></p><p><b>  }</b></p><p><b>  六、設(shè)計(jì)結(jié)果</b></p><p>  按鍵未按下時(shí),處于初始狀態(tài):L

87、ED1亮,LED2滅,數(shù)碼管顯示為0,蜂鳴器未啟動(dòng);按鍵按下之后,LED1滅,LED2閃爍,數(shù)碼管進(jìn)入9秒倒計(jì)時(shí)并且蜂鳴器響;9秒后恢復(fù)初始狀態(tài)。</p><p><b>  七、設(shè)計(jì)問(wèn)題</b></p><p>  設(shè)計(jì)中遇到了不少問(wèn)題:</p><p>  一開始因?yàn)檠舆t原因使得蜂鳴器音樂(lè)間斷,后來(lái)將延遲時(shí)間縮短后問(wèn)題解決;</p&g

88、t;<p>  然后在數(shù)碼管動(dòng)態(tài)顯示時(shí),也存在延時(shí)問(wèn)題,按下按鍵后數(shù)碼管在一秒后才進(jìn)入倒計(jì)時(shí),修改程序后問(wèn)題解決;</p><p><b>  八、心得感受</b></p><p>  通過(guò)本次設(shè)計(jì),我們更加熟悉C語(yǔ)言和SOPC,也在自己動(dòng)手設(shè)計(jì)中發(fā)現(xiàn)了平時(shí)所沒遇到的很多問(wèn)題,包括硬件和軟件方面的,有一部分是粗心,有一部分確實(shí)是不夠了解這門技術(shù);因此在設(shè)

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫(kù)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論