# 4 bit Counter 開發板示範 - PowerPoint PPT Presentation

1 / 6

4 bit Counter 開發板示範. 主程式. `timescale 1ns / 1ps module count_4bit ( input clk, input reset, output [3:0] q ); reg [3:0] counter; wire clkm; reg [31:0] divider; // 除頻電路 always@( posedge clkm , negedge reset ) begin if ( ! reset )

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

4 bit Counter 開發板示範

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

## 4 bit Counter開發板示範

### 主程式

`timescale 1ns / 1ps

module count_4bit(

input clk,

input reset,

output [3:0] q

);

reg [3:0] counter;

wire clkm;

reg [31:0] divider;

//除頻電路

always@( posedge clkm, negedge reset )

begin

if ( ! reset )

counter <= 4'b0000;

else

counter <= counter + 1;

end assign q = counter;

endmodule

### 除頻電路

//除頻電路------------------------------------------------------

always@(posedge clk or negedge reset )

begin

if ( ! reset )

divider <= 32'h0000_0000 ;

else

divider <= divider + 1;

end

assign clkm = divider[25]; // 40M/2^25=0.8388 sec

### 步驟

• 建新專案(指定元件編號)

• 編輯原始程式

• 語法檢查

• 行為模擬

• 指定接腳

• 實作(implement)

• 產生燒錄檔(.bit )

• 下載(燒錄)、執行

### .ucf(xc3s200a.ucf)

• user constraint file

(使用者限定(制)檔)

NET "reset" LOC = K5;

NET "clk" LOC = P9;

#--------------------------

NET "led<0>" LOC = J14;

NET "led<1>" LOC = H14;

NET "led<2>" LOC = K16;

NET "led<3>" LOC = J16;

NET "led<4>" LOC = K15;

NET "led<5>" LOC = K14;

NET "led<6>" LOC = J12;

NET "led<7>" LOC = J13;

#NET "dip<0>" LOC = E6;

#NET "dip<1>" LOC = F7;

#NET "dip<2>" LOC = F9;

#NET "dip<3>" LOC = F10;

#--------------------------

#NET "btn<0>" LOC = K12;

#NET "btn<1>" LOC = K11;

#NET "btn<2>" LOC = J11;

#NET "btn<3>" LOC = J10;

.........................

..........................