源码:
module FenPing
#(
parameter N=10,
parameter M=N/2
)
(
input clk,
input rst_n,
output ad_o,
output [3:0]ad_o1
);
reg [3:0] cont;
reg vs;
always@(posedge clk)
begin
if(~rst_n)
cont<=0;
else if(cont==N-1)
cont<=0;
else
cont<=cont+1'b1;
end
always@(posedge clk)
begin
if(~rst_n)
vs<=1;
else if(cont==0)
vs<=1;
else if(cont==M)
vs<=0;
end
assign ad_o=vs;
assign ad_o1=cont;
endmodule
激励:
`timescale 1ns/1ns
module FenPing_tp();
reg clk;
reg rst_n;
wire ad_o;
wire ad_o1;
parameter N=10;
parameter M=N/2;
initial
begin
rst_n=0;
#1000 rst_n=1;
#10000 $stop;
end
initial
begin
clk=0;
end
always #10 clk<=~clk;
FenPing #(
.N(N),
.M(M)
)FenPing_out(
.clk(clk),
.rst_n(rst_n),
.ad_o(ad_o),
.ad_o1(ad_o1)
);
endmodule
分频要记得一点是要把频率设置成参数。10M是频率,不是容量。1MHz=100_0000Hz
1s=1000ms=1000_000ns=1_000_000_000us