本帖最后由 永反倒是 于 2017-12-5 21:46 编辑
设计程序:
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Module Name: clkdiv
// 产生一个波特率9600的16倍频的时钟,9600*16= 153600
// 相当于100MHz的2*326分频,2*50000000/153600=2*326
//////////////////////////////////////////////////////////////////////////////////
module clkdiv(clk100,rstn,clk);
input clk100; //系统时钟
input rstn;
output clk; //采样时钟输出
reg [15:0] cnt;
reg clkout;
assign clk = clkout;
//分频进程,对100Mhz的时钟2*326分频
always @(posedge clk100)
begin
if(!rstn)
begin cnt <= 16'd0; end
else
begin
if(cnt == 16'd324)
begin
clkout <= 1'b1;
cnt <= cnt + 16'd1;
end
else if(cnt == 16'd651)
begin
clkout <= 1'b0;
cnt <= 16'd0;
end
else
begin
cnt <= cnt + 16'd1;
end
end
end
endmodule
仿真程序:
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2017/12/05 18:31:59
// Design Name:
// Module Name: uart_simu
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module uart_simu(
);
reg rstn;
reg clk100;
wire clk;
clkdiv mytest(
.clk100(clk100),
.rstn(rstn),
.clk(clk)
);
initial
begin
rstn = 0; #10;rstn = 1;
clk100 = 0; forever #20 clk100 = ~clk100;
end
endmodule
仿真结果:
|