×

vhdl分频器

vhdl分频器(VHDL 分频器)

admin admin 发表于2022-09-03 03:20:18 浏览183 评论0

抢沙发发表评论

本文目录

VHDL 分频器


仿真的图形给出了,因为本题数字太大,我改小后仿真的

library IEEE;

use IEEE.std_logic_1164.all;

use IEEE.std_logic_unsigned.all;

entity fp is

    port (

        clk: in STD_LOGIC;

        q: out STD_LOGIC

    );

end fp;

architecture fp_arch of fp is

begin

 process(clk)

 variable n:integer range 0 to 49999; 

 begin

  if clk’event and clk=’1’ then

   if n《=24999 then  

   n:=n+1;

   q《=’0’;

   elsif n=49999 then 

   n:=0;

   q《=’1’;

   else

   n:=n+1;

   q《=’1’;

   end if;

  end if;

  end process;

   

end fp_arch;


用VHDL语言写分频器


library
ieee;
use
ieee.std_logic_1164.all;
use
ieee.std_logic_unsigned.all;
entity
div
is
generic(n:integer
:=1000000);
port
(clk:in
std_logic;
q:out
std_logic);
end
div;
architecture
behave
of
div
is
signal
count
:integer
range
n-1
downto
0:=n-1;
begin
process(clk)
begin
if
rising_edge(clk)
then
count《=count-1;
if
count》=n/2
then
q《=’0’;
else
q《=’1’;
end
if;
if
count《=0
then
count《=n-1;
end
if;
end
if;
end
process;
end
behave;
-vhdl分频器

VHDL分频器求助:


你这样是把频率分了10倍,50倍,50000倍,,你可以假定一个计数值,当这个一个时钟上升沿到来时,计数值加1,当计数值加到一定值X时的时候,你的输出信号由1变0,或者由0变1这个翻转,则输出的频率就等于50mhz*X*2,然后再根据你需要分频结果,计算X的值,下面是一个例子,你只需添加三个相同的process()----end process;的内容就可以了,当然还需改下X的值!!!
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity fenpin is
port(clk:in std_logic;
clk_out:out std_logic);
end;
architecture art of fenpin is
signal count:integer range 0 to X;---改X值,
signal clk_data:std_logic;
begin
process(clk,count)
begin
if clk’event and clk=’1’ then
if count=X then ---X值决定分频倍数
count=0;
clk_data《=not clk_data;
else count《=count+1;
end if;
end if;
clk_out《=clk_data;
end process;
end art;
-vhdl分频器

如何用VHDL实现分频


  1. 模N计数器的实现

    一般设计中用到计数器时,我们可以调用lpm库中的计数器模块,也可以采用VHDL语言自己设计一个模N计数器。本设计采用VHDL语言设计一个最大模值为16的计数器。输入端口为:使能信号en,复位信号clr和时钟信号clk;输出端口为:qa、qb、qc、qd。其VHDL语言描述略。-vhdl分频器

  2. 带使能控制的异或门的实现

  3. 输入端为:xor_en:异或使能,a和b:异或输入;输出端为:c:异或输出。当xor_en为高电平时,c输出a和b的异或值。当xor_en为低电平时,c输出信号b。其VHDL语言略。

  4. 2分频(触发器)的实现

  5. 输入端为:时钟信号clk,输入信号d;输出端为:q:输出信号a,q1:输出信号a反。其VHDL语言略。

  6. 4.分频器的实现

  7. 本设计采用层次化的设计方法,首先设计实现分频器电路中各组成电路元件,然后通过元件例化的方法,调用各元件,实现整个分频器。其VHDL语言略。


VHDL 分频器 为什么要调用计数器呢


