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

相关文章

SQL中JOIN操作的条件使用总结与实践

《SQL中JOIN操作的条件使用总结与实践》在SQL查询中,JOIN操作是多表关联的核心工具,本文将从原理,场景和最佳实践三个方面总结JOIN条件的使用规则,希望可以帮助开发者精准控制查询逻辑... 目录一、ON与WHERE的本质区别二、场景化条件使用规则三、最佳实践建议1.优先使用ON条件2.WHERE用

Linux链表操作方式

《Linux链表操作方式》:本文主要介绍Linux链表操作方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、链表基础概念与内核链表优势二、内核链表结构与宏解析三、内核链表的优点四、用户态链表示例五、双向循环链表在内核中的实现优势六、典型应用场景七、调试技巧与

全屋WiFi 7无死角! 华硕 RP-BE58无线信号放大器体验测评

《全屋WiFi7无死角!华硕RP-BE58无线信号放大器体验测评》家里网络总是有很多死角没有网,我决定入手一台支持Mesh组网的WiFi7路由系统以彻底解决网络覆盖问题,最终选择了一款功能非常... 自2023年WiFi 7技术标准(IEEE 802.11be)正式落地以来,这项第七代无线网络技术就以超高速

Java Multimap实现类与操作的具体示例

《JavaMultimap实现类与操作的具体示例》Multimap出现在Google的Guava库中,它为Java提供了更加灵活的集合操作,:本文主要介绍JavaMultimap实现类与操作的... 目录一、Multimap 概述Multimap 主要特点:二、Multimap 实现类1. ListMult

Java中JSON格式反序列化为Map且保证存取顺序一致的问题

《Java中JSON格式反序列化为Map且保证存取顺序一致的问题》:本文主要介绍Java中JSON格式反序列化为Map且保证存取顺序一致的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未... 目录背景问题解决方法总结背景做项目涉及两个微服务之间传数据时,需要提供方将Map类型的数据序列化为co

Python中文件读取操作漏洞深度解析与防护指南

《Python中文件读取操作漏洞深度解析与防护指南》在Web应用开发中,文件操作是最基础也最危险的功能之一,这篇文章将全面剖析Python环境中常见的文件读取漏洞类型,成因及防护方案,感兴趣的小伙伴可... 目录引言一、静态资源处理中的路径穿越漏洞1.1 典型漏洞场景1.2 os.path.join()的陷

Python使用Code2flow将代码转化为流程图的操作教程

《Python使用Code2flow将代码转化为流程图的操作教程》Code2flow是一款开源工具,能够将代码自动转换为流程图,该工具对于代码审查、调试和理解大型代码库非常有用,在这篇博客中,我们将深... 目录引言1nVflRA、为什么选择 Code2flow?2、安装 Code2flow3、基本功能演示

Python中OpenCV与Matplotlib的图像操作入门指南

《Python中OpenCV与Matplotlib的图像操作入门指南》:本文主要介绍Python中OpenCV与Matplotlib的图像操作指南,本文通过实例代码给大家介绍的非常详细,对大家的学... 目录一、环境准备二、图像的基本操作1. 图像读取、显示与保存 使用OpenCV操作2. 像素级操作3.

python操作redis基础

《python操作redis基础》Redis(RemoteDictionaryServer)是一个开源的、基于内存的键值对(Key-Value)存储系统,它通常用作数据库、缓存和消息代理,这篇文章... 目录1. Redis 简介2. 前提条件3. 安装 python Redis 客户端库4. 连接到 Re

Java Stream.reduce()方法操作实际案例讲解

《JavaStream.reduce()方法操作实际案例讲解》reduce是JavaStreamAPI中的一个核心操作,用于将流中的元素组合起来产生单个结果,:本文主要介绍JavaStream.... 目录一、reduce的基本概念1. 什么是reduce操作2. reduce方法的三种形式二、reduce