企业 个人 用户名 密码   忘记密码?
站内 站外
风格设定:
论坛 博客 会展
论坛 博客 会展
 
用VHDL设计的任意频率分频器
作者:haichao    时间:2007-11-12    来源: 
 
      

Sometimes I need to generate a clock at a lower frequency than the main clock driving the FPGA. If the ratio of the frequencies is a power of 2, the logic is easy. If the ratio is an integer N, then a divide-by-N counter is only a little harder. But if the ratio isn't an integer, a little (and I mean a little) math is required.

Note that the new clock will have lots of jitter: there's no escaping that. But it will have no drift, and for some applications that's what counts.

If you have a clock A at frequency a, and want to make a clock B at some lower frequency b (that is, b < a), then something like:

d = 0;
forever {
Wait for clock A.
if (d < 1) {
d += (b/a);
} else {
d += (b/a) - 1; /* getting here means tick for clock B */
}
}


but comparison against zero is easier, so subtract 1 from d:

d = 0;
forever {
Wait for clock A.
if (d < 0) {
d += (b/a);
} else {
d += (b/a) - 1; /* getting here means tick for clock B */
}
}


want an integer representation, so multiply everything by a:

d = 0;
forever {
Wait for clock A.
if (d < 0) {
d += b;
} else {
d += b - a; /* getting here means tick for clock B */
}
}

For example. I just bought a bargain batch of 14.1523MHz oscillators from BG but I need to generate a 24Hz clock.

So a=14152300 and b=24:


d = 0;
forever {
Wait for clock A.
if (d < 0) {
d += 24;
} else {
d += 24 - 14152300; /* getting here means tick for clock B */
}
}


For a hardware implementation I need to know how many bits are needed for d: here it's 24 bits to hold the largest value (-14152300) plus one more bit for the sign. In VHDL this looks like:


signal d, dInc, dN : std_logic_vector(24 downto 0);
process (d)
begin
if (d(24) = '1') then
dInc <= "0000000000000000000011000"; -- (24)
else
dInc <= "1001010000000110110101100"; -- (24 - 14152300)
end if;
end process;
dN <= d + dInc;
process
begin
wait until A'event and A = '1';
d <= dN;
-- clock B tick whenever d(24) is zero
end process;

标签:  VHDL  任意频率分频器


  发表评论

昵称: 验证码:
内容:
 
相关新闻
 · 使用LeonardoSpectrum综
 · 基于FPGA的同步测周期高精度数字频率
 · 用CPLD实现Gollmann密钥流发
 · 基于FPGA的高速数字锁相环的设计与实
 · 基于FPGA的非对称同步FIFO设计
 · 基于FPGA的可编程定时器/计数器82
 · I2C总线控制器的VHDL设计及实现
 · 实时系统的DDSPN建模与VHDL描述
最新资讯
 · 便携电子产品电源测试的理想选择--吉时
 · 各种白光LED驱动电路特性评比
 · GPS技术在ITS的发展中得到了广泛的
 · 电子工程师心声:销售与我无关
 · 关于你的一生--IT人职业规划
 · 通过自适应曝光校正技术来改进拍照手机的
 · 嵌入式操作系统Nucleus下触摸屏驱
 · 模拟器件将投产手机3轴加速度传感器
 
  站内 站外
  Copyright(C)2008 Electronic Design & Application World All rights reserved.  《电子设计应用》杂志社 版权所有
联系电话:(86)10-66421136 66421836 66423836   传真:(86)10-66423936   京ICP备05012822号