集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 2739|回复: 6

测试方波的频率计

[复制链接]
奋斗的小孩 发表于 2016-7-12 09:23:24 | 显示全部楼层 |阅读模式
module pinlvji (clk, rst_n, wave, zhankongbi, pinlv);

        input clk;
        input rst_n;
        input wave;
       
        output reg [6:0] zhankongbi;
        output reg [19:0] pinlv;
       
        reg [25:0] t_low_count;
        reg [25:0] t_high_count;
       
        reg [25:0] t_low;
        reg [25:0] t_high;
       
        reg state;
       
        always @ (*)
                begin
                        zhankongbi = 100*t_high/(t_high + t_low);
                        pinlv = 1_000_000_000/(t_high*10 + t_low*10);
                end
       
        always @ (posedge clk)
                begin
                        if (rst_n == 0)
                                begin
                                        t_low <= 0;
                                        t_high <= 0;
                                        t_low_count <= 0;
                                        t_high_count <= 0;
                                        state <= 0;
                                end
                        else
                                begin
                                        case (state)
                                                0 : begin
                                                                if (wave == 1)
                                                                        begin
                                                                                t_high_count <= t_high_count + 1;
                                                                                state <= 0;
                                                                        end
                                                                else
                                                                        begin
                                                                                t_high <= t_high_count;
                                                                                t_high_count <= 0;
                                                                                state <= 1;
                                                                        end
                                                        end
                                               
                                                1 : begin
                                                                if (wave == 0)
                                                                        begin
                                                                                t_low_count <= t_low_count + 1;
                                                                                state <= 1;
                                                                        end
                                                                else
                                                                        begin
                                                                                t_low_count <= 0;
                                                                                t_low <= t_low_count;
                                                                                state <= 0;
                                                                        end
                                                        end
                                       
                                                default : state <= 0;
                                               
                                        endcase
                                end
                end


endmodule
 楼主| 奋斗的小孩 发表于 2016-7-12 09:24:01 | 显示全部楼层
有什么问题,留言或者联系奋斗的小孩QQ:746833924
辉煌 发表于 2016-9-8 13:43:02 | 显示全部楼层
测试方波的频率计
zxopen08 发表于 2016-9-18 15:31:56 | 显示全部楼层
测试方波的频率计
辉煌 发表于 2016-9-20 15:19:43 | 显示全部楼层
测试方波的频率计
4798345 发表于 2017-3-11 09:13:00 | 显示全部楼层
感谢楼主分享
fpga_feixiang 发表于 2023-11-21 14:18:56 | 显示全部楼层
6                        
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

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

QQ|小黑屋|手机版|Archiver|集成电路技术分享 ( 京ICP备20003123号-1 )

GMT+8, 2024-5-3 20:35 , Processed in 0.071858 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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