|  | 
 
 发表于 2015-8-17 23:11:46
|
显示全部楼层 
| 回复 4# tjzcl 你好,那如果通过一个50M的时钟想得到10k,1hz,2.5hz的时钟,代码如下:module ts(clk,rst, clk_10k, clk_1, clk_out);
 input clk;
 input rst;
 output clk_10k;
 output clk_1;
 output clk_out;
 reg clk_10k;
 reg clk_1;
 reg clk_out;
 reg [11:0] n;
 reg [8:0] m;
 reg [1:0]k;
 
 
 
 //-----------------fenpin-----------------------
 
 always@(posedge clk)
 
 begin
 
 if(!rst)
 
 begin
 
 clk_10k <= 1'b0;
 
 n <= 0;
 
 end
 
 
 else
 
 begin
 
 n <= n + 12'd1;
 
 if( n == 12'd2500)
 
 begin
 
 n <= 12'h0;
 
 clk_10k <= ~clk_10k;
 
 end
 
 
 end
 
 
 end
 
 
 always@(posedge clk_10k)
 
 begin
 
 if(!rst)
 
 begin
 
 clk_1 <= 1'b0;
 
 m <= 0;
 
 end
 
 else
 
 
 begin
 
 m <= m + 9'd1;
 
 if( m == 9'd500)
 
 begin
 
 m <= 9'h0;
 
 clk_1 <= ~clk_1;
 
 end
 
 
 end
 
 
 end
 always@( posedge clk_10k)//??
 
 begin
 
 if(!rst)
 
 begin
 
 clk_out <= 1'b0;
 
 k <= 0;
 
 end
 
 else
 
 begin
 
 k <= k + 2'd1;
 
 if( k == 2'd3)
 
 begin
 
 k <= 2'd0;
 
 clk_out <= ~clk_out;
 
 end
 
 
 end
 
 
 end
 
 endmodule
 
 测试代码
 `timescale 1ns/1ns
 module tb1;
 reg clk;
 reg rst;
 wire [11:0]n;
 wire [8:0]m;
 wire [1:0]k;
 wire clk_10k;
 wire clk_1;
 wire clk_out;
 ts i(
 .clk(clk),
 .rst(rst),
 .clk_10k(clk_10k),
 .clk_1(clk_1),
 .clk_out(clk_out)
 );
 initial
 begin
 clk = 0;
 rst = 0;
 #20 rst = 1;
 end
 always
 begin
 #10 clk <= ~clk;
 end
 
 endmodule
 
 
 
 为什么在modelsim仿真的时候只能得到10k的时钟,其他的时钟是高阻态
 | 
 |