使用Quartus-II 9.1SP2 + ModelSim 6.5b-Aletra + Altera DE2-115 FPGA開發平台,設計 Monostable (One_Shor) 為例(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 LEDG[4]=clk1;
//module delayed_monostable(
// input clk,
// input reset,
// input trigger,
// output pulse
delayed_monostable(clk1,SW[0],KEY[0],LEDG[0]);
//module oneshot_monostable(
// input clk,
// input reset,
// input trigger,
// output reg pulse = 0
oneshot_monostable(clk1,SW[0],KEY[1],LEDG[1]);
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 LEDG[4]=clk1;
//module delayed_monostable(
// input clk,
// input reset,
// input trigger,
// output pulse
delayed_monostable(clk1,SW[0],KEY[0],LEDG[0]);
//module oneshot_monostable(
// input clk,
// input reset,
// input trigger,
// output reg pulse = 0
oneshot_monostable(clk1,SW[0],KEY[1],LEDG[1]);
endmodule
//1 HZ CLOCK GENERATOR
module Clock_1Hz(clk, reset, clk_1Hz);
input clk, reset;
output clk_1Hz;
reg clk_1Hz = 1'b0;
reg [27:0] counter;
always@(negedge reset or posedge clk)
begin
if (!reset)
begin
clk_1Hz <= 0;
counter <= 0;
end
else
begin
counter <= counter + 1;
if ( counter == 25_000_000)
begin
counter <= 0;
clk_1Hz <= ~clk_1Hz;
end
end
end
endmodule
module delayed_monostable(
input clk,
input reset,
input trigger_n,
output pulse
);
parameter DELAY_WIDTH = 5;
parameter SIGNAL_WIDTH = 15;
wire dly;
oneshot_monostable #(.PULSE_WIDTH(DELAY_WIDTH)) delay(
.clk(clk),
.reset(reset),
.trigger_n(trigger_n),
.pulse(dly)
);
wire trig = ~dly;
oneshot_monostable #(.PULSE_WIDTH(SIGNAL_WIDTH)) signal(
.clk(clk),
.reset(reset),
.trigger_n(trigger_n),
.pulse(pulse)
);
endmodule
module oneshot_monostable(
input clk,
input reset,
input trigger_n,
output reg pulse = 0
);
parameter PULSE_WIDTH = 5;
reg [4:0] count = 0;
wire count_rst = reset | (count == PULSE_WIDTH);
always @ (negedge trigger_n, posedge count_rst) begin
if (count_rst) begin
pulse <= 1'b0;
end else begin
pulse <= 1'b1;
end
end
always @ (posedge clk, posedge count_rst) begin
if(count_rst) begin
count <= 0;
end else begin
if(pulse) begin
count <= count + 1'b1;
end
end
end
endmodule
沒有留言:
張貼留言