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

相关文章

Python正则表达式匹配和替换的操作指南

《Python正则表达式匹配和替换的操作指南》正则表达式是处理文本的强大工具,Python通过re模块提供了完整的正则表达式功能,本文将通过代码示例详细介绍Python中的正则匹配和替换操作,需要的朋... 目录基础语法导入re模块基本元字符常用匹配方法1. re.match() - 从字符串开头匹配2.

Java实现在Word文档中添加文本水印和图片水印的操作指南

《Java实现在Word文档中添加文本水印和图片水印的操作指南》在当今数字时代,文档的自动化处理与安全防护变得尤为重要,无论是为了保护版权、推广品牌,还是为了在文档中加入特定的标识,为Word文档添加... 目录引言Spire.Doc for Java:高效Word文档处理的利器代码实战:使用Java为Wo

sysmain服务可以禁用吗? 电脑sysmain服务关闭后的影响与操作指南

《sysmain服务可以禁用吗?电脑sysmain服务关闭后的影响与操作指南》在Windows系统中,SysMain服务(原名Superfetch)作为一个旨在提升系统性能的关键组件,一直备受用户关... 在使用 Windows 系统时,有时候真有点像在「开盲盒」。全新安装系统后的「默认设置」,往往并不尽编

Python自动化处理PDF文档的操作完整指南

《Python自动化处理PDF文档的操作完整指南》在办公自动化中,PDF文档处理是一项常见需求,本文将介绍如何使用Python实现PDF文档的自动化处理,感兴趣的小伙伴可以跟随小编一起学习一下... 目录使用pymupdf读写PDF文件基本概念安装pymupdf提取文本内容提取图像添加水印使用pdfplum

Python从Word文档中提取图片并生成PPT的操作代码

《Python从Word文档中提取图片并生成PPT的操作代码》在日常办公场景中,我们经常需要从Word文档中提取图片,并将这些图片整理到PowerPoint幻灯片中,手动完成这一任务既耗时又容易出错,... 目录引言背景与需求解决方案概述代码解析代码核心逻辑说明总结引言在日常办公场景中,我们经常需要从 W

使用Python的requests库来发送HTTP请求的操作指南

《使用Python的requests库来发送HTTP请求的操作指南》使用Python的requests库发送HTTP请求是非常简单和直观的,requests库提供了丰富的API,可以发送各种类型的HT... 目录前言1. 安装 requests 库2. 发送 GET 请求3. 发送 POST 请求4. 发送

python 线程池顺序执行的方法实现

《python线程池顺序执行的方法实现》在Python中,线程池默认是并发执行任务的,但若需要实现任务的顺序执行,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋... 目录方案一:强制单线程(伪顺序执行)方案二:按提交顺序获取结果方案三:任务间依赖控制方案四:队列顺序消

Python使用python-pptx自动化操作和生成PPT

《Python使用python-pptx自动化操作和生成PPT》这篇文章主要为大家详细介绍了如何使用python-pptx库实现PPT自动化,并提供实用的代码示例和应用场景,感兴趣的小伙伴可以跟随小编... 目录使用python-pptx操作PPT文档安装python-pptx基础概念创建新的PPT文档查看

MySQL 数据库表操作完全指南:创建、读取、更新与删除实战

《MySQL数据库表操作完全指南:创建、读取、更新与删除实战》本文系统讲解MySQL表的增删查改(CURD)操作,涵盖创建、更新、查询、删除及插入查询结果,也是贯穿各类项目开发全流程的基础数据交互原... 目录mysql系列前言一、Create(创建)并插入数据1.1 单行数据 + 全列插入1.2 多行数据

MySQL 临时表与复制表操作全流程案例

《MySQL临时表与复制表操作全流程案例》本文介绍MySQL临时表与复制表的区别与使用,涵盖生命周期、存储机制、操作限制、创建方法及常见问题,本文结合实例代码给大家介绍的非常详细,感兴趣的朋友跟随小... 目录一、mysql 临时表(一)核心特性拓展(二)操作全流程案例1. 复杂查询中的临时表应用2. 临时