使用Quartus-II 9.1SP2 + ModelSim 6.5b-Aletra + Altera DE2-115 FPGA開發平台,設計 Ring Counter 為例(FPGA開發平台)
module DE2_115 (SW, LEDR, LEDG , CLOCK_50 ,KEY ,HEX0 ,HEX1 ,HEX2,HEX3,HEX4 ,HEX5 ,HEX6,HEX7, GPIO );
input [17:0] SW; // toggle switches
input [7:0] KEY; // Push bottom
input CLOCK_50; //Clock 27MHz , 50Mhz
output [17:0] LEDR; // red LEDS
output [8:0] LEDG; // green LEDs
output [6:0] HEX0,HEX1,HEX2,HEX3; //7-segment display
output [6:0] HEX4,HEX5,HEX6,HEX7; //7-segment display
inout [35:0] GPIO;
assign HEX0=7'b111_1111;
assign HEX1=7'b111_1111;
assign HEX2=7'b111_1111;
assign HEX3=7'b111_1111;
assign HEX4=7'b111_1111;
assign HEX5=7'b111_1111;
assign HEX6=7'b111_1111;
assign HEX7=7'b111_1111;
wire clk1;
//module Clock_1Hz(clk, reset, clk_1Hz);
//input clk, reset;
//output clk_1Hz;
Clock_1Hz(CLOCK_50,KEY[2],clk1);
assign LEDR[17]=clk1;
//ring_counter #(parameter WIDTH=16)
// input clk,
// input rst_n,
// output reg [WIDTH-1:0] out
ring_counter(clk1,KEY[0],LEDR[15:0]);
endmodule
input [7:0] KEY; // Push bottom
input CLOCK_50; //Clock 27MHz , 50Mhz
output [17:0] LEDR; // red LEDS
output [8:0] LEDG; // green LEDs
output [6:0] HEX0,HEX1,HEX2,HEX3; //7-segment display
output [6:0] HEX4,HEX5,HEX6,HEX7; //7-segment display
inout [35:0] GPIO;
assign HEX0=7'b111_1111;
assign HEX1=7'b111_1111;
assign HEX2=7'b111_1111;
assign HEX3=7'b111_1111;
assign HEX4=7'b111_1111;
assign HEX5=7'b111_1111;
assign HEX6=7'b111_1111;
assign HEX7=7'b111_1111;
wire clk1;
//module Clock_1Hz(clk, reset, clk_1Hz);
//input clk, reset;
//output clk_1Hz;
Clock_1Hz(CLOCK_50,KEY[2],clk1);
assign LEDR[17]=clk1;
//ring_counter #(parameter WIDTH=16)
// input clk,
// input rst_n,
// output reg [WIDTH-1:0] out
ring_counter(clk1,KEY[0],LEDR[15:0]);
endmodule
module ring_counter #(parameter WIDTH=16)
(
input clk,
input rst_n,
output reg [WIDTH-1:0] out
);
integer i;
always @ (posedge clk) begin
if (!rst_n)
out <= 1;
else begin
out[WIDTH-1] <= out[0];
for (i = 0; i < WIDTH-1; i=i+1) begin
out[i] <= out[i+1];
end
end
end
endmodule
沒有留言:
張貼留言