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

相关文章

SpringBoot中配置文件的加载顺序解读

《SpringBoot中配置文件的加载顺序解读》:本文主要介绍SpringBoot中配置文件的加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot配置文件的加载顺序1、命令⾏参数2、Java系统属性3、操作系统环境变量5、项目【外部】的ap

Python ZIP文件操作技巧详解

《PythonZIP文件操作技巧详解》在数据处理和系统开发中,ZIP文件操作是开发者必须掌握的核心技能,Python标准库提供的zipfile模块以简洁的API和跨平台特性,成为处理ZIP文件的首选... 目录一、ZIP文件操作基础三板斧1.1 创建压缩包1.2 解压操作1.3 文件遍历与信息获取二、进阶技

Java中字符串转时间与时间转字符串的操作详解

《Java中字符串转时间与时间转字符串的操作详解》Java的java.time包提供了强大的日期和时间处理功能,通过DateTimeFormatter可以轻松地在日期时间对象和字符串之间进行转换,下面... 目录一、字符串转时间(一)使用预定义格式(二)自定义格式二、时间转字符串(一)使用预定义格式(二)自

Java字符串操作技巧之语法、示例与应用场景分析

《Java字符串操作技巧之语法、示例与应用场景分析》在Java算法题和日常开发中,字符串处理是必备的核心技能,本文全面梳理Java中字符串的常用操作语法,结合代码示例、应用场景和避坑指南,可快速掌握字... 目录引言1. 基础操作1.1 创建字符串1.2 获取长度1.3 访问字符2. 字符串处理2.1 子字

Python 中的 with open文件操作的最佳实践

《Python中的withopen文件操作的最佳实践》在Python中,withopen()提供了一个简洁而安全的方式来处理文件操作,它不仅能确保文件在操作完成后自动关闭,还能处理文件操作中的异... 目录什么是 with open()?为什么使用 with open()?使用 with open() 进行

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