我想设计一个0-999之间的任意整数分频器, 分频数count由按键输入对CLK进行分频,下面是我写的一部分程序
reg[15:0] count ; //按键输入要分频的数字
reg[15:0]countx; //计数器, 对CLK进行计数, 满足countx==count时输出翻转)
(num[]等数字是输出到七段数码管作为显示用的,显示的分频数与实际分频相差1)
always @(posedge keyclk) //按键输入处理
5'b00100: //count的百位数+1, 到9时回到0
begin
if(num[2]==9)
begin
num[2]<=0;
count<=count-900;
end
else
begin
num[2]<=num[2]+1;
count<=count+100;
end
end
5'b00010: // count的十位数+1
begin
if(num[1]==9)
begin
num[1]<=0;
count<=count-90;
end
else
begin
num[1]<=num[1]+1;
count<=count+10;
end
end
5'b00001: //count的个位数+1
begin
if(num[0]==9)
begin
num[0]<=0;
count<=count-9;
end
else
begin
num[0]<=num[0]+1;
count<=count+1;
end
end
default:
begin
count<=0;
end
endcase
always @(posedge clk)
if(countx==count)
outdata<=~outdata; //计数满, 输出翻转
countx<=0; //计数器清零
else
countx<=countx+1;
程序编译没有错误, 但是下载到芯片的时候好像countx==count不起作用, 输出的频率总是2分频
请问各位大侠, 怎么样设计一个任意整数分频器? 有甚么技巧?
求教! 急啊
你这个程序如果count=n的话,结果实现的是2n倍的分频。
因为你每个 n 翻转一次,周期就是 2n 嘛
always @(posedge clk)
if(countx==count)
outdata<=~outdata; //计数满, 输出翻转
countx<=0; //计数器清零
else
countx<=countx+1;
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |