仿真正确,程序如下 求大神解答
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 18:29:23 12/18/2013
// Design Name:
// Module Name: fdiv
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module fdiv(f_1khz,f_2hz,clk,rset);
input clk; //时钟源频率50MHZ
input rset;
output f_1khz,f_2hz;
reg f_1khz,f_2hz;
reg [13:0]CNT1;
reg [9:0]CNT2;
always@(posedge clk or posedge rset) //50MHZ分频得到1KHZ
begin
if(rset) begin CNT1<=0;end
else
//if(CNT1<49)
if(CNT1<49999)
begin
CNT1<=CNT1+1;
f_1khz<=1'b0;
end
else begin
CNT1<=0;
f_1khz<=1'b1;
end
end
always@(posedge f_1khz) //1KHZ分频得到50HZ
begin
if(rset) begin CNT2<=0;end
if(CNT2<49)
//if(CNT2<4)
begin
CNT2<=CNT2+1;
f_2hz<=1'b0;
end
else begin
CNT2<=0;
f_2hz<=1'b1;
end
end
endmodule