当前位置:网站首页>VHDL arbitrary frequency divider (50% duty cycle)
VHDL arbitrary frequency divider (50% duty cycle)
2022-04-23 06:47:00 【Round moon】
Preface
Before last winter vacation, one of my relatives asked me how to make a five frequency divider . I don't think it's easy , Isn't it just a counter , But the discovery is not that simple , Because the even frequency divider can count according to the rising edge , But odd dividers can also , But I can't 50% Duty cycle . In today's class, the teacher solved this problem perfectly .
Even frequency division
We've studied counters before , Even allocation is nothing more than a counter , When using the signal as the intermediate variable, it should be noted that it is a lag variable , Therefore, when modifying, you should consider clearing . There's nothing to say about this. Go directly to the code .
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity Test is
generic(constant N:integer:=6);
port(signal clk:in std_logic;signal cout:out std_logic);
end Test;
architecture even of Test is
signal temp:integer:=0;
constant half:integer:=N/2;
begin
process(clk)
begin
if rising_edge(clk) then
temp<=temp+1;
if temp<half then
cout<='1';
elsif temp<N-1 then
cout<='0';
else
temp<=0;
cout<='0';
end if;
end if;
end process;
end even;
Here we can realize an even frequency division . This must be no problem for everyone , So let's continue to look at odd frequency division
Odd frequency division
It's easy to think of odd frequency division 50% The duty cycle of must be related to both rising and falling edges , So we count both rising and falling edges , Take a look at the effect .
We find that only when the states in both directions are 0 Only when 0
Because looking in the right direction , He will have a delay of half a clock cycle , So you can do it 3.5 A cycle of high level . Then the rest is naturally low level .
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity div_any is
generic(constant N:integer:=5);
port(signal clk:in std_logic;signal cout:out std_logic);
end div_any;
architecture even of div_any is
signal tempA,tempB:integer:=0;
signal coutA,coutB:std_logic;
constant half:integer:=N/2;
begin
process(clk)
begin
if rising_edge(clk,coutA,coutB) then
tempA<=tempA+1;
if tempA<half then
coutA<='1';
elsif tempA<N-1 then
coutA<='0';
else
tempA<=0;
coutA<='0';
end if;
elsif falling_edge(clk) then
tempB<=tempB+1;
if tempB<half then
coutB<='1';
elsif tempB<N-1 then
coutB<='0';
else
tempB<=0;
coutB<='0';
end if;
end if;
cout<=coutA or coutB;
end process;
end even;
Arbitrary frequency division
So how to achieve arbitrary frequency division ?
We can find out , If the current number is even , Then it's just the same as the rising edge . But let's make a special judgment here ,1 The situation of .
The following code changes the frequency division status by entering the frequency division value .
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity div_any is
port(signal clk:in std_logic;
signal scaler:in integer range 0 to 63;
signal clk_out,clk_f,clk_r:out std_logic);
end div_any;
architecture DIV of div_any is
signal f_count:integer range 0 to 63:=0;
signal r_count:integer range 0 to 63:=0;
signal half:integer;
signal even:integer;
signal clk_f_temp,clk_r_temp:std_logic;
begin
half<=scaler/2;
even<= scaler rem 2;
with even*scaler select
clk_out<=clk_r_temp when 0,
clk when 1,
clk_f_temp or clk_r_temp when others;
process(clk,scaler)
begin
if rising_edge(clk) then
r_count<=r_count+1;
if r_count<half then
clk_r_temp<='1';
elsif r_count<scaler-1 then
clk_r_temp<='0';
else
clk_r_temp<='0';
r_count<=0;
end if;
elsif falling_edge(clk) then
f_count<=f_count+1;
if f_count<half then
clk_f_temp<='1';
elsif f_count<scaler-1 then
clk_f_temp<='0';
else
clk_f_temp<='0';
f_count<=0;
end if;
end if;
end process;
clk_f<=clk_f_temp;
clk_r<=clk_r_temp;
end DIV;
By-Round Moon
版权声明
本文为[Round moon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230549498912.html
边栏推荐
- Using printf in MFC
- Notes on advanced points of C language 5
- [opencv] use filestorage to read and write eigenvectors
- [UDS unified diagnosis service] i. diagnosis overview (2) - main diagnosis protocols (K-line and can)
- 生成快捷方式
- vs中能编译通过,但是会有红色下划线提示未定义标示符问题
- 赛氪-二进制
- Shell脚本 单引号、双引号和反引号的区别
- C语言进阶要点笔记5
- Log writing method (with time)
猜你喜欢
[UDS unified diagnostic service] IV. typical diagnostic service (2) - data transmission function unit
[ThreadX] h743 + ThreadX + Filex migration record
卷积神经网络实现CIFAR100数据集分类
CUDA环境安装
[UDS unified diagnostic service] II. Network layer protocol (1) - overview and functions of network layer
进程管理命令
CUDA environment installation
Installation of GCC, G + +, GDB
[UDS unified diagnostic service] i. overview of diagnosis (4) - basic concepts and terms
三极管原理及特性分析
随机推荐
Eigen 学习总结
共用数据的保护
Static member
Figure guessing game
基于VGG对五种类别图片的迁移学习
2020 Jiangsu Collegiate Programming Contest-A.Array
Qt 给应用程序加图标
【UDS统一诊断服务】三、应用层协议(2)
赛氪-zeal
ARM常用汇编指令
CUDA environment installation
[ThreadX] h743 + ThreadX + Filex migration record
提交本地仓库并同步码云仓库
【UDS统一诊断服务】一、诊断概述(1)— 诊断概述
C language advanced notes 3
【UDS统一诊断服务】二、网络层协议(1)— 网络层概述与功能
猜數字遊戲
ES6
HDU-Tunnel Warfare
realsense 选型大对比D455 D435i D415 T265 3D硬件对比