|
发表于 2009-11-2 16:23:27
|
显示全部楼层
module pulse_modulate();
reg clk;
reg pulse;
reg rst_n;
wire pulse_out;
initial begin
clk <= 0;
pulse <= 0;
forever #5 clk <= ~clk;
end
initial begin
rst_n <= 0;
#100 rst_n <= 1;
end
always begin
repeat(5)
@(posedge clk);
pulse <= 1;
@(posedge clk);
pulse <= 0;
end
pulse p1(
.clk(clk),
.rst_n(rst_n),
.pulse_in(pulse),
.pulse_out(pulse_out)
);
endmodule
module pulse(
input clk,
input rst_n,
input pulse_in,
output pulse_out
);
reg [ 2: 0] shift;
always@(posedge clk or negedge rst_n) begin
if (~rst_n) shift <= 0;
else if (pulse_in) shift <= 3'b111;
else shift <= {1'b0,shift[2:1]};
end
assign pulse_out = shift[0];
endmodule |
|