CPLD的分频语言

news/2024/7/2 23:33:13

分频器在FPGA/CPLD设计中是不可缺少的一部分,这就包括分频系数是奇数和偶数的(我们称为奇分频和偶分频),而对于偶分频来说还有不同的分频方法,下面将给出具体的方法:

1、占空比不为50%的偶分频

占空比:指在一个周期内高低电平持续的时间不等。

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all; --定义库文件
entity ofp is         --定义实体名为ofp
port(
     clk:in std_logic;
     clk_fp:out std_logic);
end entity;
architecture miao of ofp is
signal n:integer range 0 to 3;--4分频 注意:要想得到别的偶数分频

                             --可以将3替换为 fp_num-1 (fp_num为分频系数)
begin
process(clk)
begin
if clk'event and clk='1' then    --时钟上升沿触发
   if n<3 then             --当计数器n<3时进行+1运算,当n=3时n返回0
      n<=n+1;clk_fp<='0';
   else
   n<=0;clk_fp<='1';
   end if;
end if;
end process;
end miao;

 

2、占空比为50%的偶分频

 

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;--定义库文件
entity ofp1 is --定义实体名为ofp1
port(
     clk:in std_logic;
     clk_fp:out std_logic);
end entity;
architecture miao of ofp1 is
signal n:integer range 0 to 1;--注意:同样是四分频,这里n只是0-1

-- 注意:要想得到别的偶数分频

--可以将1替换为 fp_num/2 -1 (fp_num为分频系数)

signal cp:std_logic;   --定义一个中间变量,因为port内的输出信号不能放在-                      ---赋值号的右边
begin
process(clk)
begin
if clk'event and clk='1'then --思想:当计数器n计数到1的时候就将信号

                             --cp进行翻转
   if n<1 then
      n<=n+1;
   else
   n<=0;cp<=not cp;
   end if;
end if;
end process;
clk_fp<=cp;
end miao;

 

3、占空比不为50%的奇分频

    下面这个程序是3分频的程序,要是大家想改为别的,就尝试一下吧,我就不明说了,要是真的不知道,可以留言

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
entity thirdfreq is
port(
   clkin : in STD_LOGIC;
   rst : in STD_LOGIC;
   thirdfreq : out STD_LOGIC;    -- three freq output, 50%
   threecountp : out STD_LOGIC_VECTOR(1 downto 0); --not 50%
   threecountn : out STD_LOGIC_VECTOR(1 downto 0) --not 50%
      );
end thirdfreq;
architecture thirdfreq of thirdfreq is
signal threecntp   : std_logic_vector(1 downto 0);
signal threecntn   : std_logic_vector(1 downto 0);
signal thirdfreq_p : std_logic;
signal thirdfreq_n : std_logic;
begin
thirdfreq <= thirdfreq_p and thirdfreq_n;
u0: process(clkin,rst)
begin
if rst = '0' then
   threecntp <= "00";
else
   if clkin'event and clkin = '1' then
    if threecntp = "10" then
     threecntp <= "00";
    else
     threecntp <= threecntp + '1';
    end if;
   end if;
end if;
end process u0;  
threecountp <= threecntp;

u1: process(clkin,rst)
begin
if rst = '0' then
   threecntn <= "00";
else
   if clkin'event and clkin = '0' then
    if threecntn = "10" then
     threecntn <= "00";
    else
     threecntn <= threecntn + '1';
    end if;
   end if;
end if;
end process u1;
threecountn <= threecntn;

u2: process(clkin,rst)
begin
if rst = '0' then
   thirdfreq_p <= '0';
else
   if clkin'event and clkin = '1' then
    if threecntp < "01" then
     thirdfreq_p <= '0';
    else
     thirdfreq_p <= '1';
    end if;
   end if;
end if;
end process u2;  

u3: process(clkin,rst)
begin
if rst = '0' then
   thirdfreq_n <= '0';
else
   if clkin'event and clkin = '0' then
    if threecntn < "01" then
     thirdfreq_n <= '0';
    else
     thirdfreq_n <= '1';
    end if;
   end if;
end if;
end process u3;
end thirdfreq;

转自:http://www.3mdianzi.cn/web/viewarticle.asp?userid=893633&lanmuid=6048701&contentID=1526842

转载于:https://www.cnblogs.com/itxiaocaiyidie/archive/2012/03/30/2424856.html


http://lihuaxi.xjx100.cn/news/252708.html

相关文章

Android Wifi 主动扫描 被动扫描

介绍主动扫描&#xff0c;被动扫描以及连接的wifi的扫描过程 参考文档 《802.11无线网络权威指南》 《80_Y0513_1_QCA_WCN36X0_SOFTWARE_ARCHITECTURE.pdf》(高通文档) 被动扫描&#xff08;passive scanning&#xff09; 可以节省电池的电力&#xff0c;因为不需要传送任何信号…

【一周AI新鲜事】“擎天柱”霸气登场/全球创新指数中国排名11位/摩尔定律死了,又活了?...

本周&#xff0c;业界有哪些新鲜事&#xff1f;机器人家族再添新成员&#xff0c;“擎天柱”霸气登场首先&#xff0c;最劲爆的消息莫过于特斯拉的机器人“擎天柱”在今天召开的AI DAY上登台亮相。虽然没有电影中的擎天柱高大&#xff0c;但金属电缆的机械味道还是让人瞬间带入…

使用Bot Service创建Bot Framework

创建Bot Service&#xff1a;进入至Azure控制台中&#xff0c;新建Bot Service&#xff0c;如不知道Bot Service在哪个选项中&#xff0c;可以先查找Bot Service再创建 在弹出的查询结果中&#xff0c;选择Bot Service&#xff0c;点击后会进入至下一个步骤 在弹出的Bot Servic…

【组队学习】【28期】青少年编程(Scratch 一级)

青少年编程&#xff08;Scratch 一级&#xff09; 论坛版块&#xff1a; http://datawhale.club/c/team-learning/34-category/34 开源内容&#xff1a; https://github.com/datawhalechina/team-learning-program/tree/master/Scratch 学习目标 全国青少年软件编程等级考…

JNI

引用&#xff1a;http://baike.baidu.com/view/1272329.htm 使用&#xff1a;http://blog.wiyun.com/?p87 JNI是Java Native Interface的缩写&#xff0c;中文为JAVA本地调用。从Java1.1开始&#xff0c;Java Native Interface(JNI)标准成为java平台的一部分&#xff0c;它允许…

Session 常见操作

对于敏感、重要的信息&#xff0c;建议要存储在服务器端&#xff08;Session是存储在服务器端的&#xff09;&#xff0c;不能存储在浏览器中&#xff0c;如用户名、余额、等级、验证码等信息 Session依赖于Cookie session数据的获取 session:请求上下文对象&#xff0c;用于处…

弃用 AWS 后,我们服务器的年成本降低了 80%

摘要&#xff1a;云时代&#xff0c;在面对云厂商高额的成本时&#xff0c;放弃云服务采用内部基础设施进行替换是否是更合适的选择&#xff1f;原文链接&#xff1a;https://levelup.gitconnected.com/how-we-reduced-our-annual-server-costs-by-80-from-1m-to-200k-by-movin…

display的block、none、inline属性及解释

常会用到display对应值有block、none、inline这三个值 参数&#xff1a; block :块对象的默认值。用该值为对象之后添加新行。之前也添加一行。 none :隐藏对象。与visibility属性的hidden值不同&#xff0c;其不为被隐藏的对象保留其物理空间 inline :内联对象的默认值。用该值…