首先:分频,就是将频率缩小;
比如之前的频率是10Hz(时钟周期为0.1),那2分频后就是5Hz(时钟周期为0.2)
好,那我问你,如果时钟频率是10Hz,1秒钟内有多少个时钟呢(就是clk cycle是怎样的呢);显然画出的波形就是1秒钟内有10个clock,那要怎么体现在代码里面呢?--》计数器
用计数器就是数clock cycle的数目!
10Hz的clock变成5Hz的clock:
--》10Hz的clock:用计数器数A到10表示
--》5Hz的clock:计数器数B到5
所以说当计数器A每数2个,计数器B就加1;这样计数器B对应的时钟是不是就是10Hz进行了2分频呢
---------------------------------------
不知道明白了没有
-vhdl分频器

分频器的VHDL看不懂


hz512《=q(0);表示2的1次幂分频(及2分频),此信号‘0’,‘1‘交替变化;
hz256《=q(1);表示2的2次幂分频
hz64《=q(3);表示2的4次幂分频
hz4《=q(7);表示2的6次幂分频
hz1《=q(9);表示2的10次幂分频
-vhdl分频器

VHDL编写分频器


library ieee;
use ieee.std_logic_1164.all;
entity oneMHZ is
port( clkin:in std_logic; --时钟信号输入
clkout:out std_logic); --时钟信号输出
end oneMHZ;
architecture aroneMHZ of oneMHZ is
signal data:integer range 0 to 10;
signal Q:std_logic;
begin
process(clkin)
begin
if rising_edge(clkin) then
if(data=0) then --此句为你想要的分频比,data=0,1,2,3,4.......9的分频比为1,2,3,,,10
data《=0;
Q《=not Q;
else
data《=data+1;
end if;
end if;
clkout《=Q;
end process;
end oneMHZ;
-vhdl分频器

vhdl语言做分频器,1000000hz变成1hz的


就是把1MHz分频成1hz,两种方法,一种是用fpga自带的锁相环或者时钟管理器,直接设置输出成1hz就行了。另外一种方法就是用hdl实现,包括vhdl和verilog。分频算法如下:计数器开始计数,寄到500000,输出高电平或者低电平;再从500000计数到1000000,输出电平反向。如此反复即可输出1hz时钟信号。
友情提醒:虽然用hdl可以分频时钟信号,但是不建议这样做,因为这样得到的时钟信号不是最优的,可靠性得不到保障,最好选用fpga自带的锁相环或者时钟管理器进行分频和倍频,这样得到的时钟最可靠。
-vhdl分频器

VHDL语言设计分频器


输入信号10HZ的话 你要分频咯 这个频率无所谓的 主要看你分频的精度
毕业设计这个层次的东西要求不会很高的 那就选25MHz的吧 最好用有源晶振
无源也问题不大 呵呵
我给你个万能分频代码吧 你的分数也太低了吧 0分
VHDL的任意整数且占空比为50%分频代码
说明如下:
1.其中top file 为 division,其中的clk_com是比较的频率,用它来和分频后波形进行比较,便于观察,
2.any_enve为任意偶数分频文件
3.any_odd为任意奇数分频文件
4.是一个用于2进制与8进制的译码器,我用它来显示在数码管上当前到底是多少分频
5.以下代码在开发板上实验过,请大家放心使用,欢迎转载,但请注明出处,另外说明由于用的是quartus7.1编辑的,中间无法加中文注释,请大家慢慢读了;以下是代码:
------the top file of the design division
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity division is
port (input : in std_logic_vector(7 downto 0);
clk : in std_logic;
clk_out : out std_logic;
clk_com : out std_logic;
led1: out std_logic_vector(6 downto 0);
led2: out std_logic_vector(6 downto 0);
led3: out std_logic_vector(6 downto 0));
end entity division;
--------------------------------------------------
architecture freq of division is
component decoder is----decoder
port(bin : in std_logic_vector(2 downto 0);
de : out std_logic_vector(6 downto 0));
end component;
component any_even is----any_even division
generic (data_width : integer := 8 );
port(input1 : in std_logic_vector(data_width-1 downto 0);
clk_in : in std_logic;
clk_out : out std_logic);
end component any_even;
component any_odd is-----any_even division
generic (data_width : integer := 8);
port(input2 : in std_logic_vector(data_width - 1 downto 0);
clk_in : in std_logic;
clk_out : out std_logic);
end component any_odd;
signal temp1,temp2 : std_logic;
begin
u1: decoder port map(bin=》input(2)&input(1)&input(0),de=》led1);
u2: decoder port map(bin=》input(5)&input(4)&input(3),de=》led2);
u3: decoder port map(bin=》’0’&input(7)&input(6),de=》led3);
u4: any_even port map(input,clk,temp1);
U5: any_odd port map(input,clk,temp2);
process(clk,input)
begin
if input(0)= ’0’ then
clk_out 《= temp1;
else clk_out 《= temp2;
end if;
end process;
clk_com 《= clk;
end architecture freq;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity any_even is
generic (data_width : integer := 8 );
port(input1 : in std_logic_vector(data_width-1 downto 0);
clk_in : in std_logic;
clk_out : out std_logic);
end entity any_even;

