这是基于微相的ZYNQ 7020开发板的学习资料,主要是使用由vivado软件提供的IP内核中的时钟向导(clocking wizard)使用的是MMCM(混合模式时钟管理)来产生3个不同频率的时钟,以此来学习配置一个IP核的过程。由IP模块产生3中不同时钟,然后由于频率不同,使其计数到相同数值50_000_000用来产生0.5s,1s,以及2秒的时钟用来控制LED灯。以下是自己写的关于这次的代码
`timescale 1ns / 1ps
//
// Company:
// Engineer:
//
// Create Date: 2024/07/13 19:15:48
// Design Name:
// Module Name: pll_test
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
module pll_test(
input wire clk,
input wire rst_n,
output wire [2:0] led
);
parameter CNT_MAX = 50_000_000 - 1;
parameter CLK1_FREQ = 25_000_000;
parameter CLK2_FREQ = 50_000_000;
parameter CLK3_FREQ = 100_000_000;
reg [27:0] times [2:0];//定义3个计数器
wire [2:0] clk_out;
wire locked;
// Instantiate clock module
clock inst_clock (
.clk_out1(clk_out[0]), // output clk_out1 25M
.clk_out2(clk_out[1]), // output clk_out2 50M
.clk_out3(clk_out[2]), // output clk_out3 100M
.reset(~rst_n), // input reset
.locked(locked), // output locked
.clk_in(clk) // input clk_in
);
// Clock process for each clk_out
genvar i;
generate
for (i = 0; i < 3; i = i + 1) begin : gen_clock
always @(posedge clk_out[i] or negedge rst_n) begin
if (~rst_n) begin
times[i] <= 'd0;
end
else if (locked == 1'b1) begin
if (times[i] == CNT_MAX) begin
times[i] <= 'd0;
end
else begin
times[i] <= times[i] + 1;
end
end
else begin
times[i] <= 'd0;
end
end
end
endgenerate
// LED output logic
assign led[0] = (times[0] > CNT_MAX / 2) ? 1'b1 : 1'b0;
assign led[1] = (times[1] > CNT_MAX / 2) ? 1'b1 : 1'b0;
assign led[2] = (times[2] > CNT_MAX / 2) ? 1'b1 : 1'b0;
endmodule
使用生成语句generate来整合3个计数完全相同的代码,减少了代码量,但实现功能基本相同。