这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » FPGA » VHDL任意整数分频例程【经典】

共3条 1/1 1 跳转至

VHDL任意整数分频例程【经典】

专家
2009-03-22 14:18:10     打赏
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:=23);
PORT(
 CLK: IN STD_LOGIC;
 CLKOUT_3:BUFFER STD_LOGIC
);
END clkdiv;

ARCHITECTURE A OF clkdiv IS
 SIGNAL CNT1,CNT2:integer:=0;
 SIGNAL OUTTEMP:STD_LOGIC;
 SIGNAL LOUT:STD_LOGIC;
 SIGNAL OUT3:STD_LOGIC:='0';

 BEGIN
 l1:  PROCESS(CLK)
  BEGIN
  IF CLK'EVENT AND CLK='1'THEN
   IF CNT1=n-1 THEN
    CNT1<=0;
   ELSE
    CNT1<=CNT1+1;
   END IF;
  END IF;
 END PROCESS;
 
 l2: PROCESS(CLK)
  BEGIN
  IF CLK'EVENT AND CLK='0'THEN
   IF CNT2=n-1 THEN
    CNT2<=0;
   ELSE
    CNT2<=CNT2+1;
   END IF;
  END IF;
 END PROCESS;

 l3: PROCESS(CNT1,CNT2 )
  BEGIN
  if ((n mod 2)=1) then
   IF CNT1=1 THEN
    IF CNT2=0 THEN
     OUTTEMP<='1';
    ELSE OUTTEMP<='0';
    END IF;
   ELSIF CNT1=(n+1)/2 THEN
    IF CNT2=(n+1)/2 THEN
     OUTTEMP<='1';
    ELSE OUTTEMP<='0';
    END IF;
   ELSE
    OUTTEMP<='0';
   END IF;
  else
   if cnt1=1 then
    outtemp<='1';
   elsif (cnt1=(n/2+1)) then
    outtemp<='1';
   else
    outtemp<='0';
   end if;
  end if;
 END PROCESS;
 
 l4:  PROCESS(OUTTEMP,clk)
  BEGIN
  if ((n/=2) and (n/=1)) then
   IF OUTTEMP'EVENT AND OUTTEMP='1' THEN
    CLKOUT_3<=NOT CLKOUT_3;
   END IF;
  elsif (n=2) then
   if(clk'event and clk='1')then
    clkout_3<=not clkout_3;
   end if;
  else
   clkout_3<=clk;
  end if;
 END PROCESS;
END A;




关键词: 任意     整数     例程     经典    

助工
2009-03-26 09:39:22     打赏
2楼
正在找这东东,感谢lz了

助工
2009-03-27 09:50:15     打赏
3楼
要是verilog就好了。。。。。。。。。。。

共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]