architecture div1 of any_even is
signal clk_outQ : std_logic ;
signal coutQ : std_logic_vector (data_width - 1 downto 0);
begin
-------------------------------------------------
process(clk_in)
begin
if clk_in’event and clk_in = ’1’ then
if coutQ 《 (conv_integer(input1) - 1) then
coutQ 《= coutQ + 1;
else coutQ 《= (others =》 ’0’);
end if;
end if;
end process;
---------------------------------------------------
process(coutQ)
begin
if coutQ 《 (conv_integer(input1))/2 then
clk_outQ 《= ’0’;
else clk_outQ 《= ’1’;
end if;
end process;
clk_out 《= clk_outQ;
end architecture div1;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity any_odd is
generic (data_width : integer := 8);
port(input2 : in std_logic_vector(data_width - 1 downto 0);
clk_in : in std_logic;
clk_out : out std_logic);
end entity any_odd;
architecture div2 of any_odd is
signal cout1,cout2 : std_logic_vector(data_width - 1 downto 0);
signal clk1,clk2 : std_logic;
begin
process(clk_in)------rising edge
begin
if clk_in’event and clk_in=’1’ then
if cout1 《 (conv_integer(input2)-1) then
cout1 《= cout1 + 1;
else cout1 《= (others =》 ’0’);
end if;
if cout1 《 (conv_integer(input2)-1)/2 then
clk1 《= ’1’;
else clk1 《= ’0’;
end if;
end if;
end process;
---------------------------
process(clk_in)------falling edge
begin
if clk_in’event and clk_in=’0’ then
if cout2 《 (conv_integer(input2)-1) then
cout2 《= cout2 + 1;
else cout2 《= (others =》 ’0’);
end if;
if cout2 《 (conv_integer(input2)-1)/2 then
clk2 《= ’1’;
else clk2 《= ’0’;
end if;
end if;
end process;
clk_out 《= clk1 or clk2;
end architecture div2;
library ieee;
use ieee.std_logic_1164.all;
entity decoder is
port(bin : in std_logic_vector(2 downto 0);
de : out std_logic_vector(6 downto 0));
end entity;
----------------------------------------------------
architecture deco of decoder is
begin
process(bin)
begin
case bin is
when “000“ =》 de 《= “0111111“;---0
when “001“ =》 de 《= “0000110“;---1
when “010“ =》 de 《= “1011011“;---2
when “011“ =》 de 《= “1001111“;---3
when “100“ =》 de 《= “1100110“;---4
when “101“ =》 de 《= “1101101“;---5
when “110“ =》 de 《= “1111101“;---6
when others =》 de 《= “0000111“;---7

end case;
end process;
end architecture;
-vhdl分频器

用VHDL语言描述一个分频器,将1000HZ分频成1HZ,


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity ffpin is
port (clk1k:in std_logic;
ft:out std_logic);
end ffpin;
architecture a of ffpin is
signal fm:std_logic;
begin
process(clk1k)
variable num:integer range 0 to 1000;
begin
if clk1k’event and clk1k=’1’ then
if num《500 then
num:=num+1;
else
num:=1;
fm《=not fm;
end if ;
end if;
ft《=fm;
end process;
end a;
这个程序输入为1kHz时,输出为1Hz
-vhdl分频器