集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1041|回复: 2

FPGA时钟问题请教

[复制链接]
luyaker 发表于 2012-8-20 21:06:07 | 显示全部楼层 |阅读模式
always@(posedge clk),这个clk可以是始终以外的信号吗?
我用这种clk测频率,发现结果不对。具体程序如下
module cnt(clk,gate,cntout);

input clk;
input gate;
output[31:0] cntout;

reg[31:0] cnt;
reg[31:0] cntout;
reg gatebuf;

always@(posedge clk)
begin
        gatebuf<=gate;
end

always@(posedge clk)
begin
        if((gate==1'b1)&&(gatebuf==1'b0))
                begin
                        cnt<=32'd1;
                end
        else if((gate==1'b0)&&(gatebuf==1'b1))
                begin
                        cntout<=cnt;
                end
       
        else if(gatebuf==1'b1)
        begin
                cnt<=cnt+32'd1;
        end
end


endmodule

其中clk是被测信号,gate是门控信号,cnt_out是输出。
多谢!
bostong 发表于 2012-8-21 11:16:23 | 显示全部楼层
用被检测信号来作为时钟不是很好;
按照你的设想与方法:我认为写法可以是:
always@(posedge clk)
      begin
      gatebuf <= gate;
      if(1'b1==gatebuf)
            begin
           cnt_out<= cnt_out + 1;
            if( cnt_out==32'hffffffff)
            begin
             cnt_out<=32'hffffffff
            end
      else
             cnt_out <= 0;
      end
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-6-26 07:51 , Processed in 0.086910 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表