不用分频器的方式点亮六个数码管
为了达到六个数码管同时被点亮的效果,则要使数码管位选信号变化频率在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 regsel;
output regseg;
reg 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;//计数频率约为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
抱歉,上面的程序不够完善,可以设置一个中间参数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 regsel;
output regseg;
reg 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;//计数频率约为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 好 不错 谢谢楼主分享! 谢谢楼主分享! 顶~~~~~~~~~~~~~~~~~~
页:
[1]