集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 3691|回复: 6

不用分频器的方式点亮六个数码管

[复制链接]
打铁小肥罗 发表于 2016-7-31 22:12:43 | 显示全部楼层 |阅读模式
为了达到六个数码管同时被点亮的效果,则要使数码管位选信号变化频率在1000hz左右,也即sel的变化频率在1000hz左右

为了使频率达到1000hz,好多同学选择了用分频器的方式,当然这种方法得到的是准确的1000hz。我用了另外一种方式,也可以点亮六个数码管,虽然频率不是准确的1000hz,但却很方便。

设置一个计数器【31:0】count
这个计数器的最低位count【0】它的计数累加频率就是时钟频率50mhz
而第2位count【1】的累加频率为(50m/2^1)hz
它的第N+1位的计数频率为(50m/2^N)hz
由此可的
第17位count【16】的频率约为760hz,也可以达到点亮数码管的效果



下面附上程序供大家验证

module smg(clk,rst_n,seg,sel);
        input clk;
        input rst_n;
       
        output reg[2:0]sel;
        output reg[7:0]seg;
        reg [31:0]count;
       
       
       
        always@(posedge clk or negedge rst_n)
                begin
                        if(!rst_n)
                                begin
                                        seg<=8'b1111_1111;
                                        sel<=3'b111;
                                        count<=0;
                                end
                        else
                                begin
                                        count<=count+1;
                                        sel<=count[31:16];//计数频率约为760hz
                                        case(sel)
                                        0:begin seg<=8'b1111_1001;end
                                        1:begin seg<=8'b1010_0100;end
                                        2:begin seg<=8'b1011_0000;end
                                        3:begin seg<=8'b1001_1001;end
                                        4:begin seg<=8'b1001_0010;end
                                        5:begin seg<=8'b1000_0010;end
                                        default:begin sel<=0;end
                                        endcase
                                end
                end




endmodule

 楼主| 打铁小肥罗 发表于 2016-8-2 14:46:28 | 显示全部楼层
抱歉,上面的程序不够完善,可以设置一个中间参数B,令计数器count以B为单位累加,达到更精确的频率值。f_out=(f_clk/2^n)*B。
取f_out=1000hz,f_clk=50000000hz,n=28
B=5369,所以程序为

module smg(clk,rst_n,seg,sel);
        input clk;
        input rst_n;
       
        output reg[2:0]sel;
        output reg[7:0]seg;
        reg [31:0]count;
       
        parameter B=5369;
       
       
       
        always@(posedge clk or negedge rst_n)
                begin
                        if(!rst_n)
                                begin
                                        seg<=8'b1111_1111;
                                        sel<=3'b111;
                                        count<=0;
                                end
                        else
                                begin
                                        count<=count+B;
                                        sel<=count[31:28];//计数频率约为1khz
                                        case(sel)
                                        0:begin seg<=8'b1111_1001;end
                                        1:begin seg<=8'b1010_0100;end
                                        2:begin seg<=8'b1011_0000;end
                                        3:begin seg<=8'b1001_1001;end
                                        4:begin seg<=8'b1001_0010;end
                                        5:begin seg<=8'b1000_0010;end
                                        default:begin sel<=0;end
                                        endcase
                                end
                end




endmodule
芙蓉王 发表于 2016-8-3 11:33:53 | 显示全部楼层
                           好
Adamancy 发表于 2016-8-10 15:58:11 | 显示全部楼层
                  不错
大鹏 发表于 2018-8-16 21:22:09 | 显示全部楼层
谢谢楼主分享!
大鹏 发表于 2018-8-18 20:15:07 | 显示全部楼层
谢谢楼主分享!
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

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

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

GMT+8, 2024-6-17 21:51 , Processed in 0.063279 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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