【VHDL语言学习笔记(七)】 分频器

本文是VHDL语言学习笔记的第七部分,主要介绍如何设计8分频器。首先,设计了一个8分频器,其输出信号占空比为50%,即高低电平各占半个周期。接着,在此基础上调整,实现了占空比为25%的8分频器,通过波形仿真验证了设计效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目的:实现分频器设计。

1.  设计一个分频器实现将原信号进行8分频,所得信号占空比为50%。

分频是将单一频率信号的频率降为原来的1/N,就叫N分频。将信号进行8分频,即所得信号频率是原信号频率的1/8,则其所得信号的1个周期等于原始信号的8个周期。

占空比是高电平持续时间占整个周期的比值。占空比为50%意思是高低电平持续时间一样,均为半个周期的时间长。

程序

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity frequency_divider is
	port(
		clk		:in std_logic;	--原始信号
		fp_out	:out std_logic	--经过分频后的输出信号
		);
end frequency_divider;

architecture behave of frequency_divider is
begin 
	process(clk)
		variable count	:integer := 0;	--integer决定分频数N
	begin
		if(clk'event and clk = '1') then	--上升沿
			count := count + 1;		--对上升沿的个数进行计数,其实就是对原始信号的周期进行计数
			if(count < 5) then
				fp_out <= '1';	--输出信号在原始信号的前四个周期内保持高电平
			elsif(count <8) then
				fp_out <= '0';	--输出信号在原始信号的后四个周期内保持低电平
			end if;
			if(count = 8) then	--因为是8分频,所以当计数到8时要将计数值清0
				count := 0;
			end if;
		end if;
	end process;
end behave;
		
		
		

波形仿真图

 2.  设计一个分频器实现将原信号进行8分频,所得信号占空比为25%。

在上个程序的基础上,对高电平持续时间进行修改,即可实现占空比的修改。

程序

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity frequency_divider is
	port(
		clk		:in std_logic;	--原始信号
		fp_out	:out std_logic	--经过分频后的输出信号
		);
end frequency_divider;

architecture behave of frequency_divider is
begin 
	process(clk)
		variable count	:integer := 0;	--integer决定分频数N
	begin
		if(clk'event and clk = '1') then	--上升沿
			count := count + 1;		--对上升沿的个数进行计数,其实就是对原始信号的周期进行计数
			if(count < 3) then
				fp_out <= '1';	--输出信号在原始信号的前两个周期内保持高电平
			elsif(count <8) then
				fp_out <= '0';	--输出信号在原始信号的后六个周期内保持低电平
			end if;
			if(count = 8) then	--因为是8分频,所以当计数到8时要将计数值清0
				count := 0;
			end if;
		end if;
	end process;
end behave;
		
		
		

波形仿真图

 

小数分频器是一种常见的电路,能够将输入时钟信号分频为一个小于1的分数。VHDL是硬件描述语言,可以用于设计数字电路。下面是一个小数分频器VHDL实现。 ```vhdl library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity Fractional_Divider is Port ( CLK_IN : in STD_LOGIC; CLK_OUT : out STD_LOGIC; EN : in STD_LOGIC; RST : in STD_LOGIC; N : in UNSIGNED(9 downto 0); D : in UNSIGNED(9 downto 0)); end Fractional_Divider; architecture Behavioral of Fractional_Divider is signal counter : UNSIGNED(9 downto 0) := (others => '0'); signal div : UNSIGNED(19 downto 0) := (others => '0'); signal clk_div : STD_LOGIC := '0'; begin process (CLK_IN, RST) begin if (RST = '1') then counter <= (others => '0'); div <= (others => '0'); clk_div <= '0'; elsif rising_edge(CLK_IN) then if (EN = '1') then counter <= counter + 1; if (counter = (D - 1)) then counter <= (others => '0'); div <= div + N; clk_div <= not clk_div; end if; end if; end if; end process; CLK_OUT <= clk_div; end Behavioral; ``` 这个小数分频器的输入是一个时钟信号`CLK_IN`,还有一个使能信号`EN`和复位信号`RST`。输出是分频后的时钟信号`CLK_OUT`。`N`和`D`分别是分子和分母,用于计算分数。 在`process`中,首先根据复位信号清空计数器和除数寄存器以及分频后的时钟信号。然后在时钟上升沿触发时,如果使能信号为1,则将计数器加1。当计数器计数到D-1时,说明经过了D个时钟周期,需要对除数寄存器加上分数N,并将计数器清零。同时,分频后的时钟信号取反。 最后将分频后的时钟信号赋值给输出端口`CLK_OUT`即可。 这是一个简单的小数分频器VHDL实现。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

单片机学习之路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值