1. 程式人生 > >FPGA學習筆記(貳)--- 流水燈

FPGA學習筆記(貳)--- 流水燈

tle 晶振 定義 -1 min itl dual color lan

平臺:FPGA黑金開發板 AX301

技術分享

開發環境:Quartus Prime Version 17.0.0 Build 595 04/25/2017 Standard Edition

技術分享

引腳配置:鼠標托拉 Node Name 項到引腳圖即可

技術分享

註意事項新建工程:Set Up Top-Level Entity 名字要對應

技術分享

註意事項引腳復用:Assignments-->Device-->Device and Pin Options...-->Dual-Purpose pins-->nCEO -->Use as regular I/O

nCEO:Specifies how the nCEO pin should be used when the device is operating in user mode after configuration is complete. The nCEO pin can be reserved as dedicated nCEO programming pin or a regular I/O pin.

技術分享

我的Top-Level:

 1 module MyLED(CLK, RSTn, Run_LED);
 2 
 3     input CLK;
 4      input
RSTn; 5 output [3:0]Run_LED;//I/O口的說明:input[信號位寬]端口名 6 7 /**********************************/ 8 9 wire [3:0]Run_LED;//定義輸出信號 10 11 Run_LED U1(.CLK( CLK ), .RSTn( RSTn ), .LED_Out( Run_LED ) ); 12 13 /***********************************/ 14 15 assign
Run_LED = Run_LED;//內部信號聲明和功能定義 16 17 /**********************************/ 18 19 endmodule

我的Run_LED:

 1 module Run_LED(CLK, RSTn, LED_Out);
 2     
 3      input CLK;
 4      input RSTn;
 5      output [3:0]LED_Out;
 6      
 7      /**************************/
 8      
 9      parameter T1MS = 16d49_999; //DB4CE15使用的晶振為50MHz,50M*0.001-1=49_999
10      
11      /**************************/
12      
13      reg [15:0]Count1;
14      
15      always @ ( posedge CLK  or negedge RSTn )//1ms計數器
16          if( !RSTn )
17               Count1 <= 16d0;
18           else if( Count1 == T1MS )
19               Count1 <= 16d0;
20           else 
21               Count1 <= Count1 + 1b1;
22 
23     /*****************************************/
24                 
25      reg [9:0]Count_MS;            
26                 
27      always @ ( posedge CLK or negedge RSTn )//100ms計數器
28          if( !RSTn )
29               Count_MS <= 10d0;
30           else if( Count_MS == 10d100 )
31               Count_MS <= 10d0;
32           else if( Count1 == T1MS )
33               Count_MS <= Count_MS + 1b1;
34                 
35      /***************************************/
36      
37      reg [3:0]rLED_Out;
38      
39      always @ ( posedge CLK or negedge RSTn )
40          if( !RSTn )
41               rLED_Out <= 4b1111;
42           else if( Count_MS == 10d100 )
43               begin
44                 
45                   if( rLED_Out == 4b0000 )
46                         rLED_Out <= 4b0001;
47                    else
48                       rLED_Out <= { rLED_Out[2:0], 1b0 };//向左移位1bit操作
49                end
50     
51 /**********************行48左移操作解釋***************************
52 知識點1: reg [n-1:0] rega;   //一個n位的寄存器
53          reg mema [n-1:0];   //一個由n個1位寄存器構成的存儲器組
54 
55 知識點2: 位拼接運算符(Concatation)     {}
56 
57 解釋:如果rLED_Out不是4‘b0000 就取rLED_Out後三位,並且與1‘b0合並成一個新的四位
58 
59 ****************************************************************/
60      
61      assign LED_Out = rLED_Out;
62      
63      /*****************************/
64 endmodule

感謝:http://www.heijin.org/forum.php?mod=viewthread&tid=31002&pid=320054&page=1&extra=#pid320054

FPGA學習筆記(貳)--- 流水燈