现在我在vivado中做了一个基于axi总线测量频率的ip核,不知道在sdk中怎么读出频率计数值,
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2019/07/20 11:04:26
// Design Name:
// Module Name: meas_freq
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module meas_freq(
input clk_100M, //100MHz系统时钟
input square ,
output wire [27:0] CNTCLK, //闸门内系统时钟周期计数
output wire [27:0] CNTSQU //闸门内待测方波时钟周期计数
);
parameter GATE_TIME = 28'd99_999_999;//实际闸门计数是99_999_999,仿真时设为10ms
reg square_r0 = 1'b0;
reg square_r1 = 1'b0;
reg square_r2 = 1'b0;
reg square_r3 = 1'b0;
reg [27:0] cnt1 = 28'd0; //产生 1s 的闸门信号的计数器
reg gate = 1'b0; //闸门信号
reg gatebuf = 1'b0; //与方波同步之后的闸门信号
reg gatebuf1 = 1'b0;//同步闸门信号延时一拍
reg [27:0] cnt2 = 28'd0;
reg [27:0] cnt2_r = 28'd0;
reg [27:0] cnt3 = 28'd0;
reg [27:0] cnt3_r = 28'd0;
// reg [27:0] CNTCLK= 28'd0;
// reg [27:0] CNTSQU= 28'd0;
wire square_pose,square_nege;
wire gate_start,gate_end;
//使方波和100MHz时钟同步并捕捉待测方波的边沿
always @ (posedge clk_100M)
begin
square_r0 <= square;
square_r1 <= square_r0;//将外部输入的方波打两拍
square_r2 <= square_r1;
square_r3 <= square_r2;
end
assign square_pose = square_r2 & ~square_r3;
assign square_nege = ~square_r2 & square_r3;
always @ (posedge clk_100M)
begin
IF(cnt1 == GATE_TIME)begin
cnt1 <= 28'd0;
gate <= ~gate;//产生 1s 的闸门信号
end
else begin
cnt1 <= cnt1 + 1'b1;
end
end
always @ (posedge clk_100M )
begin
if(square_pose == 1'b1)begin
gatebuf <= gate;//使闸门信号与待测方波同步,保证一个闸门包含整数个方波周期
end
gatebuf1 <= gatebuf;//将同步之后的闸门信号打一拍,用于捕捉闸门信号的边沿
end
assign gate_start = gatebuf & ~gatebuf1;//表示闸门开始时刻
assign gate_end = ~gatebuf & gatebuf1;//闸门结束时刻
//计数系统时钟周期
always @ (posedge clk_100M)
begin
if(gate_start == 1'b1)begin
cnt2 <= 28'd1;
end
else if(gate_end == 1'b1)begin
cnt2_r <= cnt2;//将所得结果保存在cnt2_r中,并将计数器清零
cnt2 <= 28'd0;
end
else if(gatebuf1 == 1'b1)begin//在闸门内计数系统时钟周期
cnt2 <= cnt2 + 1'b1;end
end
//计数待测方波周期数
always @ (posedge clk_100M )
begin
if(gate_start == 1'b1)begin
cnt3 <= 28'd0;
end
else if(gate_end == 1'b1)begin
cnt3_r <= cnt3;//将所得结果保存在cnt3_r中,并将计数器清零
cnt3 <= 28'd0;
end
else if(gatebuf1 == 1'b1 && square_nege == 1'b1)begin//在闸门内计数待测方波周期数(数闸门内方波的下降沿)
cnt3 <= cnt3 + 1'b1;
end
end
assign CNTCLK = cnt2_r;
assign CNTSQU = cnt3_r;
endmodule
共1条
1/1 1 跳转至页
vivado中自定义IP应用
共1条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】智能可穿戴设备AR/VR如何引领科技新潮流! | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
【有奖活动】震撼来袭!这场直播将直击工程师的心灵! | |
“我想要一部加热台”活动,不花钱赢取开发好工具!活动开始了哦 | |
【有奖活动】伙伴们:您的“需求”解决了吗? |
打赏帖 | |
---|---|
老胖子聊电路--分析一个反馈电路被打赏50分 | |
放大↔震荡被打赏50分 | |
【换取手持数字示波器】RTduino驱动ssd1306+sht31温湿度计被打赏40分 | |
【换取手持数字示波器】称植国产开源TobudOS到雅特力AT32F425被打赏40分 | |
【分享评测,赢取加热台】+Telink-泰凌微电子B91点灯篇被打赏20分 | |
【换取手持数字示波器】+精英板驱动LCD屏被打赏50分 | |
【换取手持数字示波器】+DFR0216全彩灯带WS2812示例分享被打赏50分 | |
【换取手持数字示波器】安装雅特力国产IDE-AT32IDE被打赏30分 | |
【换取手持数字示波器】+DFR0654板卡驱动数码管和串口功能分享被打赏50分 | |
【换取手持数字示波器】+DFPlayerMini模块推喇叭示例分享被打赏50分 |