EDA常用模块 奇数分频 偶数分频 冒泡排序

2023-10-11 13:50

本文主要是介绍EDA常用模块 奇数分频 偶数分频 冒泡排序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、分频

1、偶数分频

.v文件

module FenPin (input clk,input rst,output wire clk_10k);
parameter f=8;				//即为偶分频的分频数
reg [11:0] count=0;						//存储分频计数
reg clk_10k_tmp=0;
assign clk_10k = clk_10k_tmp;// 复位信号rst低电平有效
always @(posedge clk or negedge rst) 
beginif (!rst) 							beginclk_10k_tmp = 0;count = 0;end else beginif (count == f/2-1) 			//偶分频数/2 - 1beginclk_10k_tmp = ~clk_10k_tmp;count = 0;end else begincount = count + 1;endend
end
endmodule

测试文件

`timescale 1 ps/ 1 ps
module FenPin_vlg_tst();reg clk;
reg rst;wire clk_10k;FenPin i1 ( .clk(clk),.clk_10k(clk_10k),.rst(rst)
);initial                                                
begin                                                  rst=1;				//模拟复位信号按下#20 rst=0;#20 rst=1;#8000 $stop;                                        
end                                                    
always                                                                
begin                                                  #50 clk=1; #50 clk=0;                                     
end                                                    
endmodule

仿真结果

image-20210523185310874

2、奇数分频

.v文件

module FenPin(clkout,clk,rst); 
input clk,rst; 
output clkout; parameter f=9;			//即为奇分频分频数reg [9:0] counter1, counter2;
reg clkp1, clkp2;always@(posedge clk or negedge rst)  // counter1自动计数
beginif (~rst) counter1<=0;else if (counter1==f-1)counter1<=0;else counter1<=counter1+1;
endalways @(posedge clk or negedge rst) // clk上升沿触发产生p1
beginif(~rst) clkp1<=0;else if(counter1==(f-1)/2 || counter1==f-1)clkp1<=~clkp1;
endalways @(negedge clk or negedge rst)//counter2自动计数 
begin if(~rst) counter2<=0; else if(counter2==f-1) counter2<=0; else counter2<=counter1+1; 
end always @(negedge clk or negedge rst)//clk下降触发产生p2 
begin if(~rst) clkp2<=0; else begin if(counter2==(f-1)/2||counter2==f-1) clkp2<=~clkp2;end 
end assign clkout=clkp1|clkp2;   //p1|p2使占空比等于50% endmodule

测试文件

`timescale 1 ps/ 1 ps
module FenPin_vlg_tst();reg clk;
reg rst;wire clkout;FenPin i1 ( .clk(clk),.clkout(clkout),.rst(rst)
);initial                                                
begin                                                  rst=1;				//模拟复位信号按下#20 rst=0;#20 rst=1;#8000 $stop;                                        
end                                                    
always                                                                
begin                                                  #50 clk=1; #50 clk=0;                                     
end                                                    
endmodule

仿真结果

image-20210524082335407

二、其他功能

1. 冒泡排序

代码

module pop(input clk,input rst,input [3:0]data_in,	output reg[2:0]state,output reg[3:0]data_out
);reg[3:0] i,p;//计数器
reg[3:0]content[7:0];initial 
beginstate<=0;i<=0;p<=7;
endalways@(posedge clk or posedge rst )
begin
if(rst)begin state<=0;data_out<=0;i<=0;p<=7;endelse begincase(state)3'b000:begin//读取数据content[i]=data_in;i=i+1;if(i==8)begin i<=0;state<=3'b001;endend //0003'b001:begin//冒泡排序if(i<p) begin if(content[i]<content[i+1])begin //如果当前位置比后面小则对调content[i+1]<=content[i];content[i]<= content[i+1];endi<=i+1;endelse begin i<=0; p<=p-1;  endif (p==0&&i==0)  state<=3'b010;end//0013'b010:begin //发送数据data_out=content[i];i=i+1;if(i==8) begin i=0; state=3'b011; endend3'b011:begin//延时一段时间i=i+1;if(i==15)begin i=0;state=0;endend//011		endcase
end//elseend//always
endmodule

