Verilog之SOS信号-仿顺序操作

2023-10-15 02:30
文章标签 操作 顺序 信号 verilog sos

本文主要是介绍Verilog之SOS信号-仿顺序操作,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

SOS信号:. . . _ _ _ . . . 

1.

module sos_module                    
(                    CLK, RSTn, Pin_Out, SOS_En_Sig                    
);                    input CLK;                    input RSTn;                input SOS_En_Sig;                output Pin_Out;                /****************************************/                parameter T1MS = 16'd49_999;//DB4CE15开发板使用的晶振为50MHz,50M*0.001-1=49_999                /***************************************/                reg [15:0]Count1;                always @ ( posedge CLK or negedge RSTn )                if( !RSTn )                Count1 <= 16'd0;            else if( isCount && Count1 == T1MS )            Count1 <= 16'd0;            else if( isCount )            Count1 <= Count1 + 1'b1;            else if( !isCount )            Count1 <= 16'd0;            /****************************************/                    reg [9:0]Count_MS;                    always @ ( posedge CLK or negedge RSTn )                if( !RSTn )                    Count_MS <= 10'd0;            else if( isCount && Count1 == T1MS )            Count_MS <= Count_MS + 1'b1;            else if( !isCount )            Count_MS <= 10'd0;            /******************************************/                reg isCount;                reg rPin_Out;                reg [4:0]i;                always @ ( posedge CLK or negedge RSTn )                if( !RSTn )                begin            isCount <= 1'b0;            rPin_Out <= 1'b0;i <= 5'd0;end        else             case( i )                5'd0 :         if( SOS_En_Sig ) i <= 5'd1;5'd1, 5'd3, 5'd5, 5'd13, 5'd15, 5'd17 :  if( Count_MS == 10'd100 ) begin isCount <= 1'b0; rPin_Out <= 1'b0; i <= i + 1'b1; end // shortelse begin isCount <= 1'b1; rPin_Out <= 1'b1; end5'd7, 5'd9, 5'd11 :if( Count_MS == 10'd300 ) begin isCount <= 1'b0; rPin_Out <= 1'b0; i <= i + 1'b1; end // longelse begin isCount <= 1'b1; rPin_Out <= 1'b1; end5'd2, 5'd4, 5'd6,  5'd8, 5'd10, 5'd12,5'd14, 5'd16, 5'd18 :if( Count_MS == 10'd50 ) begin isCount <= 1'b0; i <= i + 1'b1; end// intervalelse isCount <= 1'b1;5'd19 :begin rPin_Out <= 1'b0; i <= 5'd0; end  // endendcase        /***************************************************/                    assign Pin_Out = rPin_Out;                /***************************************************/                endmodule                    

 

2.

“Start_Sig”如同 C 语言中的调用指令,“Done_Sig”如同 C 语言的返回指令。这两个信号的存在就是为了控制模块的调用。

module sos_control_module                    
(                    CLK, RSTn,                    Start_Sig,                S_Done_Sig, O_Done_Sig,                S_Start_Sig, O_Start_Sig,                Done_Sig                
);                    input CLK;                    input RSTn;                input Start_Sig;                input S_Done_Sig, O_Done_Sig;                output S_Start_Sig, O_Start_Sig;                output Done_Sig;                /*************************************/                reg [3:0]i;                reg isO;                reg isS;                reg isDone;                always @ ( posedge CLK or negedge RSTn )                if( !RSTn )                    begin            i <= 4'd0;            isO <= 1'b0;isS <= 1'b0;isDone <= 1'b0;end        else if( Start_Sig )            case( i )            4'd0:if( S_Done_Sig ) begin isS <= 1'b0; i <= i + 1'b1; endelse isS <= 1'b1;4'd1:if( O_Done_Sig ) begin isO <= 1'b0; i <= i + 1'b1; endelse isO <= 1'b1;4'd2:if( S_Done_Sig ) begin isS <= 1'b0; i <= i + 1'b1; endelse isS <= 1'b1;4'd3:begin isDone <= 1'b1; i <= 4'd4; end                    4'd4:begin isDone <= 1'b0; i <= 4'd0; endendcase    /*****************************************/                    assign S_Start_Sig = isS;                    assign O_Start_Sig = isO;                    assign Done_Sig = isDone;                     /*****************************************/                endmodule                    
module s_module                    
(                    CLK, RSTn,                    Start_Sig,                Done_Sig,                Pin_Out                
);                    input CLK;                    input RSTn;                input Start_Sig;                output Done_Sig;                output Pin_Out;                /****************************************/                parameter T1MS = 16'd49_999;                /***************************************/                reg [15:0]Count1;                always @ ( posedge CLK or negedge RSTn )                if( !RSTn )                Count1 <= 16'd0;            else if( Count1 == T1MS )            Count1 <= 16'd0;            else if( isCount )            Count1 <= Count1 + 1'b1;            else if( !isCount )            Count1 <= 16'd0;            /****************************************/                    reg [9:0]Count_MS;                    always @ ( posedge CLK or negedge RSTn )                if( !RSTn )                    Count_MS <= 10'd0;            else if( Count_MS == rTimes )            Count_MS <= 10'd0;            else if( Count1 == T1MS )            Count_MS <= Count_MS + 1'b1;            /******************************************/                reg [3:0]i;                reg rPin_Out;                reg [9:0]rTimes;                reg isCount;                reg isDone;                always @ ( posedge CLK or negedge RSTn )                if( !RSTn )                begin             i <= 4'd0;        rPin_Out <= 1'b0;            rTimes <= 10'd1000;isCount <= 1'b0;    isDone <= 1'b0;    end        else if( Start_Sig )            case( i )            4'd0, 4'd2, 4'd4:        if( Count_MS == rTimes ) begin rPin_Out <= 1'b0; isCount <= 1'b0; i <= i + 1'b1; end        else begin isCount <= 1'b1; rPin_Out <= 1'b1; rTimes <= 10'd100; end    4'd1, 4'd3, 4'd5:if( Count_MS == rTimes ) begin isCount <= 1'b0; i <= i + 1'b1; endelse  begin isCount <= 1'b1; rTimes <= 10'd50; end4'd6:begin isDone <= 1'b1; i <= 4'd7; end4'd7:begin isDone <= 1'b0; i <= 4'd0; endendcase        /******************************************/                assign Done_Sig = isDone;                assign Pin_Out = !rPin_Out;                /******************************************/                endmodule                    
module o_module                    
(                    CLK, RSTn,                    Start_Sig,                Done_Sig,                Pin_Out                
);                    input CLK;                    input RSTn;                input Start_Sig;                output Done_Sig;                output Pin_Out;                /****************************************/                parameter T1MS = 17'd49_999;                /***************************************/                reg [16:0]Count1;                always @ ( posedge CLK or negedge RSTn )                if( !RSTn )                Count1 <= 17'd0;            else if( Count1 == T1MS )            Count1 <= 17'd0;            else if( isCount )            Count1 <= Count1 + 1'b1;            else if( !isCount )            Count1 <= 17'd0;            /****************************************/                    reg [9:0]Count_MS;                    always @ ( posedge CLK or negedge RSTn )                if( !RSTn )                    Count_MS <= 10'd0;            else if( Count_MS == rTimes )            Count_MS <= 10'd0;            else if( Count1 == T1MS )            Count_MS <= Count_MS + 1'b1;            /******************************************/                reg [3:0]i;                reg rPin_Out;                reg [9:0]rTimes;                reg isCount;                reg isDone;                always @ ( posedge CLK or negedge RSTn )                if( !RSTn )                begin             i <= 4'd0;        rPin_Out <= 1'b0;            rTimes <= 10'd1000;isCount <= 1'b0;    isDone <= 1'b0;    end        else if( Start_Sig )            case( i )            4'd0, 4'd2, 4'd4:        if( Count_MS == rTimes ) begin rPin_Out <= 1'b0; isCount <= 1'b0; i <= i + 1'b1; end        else begin isCount <= 1'b1; rPin_Out <= 1'b1; rTimes <= 10'd400; end    4'd1, 4'd3, 4'd5:if( Count_MS == rTimes ) begin isCount <= 1'b0; i <= i + 1'b1; endelse  begin isCount <= 1'b1; rTimes <= 10'd50; end4'd6:begin isDone <= 1'b1; i <= 4'd7; end4'd7:begin isDone <= 1'b0; i <= 4'd0; endendcase        /******************************************/                assign Done_Sig = isDone;                assign Pin_Out = !rPin_Out;                /******************************************/                endmodule                    
module sos_module        
(        CLK, RSTn,        Start_Sig,        Done_Sig,    Pin_Out    
);        input CLK;        input RSTn;    input Start_Sig;    output Done_Sig;    output Pin_Out;    /*****************************/    wire S_Done_Sig;    wire S_Pin_Out;    s_module U1    (    .CLK( CLK ),    .RSTn( RSTn ),.Start_Sig( S_Start_Sig ),  // input - from U3.Done_Sig( S_Done_Sig ),    // output - to U3.Pin_Out( S_Pin_Out )       // output - to selector
          ) ;    /*********************************/    wire O_Done_Sig;    wire O_Pin_Out;    o_module U2    (    .CLK( CLK ),    .RSTn( RSTn ),.Start_Sig( O_Start_Sig ),  // input - from U3.Done_Sig( O_Done_Sig ),    // output - to U3.Pin_Out( O_Pin_Out )       // output - to selector
     );    /*********************************/    wire S_Start_Sig;    wire O_Start_Sig;    sos_control_module U3    (    .CLK( CLK ),    .RSTn( RSTn ),.Start_Sig( Start_Sig ),      // input - from top.S_Done_Sig( S_Done_Sig ),    // input - from U1.O_Done_Sig( O_Done_Sig ),    // input - from U2.S_Start_Sig( S_Start_Sig ),  // output - to U1.O_Start_Sig( O_Start_Sig ),  // output - to U2.Done_Sig( Done_Sig )         // output - to top
     );    /*********************************/    //selector    reg Pin_Out;    always @ ( * )    if( S_Start_Sig ) Pin_Out = S_Pin_Out;      // select from U1    else if( O_Start_Sig ) Pin_Out = O_Pin_Out;  // select from U2else Pin_Out = 1'bx; /*********************************/        endmodule        

 

转载于:https://www.cnblogs.com/shaogang/p/4123489.html

这篇关于Verilog之SOS信号-仿顺序操作的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

Linux ls命令操作详解

《Linuxls命令操作详解》通过ls命令,我们可以查看指定目录下的文件和子目录,并结合不同的选项获取详细的文件信息,如权限、大小、修改时间等,:本文主要介绍Linuxls命令详解,需要的朋友可... 目录1. 命令简介2. 命令的基本语法和用法2.1 语法格式2.2 使用示例2.2.1 列出当前目录下的文

Spring Boot 配置文件之类型、加载顺序与最佳实践记录

《SpringBoot配置文件之类型、加载顺序与最佳实践记录》SpringBoot的配置文件是灵活且强大的工具,通过合理的配置管理,可以让应用开发和部署更加高效,无论是简单的属性配置,还是复杂... 目录Spring Boot 配置文件详解一、Spring Boot 配置文件类型1.1 applicatio

Mysql表的简单操作(基本技能)

《Mysql表的简单操作(基本技能)》在数据库中,表的操作主要包括表的创建、查看、修改、删除等,了解如何操作这些表是数据库管理和开发的基本技能,本文给大家介绍Mysql表的简单操作,感兴趣的朋友一起看... 目录3.1 创建表 3.2 查看表结构3.3 修改表3.4 实践案例:修改表在数据库中,表的操作主要

C# WinForms存储过程操作数据库的实例讲解

《C#WinForms存储过程操作数据库的实例讲解》:本文主要介绍C#WinForms存储过程操作数据库的实例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、存储过程基础二、C# 调用流程1. 数据库连接配置2. 执行存储过程(增删改)3. 查询数据三、事务处

Java使用Curator进行ZooKeeper操作的详细教程

《Java使用Curator进行ZooKeeper操作的详细教程》ApacheCurator是一个基于ZooKeeper的Java客户端库,它极大地简化了使用ZooKeeper的开发工作,在分布式系统... 目录1、简述2、核心功能2.1 CuratorFramework2.2 Recipes3、示例实践3

Java利用JSONPath操作JSON数据的技术指南

《Java利用JSONPath操作JSON数据的技术指南》JSONPath是一种强大的工具,用于查询和操作JSON数据,类似于SQL的语法,它为处理复杂的JSON数据结构提供了简单且高效... 目录1、简述2、什么是 jsONPath?3、Java 示例3.1 基本查询3.2 过滤查询3.3 递归搜索3.4

Python使用DrissionPage中ChromiumPage进行自动化网页操作

《Python使用DrissionPage中ChromiumPage进行自动化网页操作》DrissionPage作为一款轻量级且功能强大的浏览器自动化库,为开发者提供了丰富的功能支持,本文将使用Dri... 目录前言一、ChromiumPage基础操作1.初始化Drission 和 ChromiumPage

利用Go语言开发文件操作工具轻松处理所有文件

《利用Go语言开发文件操作工具轻松处理所有文件》在后端开发中,文件操作是一个非常常见但又容易出错的场景,本文小编要向大家介绍一个强大的Go语言文件操作工具库,它能帮你轻松处理各种文件操作场景... 目录为什么需要这个工具?核心功能详解1. 文件/目录存javascript在性检查2. 批量创建目录3. 文件

Redis中管道操作pipeline的实现

《Redis中管道操作pipeline的实现》RedisPipeline是一种优化客户端与服务器通信的技术,通过批量发送和接收命令减少网络往返次数,提高命令执行效率,本文就来介绍一下Redis中管道操... 目录什么是pipeline场景一:我要向Redis新增大批量的数据分批处理事务( MULTI/EXE

使用Python高效获取网络数据的操作指南

《使用Python高效获取网络数据的操作指南》网络爬虫是一种自动化程序,用于访问和提取网站上的数据,Python是进行网络爬虫开发的理想语言,拥有丰富的库和工具,使得编写和维护爬虫变得简单高效,本文将... 目录网络爬虫的基本概念常用库介绍安装库Requests和BeautifulSoup爬虫开发发送请求解