yuzhiwen 发表于 2010-6-3 17:07:23

偶数分频和奇数分频器设计(欢迎拍砖)

偶数分频和奇数分频器设计
(1)偶数分频
对时钟进行偶数分频比较简单,如占空比为50%的时钟信号只要使用一个计数器,在前半段时间内高电平后半段电平内低电平这样分频出来的信号就是占空比为50%的时钟信号。废话不多说上段程序。
---------------------------偶数分频VHDL代码
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity clkdiv is
   generic (n:integer:=8);                        ---偶数分频,分频数可任意更改
    port(clk:in std_logic;
         outclk:out std_logic
      );
   end clkdiv;
architecture u1 of clkdiv is
signal count:integer;
begin
process(clk)
begin
   if(clk'event and clk='1')
then
if(count=n-1)then                              --计数周期
   count<=0;
   else count<=count+1;
   if count<(integer(n/2))
then
       outclk<='0';
else
outclk<='1';
    end if;
   end if;
end if;
end process;
end u1;
(2)奇数分频
奇数分频相对偶数分频来说,如果不要求占空比的话是一样的,但是如果要求占空比为50%的话则计数分频必偶数分频要复杂些。其中需要使用些技巧。可以先对输入时钟的上升沿进行计数,然后让一个内部信号在前一半段时间内为低电平,后一半段时间内为高电平。同时对输入时钟的下降沿进行计数,让另一个内部信号在前半段时间内为高电平,在后半段时间内为低电平。然后让两个内部信号进行相与,得到了半个时钟的一个高电平,在让这个信号和第一个内部信号相或,就得到了占空比为50%的时钟信号了~~~
-----奇数分频VHDL代码------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity clkdiv is
   generic (n:integer:=7);                        ---偶数分频,分频数可任意更改
    port(clk:in std_logic;
         outclk:out std_logic
      );
    end clkdiv;
architecture u1 of clkdiv is
signal count1,count2:integer;
signal q,outclk1,outclk2:std_logic;
begin
   q<=outclk1 and outclk2;----两个内部信号相与
    outclk<=q or outclk1;   ----第一个信号和Q信号相或

process(clk)
begin
   if(clk'event and clk='1')
then
if(count1=n-1)then                              --计数周期
   count1<=0;
   else count1<=count1+1;
   if count<(integer(n/2))
then
       outclk1<='0';
else
outclk1<='1';
    end if;
   end if;
end if;
end process;

process(clk)
begin
   if(clk'event and clk='0')
then
if(count2=n-1)then                              --计数周期
   count2<=0;
   else count2<=count2+1;
   if count<(integer(n/2))
then
       outclk2<='1';
else
outclk<='0';
    end if;
   end if;
end if;
end process;
end u1;

wjfblack 发表于 2010-11-11 17:28:53

奇数分频还有第二种方法,一直没想清楚
方法如网上所说如下:
对进行奇数倍n分频时钟,首先进行n/2分频(带小数,即等于(n-1)/2+0.5),然后再进行二分频得到。得到占空比为50%的奇数倍分频。下面讲讲进行小数分频的设计方法

小数分频:首先讲讲如何进行n+0.5分频,这种分频需要对输入时钟进行操作。基本的设计思想:对于进行n+0.5分频,首先进行模n的计数,在计数到n-1时,输出时钟赋为‘1’,回到计数0时,又赋为0,因此,可以知道,当计数值为n-1时,输出时钟才为1,因此,只要保持计数值n-1为半个输入时钟周期,即实现了n+0.5分频时钟,因此保持n-1为半个时钟周期即是一个难点。从中可以发现,因为计数器是通过时钟上升沿计数,因此可以在计数为n-1时对计数触发时钟进行翻转,那么时钟的下降沿变成了上升沿。即在计数值为n-1期间的时钟下降沿变成了上升沿,则计数值n-1只保持了半个时钟周期,由于时钟翻转下降沿变成上升沿,因此计数值变为0。因此,每产生一个n+0.5分频时钟的周期,触发时钟都是要翻转一次.

zzjjhh250 发表于 2010-11-11 21:36:44

http://cache.amobbs.com/bbs_upload782111/files_34/ourdev_597234HR46Q0.jpg
(原文件名:未命名.jpg)
具体分析
应该是异或吧!

scfor 发表于 2011-7-29 13:40:17

学习了
页: [1]
查看完整版本: 偶数分频和奇数分频器设计(欢迎拍砖)