测试文件

//测试文件:
`timescale 1 ns/ 1 ps
module pop_vlg_tst();reg clk;
reg [3:0] data_in;
reg rst;                                              
wire [3:0]  data_out;
wire [2:0]  state;// assign statements (if any)                          
pop i1 ( .clk(clk),.data_in(data_in),.data_out(data_out),.rst(rst),.state(state)
);initial                                                
begin                                                  clk=0;#100rst=1;#30rst=0;forever #5 clk=~clk;                      
end                                                    
initial                                                               
begin
#130                                                  while(1)begindata_in=7;#10data_in=5;#10data_in=8;#10data_in=11;#10data_in=12;#10data_in=14;#10data_in=15;#10data_in=9;#1000rst=1;#30rst=0;end		
end                                                    
endmodule

这篇关于EDA常用模块 奇数分频 偶数分频 冒泡排序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/188490

相关文章

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

一文深入详解Python的secrets模块

《一文深入详解Python的secrets模块》在构建涉及用户身份认证、权限管理、加密通信等系统时,开发者最不能忽视的一个问题就是“安全性”,Python在3.6版本中引入了专门面向安全用途的secr... 目录引言一、背景与动机:为什么需要 secrets 模块?二、secrets 模块的核心功能1. 基

Python常用命令提示符使用方法详解

《Python常用命令提示符使用方法详解》在学习python的过程中,我们需要用到命令提示符(CMD)进行环境的配置,:本文主要介绍Python常用命令提示符使用方法的相关资料,文中通过代码介绍的... 目录一、python环境基础命令【Windows】1、检查Python是否安装2、 查看Python的安

python判断文件是否存在常用的几种方式

《python判断文件是否存在常用的几种方式》在Python中我们在读写文件之前,首先要做的事情就是判断文件是否存在,否则很容易发生错误的情况,:本文主要介绍python判断文件是否存在常用的几种... 目录1. 使用 os.path.exists()2. 使用 os.path.isfile()3. 使用

Java实现本地缓存的常用方案介绍

《Java实现本地缓存的常用方案介绍》本地缓存的代表技术主要有HashMap,GuavaCache,Caffeine和Encahche,这篇文章主要来和大家聊聊java利用这些技术分别实现本地缓存的方... 目录本地缓存实现方式HashMapConcurrentHashMapGuava CacheCaffe

Python将字符串转换为小写字母的几种常用方法

《Python将字符串转换为小写字母的几种常用方法》:本文主要介绍Python中将字符串大写字母转小写的四种方法:lower()方法简洁高效,手动ASCII转换灵活可控,str.translate... 目录一、使用内置方法 lower()(最简单)二、手动遍历 + ASCII 码转换三、使用 str.tr

Python logging模块使用示例详解

《Pythonlogging模块使用示例详解》Python的logging模块是一个灵活且强大的日志记录工具,广泛应用于应用程序的调试、运行监控和问题排查,下面给大家介绍Pythonlogging模... 目录一、为什么使用 logging 模块?二、核心组件三、日志级别四、基本使用步骤五、快速配置(bas

Spring Boot 常用注解整理(最全收藏版)

《SpringBoot常用注解整理(最全收藏版)》本文系统整理了常用的Spring/SpringBoot注解,按照功能分类进行介绍,每个注解都会涵盖其含义、提供来源、应用场景以及代码示例,帮助开发... 目录Spring & Spring Boot 常用注解整理一、Spring Boot 核心注解二、Spr

Java中的内部类和常用类用法解读

《Java中的内部类和常用类用法解读》:本文主要介绍Java中的内部类和常用类用法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录内部类和常用类内部类成员内部类静态内部类局部内部类匿名内部类常用类Object类包装类String类StringBuffer和Stri

MySQL连接池(Pool)常用方法详解

《MySQL连接池(Pool)常用方法详解》本文详细介绍了MySQL连接池的常用方法,包括创建连接池、核心方法连接对象的方法、连接池管理方法以及事务处理,同时,还提供了最佳实践和性能提示,帮助开发者构... 目录mysql 连接池 (Pool) 常用方法详解1. 创建连接池2. 核心方法2.1 pool.q